The Free Software Media System - Server Backend & API
additional fixes for #305
Luke Pulverentib43444c1dfe6
diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.csindex d3b7861a67..8abdc4df5a 100644--- a/MediaBrowser.Api/Library/LibraryHelpers.cs+++ b/MediaBrowser.Api/Library/LibraryHelpers.cs@@ -175,13 +175,22 @@ namespace MediaBrowser.Api.Library{var duplicate = Directory.EnumerateFiles(appPaths.RootFolderPath, "*.lnk", SearchOption.AllDirectories).Select(FileSystem.ResolveShortcut)- .FirstOrDefault(p => !IsNewPathValid(mediaPath, p));+ .FirstOrDefault(p => !IsNewPathValid(mediaPath, p, false));if (!string.IsNullOrEmpty(duplicate)){throw new ArgumentException(string.Format("The path cannot be added to the library because {0} already exists.", duplicate));}+ duplicate = Directory.EnumerateFiles(currentViewRootFolderPath, "*.lnk", SearchOption.AllDirectories)+ .Select(FileSystem.ResolveShortcut)+ .FirstOrDefault(p => !IsNewPathValid(mediaPath, p, true));++ if (!string.IsNullOrEmpty(duplicate))+ {+ throw new ArgumentException(string.Format("The path cannot be added to the library because {0} already exists.", duplicate));+ }+// Make sure the current root folder doesn't already have a shortcut to the same pathduplicate = Directory.EnumerateFiles(currentViewRootFolderPath, "*.lnk", SearchOption.AllDirectories).Select(FileSystem.ResolveShortcut)@@ -198,11 +207,13 @@ namespace MediaBrowser.Api.Library/// </summary>/// <param name="newPath">The new path.</param>/// <param name="existingPath">The existing path.</param>+ /// <param name="enforceSubPathRestriction">if set to <c>true</c> [enforce sub path restriction].</param>/// <returns><c>true</c> if [is new path valid] [the specified new path]; otherwise, <c>false</c>.</returns>- private static bool IsNewPathValid(string newPath, string existingPath)+ private static bool IsNewPathValid(string newPath, string existingPath, bool enforceSubPathRestriction){// Example: D:\Movies is the existing path// D:\ cannot be added+ // Neither can D:\Movies\Kids// A D:\Movies duplicate is ok here since that will be caught laterif (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase))@@ -210,6 +221,12 @@ namespace MediaBrowser.Api.Libraryreturn true;}+ // Validate the D:\Movies\Kids scenario+ if (enforceSubPathRestriction && newPath.StartsWith(existingPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))+ {+ return false;+ }+// Validate the D:\ scenarioif (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)){diff --git a/MediaBrowser.ServerApplication/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.ServerApplication/EntryPoints/LibraryChangedNotifier.csindex 715492aac4..104b09fda1 100644--- a/MediaBrowser.ServerApplication/EntryPoints/LibraryChangedNotifier.cs+++ b/MediaBrowser.ServerApplication/EntryPoints/LibraryChangedNotifier.cs@@ -4,6 +4,7 @@ using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Plugins;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Logging;using MoreLinq;using System;using System.Collections.Generic;@@ -22,6 +23,7 @@ namespace MediaBrowser.ServerApplication.EntryPointsprivate readonly ISessionManager _sessionManager;private readonly IServerManager _serverManager;private readonly IUserManager _userManager;+ private readonly ILogger _logger;/// <summary>/// The _library changed sync lock@@ -195,7 +197,14 @@ namespace MediaBrowser.ServerApplication.EntryPointsvar id = userId;var webSockets = currentSessions.Where(u => u.UserId.HasValue && u.UserId.Value == id).SelectMany(i => i.WebSockets).ToList();- await _serverManager.SendWebSocketMessageAsync("LibraryChanged", () => GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, foldersRemovedFrom, id), webSockets, cancellationToken).ConfigureAwait(false);+ try+ {+ await _serverManager.SendWebSocketMessageAsync("LibraryChanged", () => GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, foldersRemovedFrom, id), webSockets, cancellationToken).ConfigureAwait(false);+ }+ catch (Exception ex)+ {+ _logger.ErrorException("Error sending LibraryChanged message", ex);+ }}}