aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-01 13:26:31 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-01 13:26:31 -0500
commitb9d17c9bc765a0c59d81db6277300a6860bf8421 (patch)
tree8a7c538cb73c27b7e06f0055ce4f0bb45175e7aa /MediaBrowser.Server.Implementations/Library
parent88b638fbd69ed99bde7065f66af433b015977cb7 (diff)
add more methods to file system interface
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
-rw-r--r--MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs25
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs30
2 files changed, 33 insertions, 22 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs
index 5268faa4f..98a87d03d 100644
--- a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs
+++ b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Entities;
+using MediaBrowser.Common.IO;
+using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using System;
@@ -30,6 +31,13 @@ namespace MediaBrowser.Server.Implementations.Library
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
+ private readonly IFileSystem _fileSystem;
+
+ public CoreResolutionIgnoreRule(IFileSystem fileSystem)
+ {
+ _fileSystem = fileSystem;
+ }
+
/// <summary>
/// Shoulds the ignore.
/// </summary>
@@ -60,23 +68,12 @@ namespace MediaBrowser.Server.Implementations.Library
return false;
}
- // Drives will sometimes be hidden
- if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase))
+ // Sometimes these are marked hidden
+ if (_fileSystem.IsRootPath(args.Path))
{
return false;
}
- // Shares will sometimes be hidden
- if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
- {
- // Look for a share, e.g. \\server\movies
- // Is there a better way to detect if a path is a share without using native code?
- if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2)
- {
- return false;
- }
- }
-
return true;
}
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index 1a52bb224..8e4e71fd4 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -499,21 +499,18 @@ namespace MediaBrowser.Server.Implementations.Library
// When resolving the root, we need it's grandchildren (children of user views)
var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
- args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);
+ var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);
// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
if (isPhysicalRoot)
{
- var paths = args.FileSystemDictionary.Keys.ToList();
+ var paths = NormalizeRootPathList(fileSystemDictionary.Keys);
- foreach (var subPath in paths
- .Where(subPath => !subPath.EndsWith(":\\", StringComparison.OrdinalIgnoreCase) && paths.Any(i => subPath.StartsWith(i.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))))
- {
- _logger.Info("Ignoring duplicate path: {0}", subPath);
- args.FileSystemDictionary.Remove(subPath);
- }
+ fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName);
}
+
+ args.FileSystemDictionary = fileSystemDictionary;
}
// Check to see if we should resolve based on our contents
@@ -525,6 +522,23 @@ namespace MediaBrowser.Server.Implementations.Library
return ResolveItem(args);
}
+ public IEnumerable<string> NormalizeRootPathList(IEnumerable<string> paths)
+ {
+ var list = paths.Select(_fileSystem.NormalizePath)
+ .Distinct(StringComparer.OrdinalIgnoreCase)
+ .ToList();
+
+ var dupes = list.Where(subPath => !subPath.EndsWith(":\\", StringComparison.OrdinalIgnoreCase) && list.Any(i => _fileSystem.ContainsSubPath(i, subPath)))
+ .ToList();
+
+ foreach (var dupe in dupes)
+ {
+ _logger.Info("Found duplicate path: {0}", dupe);
+ }
+
+ return list.Except(dupes, StringComparer.OrdinalIgnoreCase);
+ }
+
/// <summary>
/// Determines whether a path should be ignored based on its contents - called after the contents have been read
/// </summary>