diff options
Diffstat (limited to 'MediaBrowser.Api/Library/LibraryHelpers.cs')
| -rw-r--r-- | MediaBrowser.Api/Library/LibraryHelpers.cs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs index d3b7861a6..8abdc4df5 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 path duplicate = 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 later if (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase)) @@ -210,6 +221,12 @@ namespace MediaBrowser.Api.Library return true; } + // Validate the D:\Movies\Kids scenario + if (enforceSubPathRestriction && newPath.StartsWith(existingPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + // Validate the D:\ scenario if (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) { |
