diff options
Diffstat (limited to 'MediaBrowser.Controller/IO/FileData.cs')
| -rw-r--r-- | MediaBrowser.Controller/IO/FileData.cs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index 8896d4fc1..306de1e3c 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -3,6 +3,7 @@ using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.IO; +using System.Linq; namespace MediaBrowser.Controller.IO { @@ -29,22 +30,29 @@ namespace MediaBrowser.Controller.IO throw new ArgumentNullException("path"); } - var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase); - var entries = new DirectoryInfo(path).EnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly); + if (!resolveShortcuts && flattenFolderDepth == 0) + { + return entries.ToDictionary(i => i.FullName, StringComparer.OrdinalIgnoreCase); + } + + var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase); + foreach (var entry in entries) { var isDirectory = (entry.Attributes & FileAttributes.Directory) == FileAttributes.Directory; - if (resolveShortcuts && FileSystem.IsShortcut(entry.FullName)) + var fullName = entry.FullName; + + if (resolveShortcuts && FileSystem.IsShortcut(fullName)) { - var newPath = FileSystem.ResolveShortcut(entry.FullName); + var newPath = FileSystem.ResolveShortcut(fullName); if (string.IsNullOrWhiteSpace(newPath)) { //invalid shortcut - could be old or target could just be unavailable - logger.Warn("Encountered invalid shortcut: " + entry.FullName); + logger.Warn("Encountered invalid shortcut: " + fullName); continue; } @@ -57,18 +65,18 @@ namespace MediaBrowser.Controller.IO args.AddAdditionalLocation(newPath); } - dict[data.FullName] = data; + dict[newPath] = data; } else if (flattenFolderDepth > 0 && isDirectory) { - foreach (var child in GetFilteredFileSystemEntries(entry.FullName, logger, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts)) + foreach (var child in GetFilteredFileSystemEntries(fullName, logger, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts)) { dict[child.Key] = child.Value; } } else { - dict[entry.FullName] = entry; + dict[fullName] = entry; } } |
