Fixed: Filter direct excluded subfolders of the selected directory during manual import

Fixes #4734

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/4958/head
Qstick 4 years ago
parent e6368c3095
commit 16321377fc

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.GetFileSize(It.IsAny<string>()))
.Returns(1000000);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
}

@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.GetHashFromTorrentFile(It.IsAny<byte[]>()))
.Returns("myhash");
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
}

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.OpenWriteStream(It.IsAny<string>()))
.Returns(() => new FileStream(GetTempFilePath(), FileMode.Create));
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
}

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_videoFiles);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))

@ -97,7 +97,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var specialFiles = GetFiles(path, subFolder).ToList();
var allFiles = files.Concat(specialFiles);
var filteredFiles = Subject.FilterFiles(path, allFiles);
var filteredFiles = Subject.FilterPaths(path, allFiles);
filteredFiles.Should().NotContain(specialFiles);
filteredFiles.Count.Should().BeGreaterThan(0);
}

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
private IEnumerable<WatchFolderItem> GetDownloadItems(string watchFolder, Dictionary<string, WatchFolderItem> lastWatchItems, TimeSpan waitPeriod)
{
foreach (var folder in _diskScanService.FilterFiles(watchFolder, _diskProvider.GetDirectories(watchFolder)))
foreach (var folder in _diskScanService.FilterPaths(watchFolder, _diskProvider.GetDirectories(watchFolder)))
{
var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder));
@ -88,7 +88,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
yield return newWatchItem;
}
foreach (var videoFile in _diskScanService.FilterFiles(watchFolder, _diskScanService.GetVideoFiles(watchFolder, false)))
foreach (var videoFile in _diskScanService.FilterPaths(watchFolder, _diskScanService.GetVideoFiles(watchFolder, false)))
{
var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile));

@ -41,7 +41,7 @@ namespace NzbDrone.Core.Extras
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
var filesOnDisk = _diskScanService.GetNonVideoFiles(movie.Path);
var possibleExtraFiles = _diskScanService.FilterFiles(movie.Path, filesOnDisk, false);
var possibleExtraFiles = _diskScanService.FilterPaths(movie.Path, filesOnDisk, false);
var filteredFiles = possibleExtraFiles;
var importedFiles = new List<string>();

@ -24,7 +24,7 @@ namespace NzbDrone.Core.MediaFiles
void Scan(Movie movie);
string[] GetVideoFiles(string path, bool allDirectories = true);
string[] GetNonVideoFiles(string path, bool allDirectories = true);
List<string> FilterFiles(string basePath, IEnumerable<string> files, bool filterExtras = true);
List<string> FilterPaths(string basePath, IEnumerable<string> paths, bool filterExtras = true);
}
public class DiskScanService :
@ -120,7 +120,7 @@ namespace NzbDrone.Core.MediaFiles
}
var videoFilesStopwatch = Stopwatch.StartNew();
var mediaFileList = FilterFiles(movie.Path, GetVideoFiles(movie.Path)).ToList();
var mediaFileList = FilterPaths(movie.Path, GetVideoFiles(movie.Path)).ToList();
videoFilesStopwatch.Stop();
_logger.Trace("Finished getting movie files for: {0} [{1}]", movie, videoFilesStopwatch.Elapsed);
@ -180,20 +180,20 @@ namespace NzbDrone.Core.MediaFiles
return mediaFileList.ToArray();
}
public List<string> FilterFiles(string basePath, IEnumerable<string> files, bool filterExtras = true)
public List<string> FilterPaths(string basePath, IEnumerable<string> paths, bool filterExtras = true)
{
var filteredFiles = files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
.ToList();
var filteredPaths = paths.Where(path => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(path)))
.Where(path => !ExcludedFilesRegex.IsMatch(Path.GetFileName(path)))
.ToList();
if (filterExtras)
{
filteredFiles = filteredFiles.Where(file => !ExcludedExtrasSubFolderRegex.IsMatch(basePath.GetRelativePath(file)))
.Where(file => !ExcludedExtraFilesRegex.IsMatch(Path.GetFileName(file)))
filteredPaths = filteredPaths.Where(path => !ExcludedExtrasSubFolderRegex.IsMatch(basePath.GetRelativePath(path)))
.Where(path => !ExcludedExtraFilesRegex.IsMatch(Path.GetFileName(path)))
.ToList();
}
return filteredFiles;
return filteredPaths;
}
private void SetPermissions(string path)

@ -189,7 +189,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);
}
var videoFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetVideoFiles(directoryInfo.FullName));
var videoFiles = _diskScanService.FilterPaths(directoryInfo.FullName, _diskScanService.GetVideoFiles(directoryInfo.FullName));
if (downloadClientItem == null)
{

@ -120,8 +120,11 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual
if (movie == null)
{
var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false));
var subfolders = _diskScanService.FilterFiles(baseFolder, _diskProvider.GetDirectories(baseFolder));
// Filter paths based on the rootFolder, so files in subfolders that should be ignored are ignored.
// It will lead to some extra directories being checked for files, but it saves the processing of them and is cleaner than
// teaching FilterPaths to know whether it's processing a file or a folder and changing it's filtering based on that.
var files = _diskScanService.FilterPaths(rootFolder, _diskScanService.GetVideoFiles(baseFolder, false));
var subfolders = _diskScanService.FilterPaths(rootFolder, _diskProvider.GetDirectories(baseFolder));
var processedFiles = files.Select(file => ProcessFile(rootFolder, baseFolder, file, downloadId));
var processedFolders = subfolders.SelectMany(subfolder => ProcessFolder(rootFolder, subfolder, downloadId, null, filterExistingFiles));

Loading…
Cancel
Save