diff --git a/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs b/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs index 749e8b3c2..7ecfa4a60 100644 --- a/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs +++ b/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs @@ -8,6 +8,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Movies; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; @@ -151,5 +152,107 @@ namespace NzbDrone.Core.Test.RootFolderTests unmappedFolders.Count.Should().BeGreaterThan(0); unmappedFolders.Should().NotContain(u => u.Name == subFolder); } + + [TestCase("")] + [TestCase(null)] + public void should_handle_non_configured_recycle_bin(string recycleBinPath) + { + var rootFolder = Builder.CreateNew() + .With(r => r.Path = @"C:\Test\TV") + .Build(); + if (OsInfo.IsNotWindows) + { + rootFolder = Builder.CreateNew() + .With(r => r.Path = @"/Test/TV") + .Build(); + } + + var subFolders = new[] + { + "Series1", + "Series2", + "Series3" + }; + + var folders = subFolders.Select(f => Path.Combine(@"C:\Test\TV", f)).ToArray(); + + if (OsInfo.IsNotWindows) + { + folders = subFolders.Select(f => Path.Combine(@"/Test/TV", f)).ToArray(); + } + + Mocker.GetMock() + .Setup(s => s.RecycleBin) + .Returns(recycleBinPath); + + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())) + .Returns(rootFolder); + + Mocker.GetMock() + .Setup(s => s.AllMoviePaths()) + .Returns(new Dictionary()); + + Mocker.GetMock() + .Setup(s => s.GetDirectories(rootFolder.Path)) + .Returns(folders); + + var unmappedFolders = Subject.Get(rootFolder.Id, true).UnmappedFolders; + + unmappedFolders.Count.Should().Be(3); + } + + [Test] + public void should_exclude_recycle_bin() + { + var rootFolder = Builder.CreateNew() + .With(r => r.Path = @"C:\Test\TV") + .Build(); + + if (OsInfo.IsNotWindows) + { + rootFolder = Builder.CreateNew() + .With(r => r.Path = @"/Test/TV") + .Build(); + } + + var subFolders = new[] + { + "Series1", + "Series2", + "Series3", + "BIN" + }; + + var folders = subFolders.Select(f => Path.Combine(@"C:\Test\TV", f)).ToArray(); + + if (OsInfo.IsNotWindows) + { + folders = subFolders.Select(f => Path.Combine(@"/Test/TV", f)).ToArray(); + } + + var recycleFolder = Path.Combine(OsInfo.IsNotWindows ? @"/Test/TV" : @"C:\Test\TV", "BIN"); + + Mocker.GetMock() + .Setup(s => s.RecycleBin) + .Returns(recycleFolder); + + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())) + .Returns(rootFolder); + + Mocker.GetMock() + .Setup(s => s.AllMoviePaths()) + .Returns(new Dictionary()); + + Mocker.GetMock() + .Setup(s => s.GetDirectories(rootFolder.Path)) + .Returns(folders); + + var unmappedFolders = Subject.Get(rootFolder.Id, true).UnmappedFolders; + + unmappedFolders.Count.Should().Be(3); + unmappedFolders.Should().NotContain(u => u.Name == "BIN"); + } } } diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index c7bf54edf..68286c17a 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -148,12 +148,18 @@ namespace NzbDrone.Core.RootFolders var possibleMovieFolders = _diskProvider.GetDirectories(path).ToList(); var unmappedFolders = possibleMovieFolders.Except(moviePaths.Select(s => s.Value), PathEqualityComparer.Instance).ToList(); - foreach (string unmappedFolder in unmappedFolders) + var recycleBinPath = _configService.RecycleBin; + + foreach (var unmappedFolder in unmappedFolders) { var di = new DirectoryInfo(unmappedFolder.Normalize()); + if ((!di.Attributes.HasFlag(FileAttributes.System) && !di.Attributes.HasFlag(FileAttributes.Hidden)) || di.Attributes.ToString() == "-1") { - results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName }); + if (string.IsNullOrWhiteSpace(recycleBinPath) || di.FullName.PathNotEquals(recycleBinPath)) + { + results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName }); + } } }