aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Providers/DirectoryService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Providers/DirectoryService.cs')
-rw-r--r--MediaBrowser.Controller/Providers/DirectoryService.cs71
1 files changed, 22 insertions, 49 deletions
diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs
index 6d220f3a3..d957470d3 100644
--- a/MediaBrowser.Controller/Providers/DirectoryService.cs
+++ b/MediaBrowser.Controller/Providers/DirectoryService.cs
@@ -4,7 +4,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
@@ -13,10 +12,10 @@ namespace MediaBrowser.Controller.Providers
public class DirectoryService : IDirectoryService
{
private readonly ILogger _logger;
- private readonly IFileSystem _fileSystem;
+ private readonly IFileSystem _fileSystem;
- private readonly ConcurrentDictionary<string, Dictionary<string, FileSystemMetadata>> _cache =
- new ConcurrentDictionary<string, Dictionary<string, FileSystemMetadata>>(StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache =
+ new ConcurrentDictionary<string, FileSystemMetadata[]>(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache =
new ConcurrentDictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase);
@@ -24,7 +23,7 @@ namespace MediaBrowser.Controller.Providers
public DirectoryService(ILogger logger, IFileSystem fileSystem)
{
_logger = logger;
- _fileSystem = fileSystem;
+ _fileSystem = fileSystem;
}
public DirectoryService(IFileSystem fileSystem)
@@ -32,28 +31,23 @@ namespace MediaBrowser.Controller.Providers
{
}
- public IEnumerable<FileSystemMetadata> GetFileSystemEntries(string path)
+ public FileSystemMetadata[] GetFileSystemEntries(string path)
{
return GetFileSystemEntries(path, false);
}
- public Dictionary<string, FileSystemMetadata> GetFileSystemDictionary(string path)
- {
- return GetFileSystemDictionary(path, false);
- }
-
- private Dictionary<string, FileSystemMetadata> GetFileSystemDictionary(string path, bool clearCache)
+ private FileSystemMetadata[] GetFileSystemEntries(string path, bool clearCache)
{
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentNullException("path");
}
- Dictionary<string, FileSystemMetadata> entries;
+ FileSystemMetadata[] entries;
if (clearCache)
{
- Dictionary<string, FileSystemMetadata> removed;
+ FileSystemMetadata[] removed;
_cache.TryRemove(path, out removed);
}
@@ -62,55 +56,39 @@ namespace MediaBrowser.Controller.Providers
{
//_logger.Debug("Getting files for " + path);
- entries = new Dictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase);
-
try
{
// using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
- var list = _fileSystem.GetFileSystemEntries(path)
- .ToList();
-
- // Seeing dupes on some users file system for some reason
- foreach (var item in list)
- {
- entries[item.FullName] = item;
- }
+ entries = _fileSystem.GetFileSystemEntries(path).ToArray();
}
catch (IOException)
{
+ entries = new FileSystemMetadata[] { };
}
- //var group = entries.ToLookup(i => _fileSystem.GetDirectoryName(i.FullName)).ToList();
-
_cache.TryAdd(path, entries);
}
return entries;
}
- private IEnumerable<FileSystemMetadata> GetFileSystemEntries(string path, bool clearCache)
- {
- return GetFileSystemDictionary(path, clearCache).Values;
- }
-
- public IEnumerable<FileSystemMetadata> GetFiles(string path)
+ public List<FileSystemMetadata> GetFiles(string path)
{
return GetFiles(path, false);
}
- public IEnumerable<FileSystemMetadata> GetFiles(string path, bool clearCache)
- {
- return GetFileSystemEntries(path, clearCache).Where(i => !i.IsDirectory);
- }
-
- public IEnumerable<string> GetFilePaths(string path)
- {
- return _fileSystem.GetFilePaths(path);
- }
-
- public IEnumerable<string> GetFilePaths(string path, bool clearCache)
+ public List<FileSystemMetadata> GetFiles(string path, bool clearCache)
{
- return _fileSystem.GetFilePaths(path);
+ var list = new List<FileSystemMetadata>();
+ var items = GetFileSystemEntries(path, clearCache);
+ foreach (var item in items)
+ {
+ if (!item.IsDirectory)
+ {
+ list.Add(item);
+ }
+ }
+ return list;
}
public FileSystemMetadata GetFile(string path)
@@ -133,10 +111,5 @@ namespace MediaBrowser.Controller.Providers
return file;
//return _fileSystem.GetFileInfo(path);
}
-
- public IEnumerable<FileSystemMetadata> GetDirectories(string path)
- {
- return GetFileSystemEntries(path, false).Where(i => i.IsDirectory);
- }
}
}