From 19906e0350110187071c47ca52e4b0edccc263cb Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 4 Aug 2013 10:04:36 -0700 Subject: [PATCH] Special folders also apply to RootFolder unmapped folders --- NzbDrone.Common/DirectoryLookupService.cs | 4 ++-- NzbDrone.Common/DiskProvider.cs | 16 +++++++++++++--- NzbDrone.Core/RootFolders/RootFolderService.cs | 8 +++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/NzbDrone.Common/DirectoryLookupService.cs b/NzbDrone.Common/DirectoryLookupService.cs index 6fd9062b3..7d1677005 100644 --- a/NzbDrone.Common/DirectoryLookupService.cs +++ b/NzbDrone.Common/DirectoryLookupService.cs @@ -35,8 +35,8 @@ public List LookupSubDirectories(string query) if (Path.GetPathRoot(path).Equals(path, StringComparison.InvariantCultureIgnoreCase)) { - var setToRemove = new HashSet { "$Recycle.Bin", "System Volume Information" }; - dirsList.RemoveAll(x => setToRemove.Contains(new DirectoryInfo(x).Name)); + var setToRemove = _diskProvider.SpecialFolders; + dirsList.RemoveAll(x => setToRemove.Contains(new DirectoryInfo(x.ToLowerInvariant()).Name)); } dirs = dirsList; diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index 9d01e2f7c..ad4f08580 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -11,6 +12,7 @@ namespace NzbDrone.Common { public interface IDiskProvider { + HashSet SpecialFolders { get; } DateTime GetLastFolderWrite(string path); DateTime GetLastFileWrite(string path); void EnsureFolder(string path); @@ -36,14 +38,14 @@ public interface IDiskProvider void FolderSetLastWriteTimeUtc(string path, DateTime dateTime); bool IsFileLocked(FileInfo file); string GetPathRoot(string path); - void SetPermissions(string filename, string account, FileSystemRights Rights, AccessControlType ControlType); + void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType); bool IsParent(string parentfolder, string subfolder); - FileAttributes GetFileAttributes(string path); + FileAttributes GetFileAttributes(string path); } public class DiskProvider : IDiskProvider { - enum TransferAction + enum TransferAction { Copy, Move @@ -58,6 +60,14 @@ static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + public HashSet SpecialFolders + { + get + { + return new HashSet { "$recycle.bin", "system volume information", "recycler" }; + } + } + public DateTime GetLastFolderWrite(string path) { Ensure.That(() => path).IsValidPath(); diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 16939e375..42de42e2a 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -99,7 +99,7 @@ public virtual List GetUnmappedFolders(string path) throw new ArgumentException("Invalid path provided", "path"); var results = new List(); - var series = _seriesRepository.All(); + var series = _seriesRepository.All().ToList(); if (!_diskProvider.FolderExists(path)) { @@ -116,6 +116,12 @@ public virtual List GetUnmappedFolders(string path) } } + if (Path.GetPathRoot(path).Equals(path, StringComparison.InvariantCultureIgnoreCase)) + { + var setToRemove = _diskProvider.SpecialFolders; + results.RemoveAll(x => setToRemove.Contains(new DirectoryInfo(x.Path.ToLowerInvariant()).Name)); + } + Logger.Debug("{0} unmapped folders detected.", results.Count); return results; }