aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library/LibraryHelpers.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-24 15:52:41 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-24 15:52:41 -0400
commitb43444c1dfe604f0c386f36627f6b61beb25eea5 (patch)
tree9fd42ad60522220c05da48d562bec4a93c9cbe33 /MediaBrowser.Api/Library/LibraryHelpers.cs
parent7a5ba39603c2a0c970c619016686431b7ff14df1 (diff)
additional fixes for #305
Diffstat (limited to 'MediaBrowser.Api/Library/LibraryHelpers.cs')
-rw-r--r--MediaBrowser.Api/Library/LibraryHelpers.cs21
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))
{