New: Ignore inaccessible files with getting files

Closes #5818
This commit is contained in:
Mark McDowall 2023-08-03 19:54:44 -07:00
parent 60714eb89a
commit e5aa858410
30 changed files with 82 additions and 87 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.GZip; using ICSharpCode.SharpZipLib.GZip;
@ -11,7 +12,7 @@ namespace NzbDrone.Common
public interface IArchiveService public interface IArchiveService
{ {
void Extract(string compressedFile, string destination); void Extract(string compressedFile, string destination);
void CreateZip(string path, params string[] files); void CreateZip(string path, IEnumerable<string> files);
} }
public class ArchiveService : IArchiveService public class ArchiveService : IArchiveService
@ -39,7 +40,7 @@ namespace NzbDrone.Common
_logger.Debug("Extraction complete."); _logger.Debug("Extraction complete.");
} }
public void CreateZip(string path, params string[] files) public void CreateZip(string path, IEnumerable<string> files)
{ {
using (var zipFile = ZipFile.Create(path)) using (var zipFile = ZipFile.Create(path))
{ {

View File

@ -46,7 +46,7 @@ namespace NzbDrone.Common.Disk
{ {
CheckFolderExists(path); CheckFolderExists(path);
var dirFiles = GetFiles(path, SearchOption.AllDirectories).ToList(); var dirFiles = GetFiles(path, true).ToList();
if (!dirFiles.Any()) if (!dirFiles.Any())
{ {
@ -149,25 +149,29 @@ namespace NzbDrone.Common.Disk
return Directory.EnumerateFileSystemEntries(path).Empty(); return Directory.EnumerateFileSystemEntries(path).Empty();
} }
public string[] GetDirectories(string path) public IEnumerable<string> GetDirectories(string path)
{ {
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
return Directory.GetDirectories(path); return Directory.EnumerateDirectories(path);
} }
public string[] GetFiles(string path, SearchOption searchOption) public IEnumerable<string> GetFiles(string path, bool recursive)
{ {
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
return Directory.GetFiles(path, "*.*", searchOption); return Directory.EnumerateFiles(path, "*", new EnumerationOptions
{
RecurseSubdirectories = recursive,
IgnoreInaccessible = true
});
} }
public long GetFolderSize(string path) public long GetFolderSize(string path)
{ {
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
return GetFiles(path, SearchOption.AllDirectories).Sum(e => new FileInfo(e).Length); return GetFiles(path, true).Sum(e => new FileInfo(e).Length);
} }
public long GetFileSize(string path) public long GetFileSize(string path)
@ -288,8 +292,9 @@ namespace NzbDrone.Common.Disk
{ {
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
var files = Directory.GetFiles(path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); var files = GetFiles(path, recursive);
Array.ForEach(files, RemoveReadOnly);
files.ToList().ForEach(RemoveReadOnly);
Directory.Delete(path, recursive); Directory.Delete(path, recursive);
} }
@ -381,7 +386,7 @@ namespace NzbDrone.Common.Disk
{ {
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly)) foreach (var file in GetFiles(path, false))
{ {
DeleteFile(file); DeleteFile(file);
} }

View File

@ -22,8 +22,8 @@ namespace NzbDrone.Common.Disk
bool FileExists(string path, StringComparison stringComparison); bool FileExists(string path, StringComparison stringComparison);
bool FolderWritable(string path); bool FolderWritable(string path);
bool FolderEmpty(string path); bool FolderEmpty(string path);
string[] GetDirectories(string path); IEnumerable<string> GetDirectories(string path);
string[] GetFiles(string path, SearchOption searchOption); IEnumerable<string> GetFiles(string path, bool recursive);
long GetFolderSize(string path); long GetFolderSize(string path);
long GetFileSize(string path); long GetFileSize(string path);
void CreateFolder(string path); void CreateFolder(string path);

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Returns(new[] { targetDir }); .Returns(new[] { targetDir });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) .Setup(c => c.GetFiles(targetDir, true))
.Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()

View File

@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Returns(new[] { targetDir }); .Returns(new[] { targetDir });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) .Setup(c => c.GetFiles(targetDir, true))
.Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()

View File

@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Returns(new[] { targetDir }); .Returns(new[] { targetDir });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) .Setup(c => c.GetFiles(targetDir, true))
.Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()

View File

@ -121,7 +121,7 @@ namespace NzbDrone.Core.Test.Extras
WithExistingFile(file); WithExistingFile(file);
} }
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(_episodeFolder, It.IsAny<SearchOption>())) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(_episodeFolder, It.IsAny<bool>()))
.Returns(files.ToArray()); .Returns(files.ToArray());
} }
@ -224,8 +224,8 @@ namespace NzbDrone.Core.Test.Extras
Subject.ImportEpisode(_localEpisode, _episodeFile, true); Subject.ImportEpisode(_localEpisode, _episodeFile, true);
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Once); Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, true), Times.Once);
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Never); Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, false), Times.Never);
} }
[Test] [Test]
@ -245,8 +245,8 @@ namespace NzbDrone.Core.Test.Extras
Subject.ImportEpisode(_localEpisode, _episodeFile, true); Subject.ImportEpisode(_localEpisode, _episodeFile, true);
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Never); Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, true), Times.Never);
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Once); Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_episodeFolder, false), Times.Once);
} }
} }
} }

View File

@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
sampleFile sampleFile
}; };
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(videoFiles); .Returns(videoFiles);
Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<Series>(), sampleFile, It.IsAny<bool>())) Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<Series>(), sampleFile, It.IsAny<bool>()))
@ -198,7 +198,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
Path.Combine(_series.Path, "Season 1", "Series Title - S01E01.sample.mkv").AsOsAgnostic() Path.Combine(_series.Path, "Season 1", "Series Title - S01E01.sample.mkv").AsOsAgnostic()
}; };
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(videoFiles); .Returns(videoFiles);
var results = Subject.ImportFiles(_localEpisode, _episodeFile, new List<string> { subtitleFile }, true).ToList(); var results = Subject.ImportFiles(_localEpisode, _episodeFile, new List<string> { subtitleFile }, true).ToList();

View File

@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
private void GivenFiles(IEnumerable<string> files) private void GivenFiles(IEnumerable<string> files)
{ {
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(files.ToArray()); .Returns(files.ToArray());
} }
@ -93,7 +93,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFiles(_series.Path, SearchOption.AllDirectories), Times.Never()); .Verify(v => v.GetFiles(_series.Path, true), Times.Never());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.CreateFolder(_series.Path), Times.Never()); .Verify(v => v.CreateFolder(_series.Path), Times.Never());
@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFiles(_series.Path, SearchOption.AllDirectories), Times.Never()); .Verify(v => v.GetFiles(_series.Path, true), Times.Never());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.CreateFolder(_series.Path), Times.Never()); .Verify(v => v.CreateFolder(_series.Path), Times.Never());
@ -267,7 +267,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
Subject.Scan(_series); Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Once()); .Verify(v => v.GetFiles(It.IsAny<string>(), It.IsAny<bool>()), Times.Once());
Mocker.GetMock<IMakeImportDecision>() Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series, false), Times.Once()); .Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series, false), Times.Once());

View File

@ -284,7 +284,7 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(DetectSampleResult.Sample); .Returns(DetectSampleResult.Sample);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") }); .Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
@ -310,7 +310,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(folderName)) Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(folderName))
.Returns(true); .Returns(true);
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetFiles(folderName, SearchOption.TopDirectoryOnly)) Mocker.GetMock<IDiskProvider>().Setup(c => c.GetFiles(folderName, false))
.Returns(new[] { fileName }); .Returns(new[] { fileName });
var localEpisode = new LocalEpisode(); var localEpisode = new LocalEpisode();
@ -463,7 +463,7 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(imported.Select(i => new ImportResult(i)).ToList()); .Returns(imported.Select(i => new ImportResult(i)).ToList());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") }); .Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") });
var result = Subject.ProcessPath(path); var result = Subject.ProcessPath(path);
@ -489,7 +489,7 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(imported.Select(i => new ImportResult(i)).ToList()); .Returns(imported.Select(i => new ImportResult(i)).ToList());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(new[] { _videoFiles.First().Replace(".ext", ".exe") }); .Returns(new[] { _videoFiles.First().Replace(".ext", ".exe") });
var result = Subject.ProcessPath(path); var result = Subject.ProcessPath(path);

View File

@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
var filesToReturn = files.ToArray(); var filesToReturn = files.ToArray();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(filesToReturn); .Returns(filesToReturn);
} }
@ -48,8 +48,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
Subject.GetVideoFiles(path); Subject.GetVideoFiles(path);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, true), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, false), Times.Never());
} }
[Test] [Test]
@ -59,8 +59,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
Subject.GetVideoFiles(path, true); Subject.GetVideoFiles(path, true);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, true), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, false), Times.Never());
} }
[Test] [Test]
@ -70,8 +70,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
Subject.GetVideoFiles(path, false); Subject.GetVideoFiles(path, false);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, true), Times.Never());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, false), Times.Once());
} }
[Test] [Test]

View File

@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -42,7 +41,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
.Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); .Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" });
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.AllDirectories)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, true))
.Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" }); .Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" });
} }

View File

@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -68,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
WithRecycleBin(); WithRecycleBin();
var path = @"C:\Test\TV\30 Rock".AsOsAgnostic(); var path = @"C:\Test\TV\30 Rock".AsOsAgnostic();
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), SearchOption.AllDirectories)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), true))
.Returns(new[] { "File1", "File2", "File3" }); .Returns(new[] { "File1", "File2", "File3" });
Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path); Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path);

View File

@ -1,4 +1,3 @@
using System.IO;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -22,7 +21,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
.Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); .Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" });
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly)) Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, false))
.Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" }); .Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" });
} }

View File

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Backup
// Delete journal file created during database backup // Delete journal file created during database backup
_diskProvider.DeleteFile(Path.Combine(_backupTempFolder, "sonarr.db-journal")); _diskProvider.DeleteFile(Path.Combine(_backupTempFolder, "sonarr.db-journal"));
_archiveService.CreateZip(backupPath, _diskProvider.GetFiles(_backupTempFolder, SearchOption.TopDirectoryOnly)); _archiveService.CreateZip(backupPath, _diskProvider.GetFiles(_backupTempFolder, false));
_logger.ProgressDebug("Backup zip created"); _logger.ProgressDebug("Backup zip created");
} }
@ -126,7 +126,7 @@ namespace NzbDrone.Core.Backup
_archiveService.Extract(backupFileName, temporaryPath); _archiveService.Extract(backupFileName, temporaryPath);
foreach (var file in _diskProvider.GetFiles(temporaryPath, SearchOption.TopDirectoryOnly)) foreach (var file in _diskProvider.GetFiles(temporaryPath, false))
{ {
var fileName = Path.GetFileName(file); var fileName = Path.GetFileName(file);
@ -238,7 +238,7 @@ namespace NzbDrone.Core.Backup
private IEnumerable<string> GetBackupFiles(string path) private IEnumerable<string> GetBackupFiles(string path)
{ {
var files = _diskProvider.GetFiles(path, SearchOption.TopDirectoryOnly); var files = _diskProvider.GetFiles(path, false);
return files.Where(f => BackupFileRegex.IsMatch(f)); return files.Where(f => BackupFileRegex.IsMatch(f));
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -69,7 +69,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
if (PreCheckWatchItemExpiry(newWatchItem, oldWatchItem)) if (PreCheckWatchItemExpiry(newWatchItem, oldWatchItem))
{ {
var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories); var files = _diskProvider.GetFiles(folder, true);
newWatchItem.TotalSize = files.Select(_diskProvider.GetFileSize).Sum(); newWatchItem.TotalSize = files.Select(_diskProvider.GetFileSize).Sum();
newWatchItem.Hash = GetHash(folder, files); newWatchItem.Hash = GetHash(folder, files);
@ -153,7 +153,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
} }
} }
private string GetHash(string folder, string[] files) private string GetHash(string folder, IEnumerable<string> files)
{ {
var data = new StringBuilder(); var data = new StringBuilder();

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using FluentValidation.Results; using FluentValidation.Results;
@ -61,7 +61,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
public override IEnumerable<DownloadClientItem> GetItems() public override IEnumerable<DownloadClientItem> GetItems()
{ {
foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly)) foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, false))
{ {
if (Path.GetExtension(file) != ".strm") if (Path.GetExtension(file) != ".strm")
{ {

View File

@ -60,9 +60,7 @@ namespace NzbDrone.Core.Extras
return; return;
} }
var folderSearchOption = localEpisode.FolderEpisodeInfo == null var folderSearchOption = localEpisode.FolderEpisodeInfo != null;
? SearchOption.TopDirectoryOnly
: SearchOption.AllDirectories;
var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(e => e.Trim(' ', '.') .Select(e => e.Trim(' ', '.')

View File

@ -145,7 +145,7 @@ namespace NzbDrone.Core.Extras.Subtitles
// Use any sub if only episode in folder // Use any sub if only episode in folder
if (matchingFiles.Count == 0 && filteredFiles.Count > 0) if (matchingFiles.Count == 0 && filteredFiles.Count > 0)
{ {
var videoFiles = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories) var videoFiles = _diskProvider.GetFiles(sourceFolder, true)
.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) .Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
.ToList(); .ToList();

View File

@ -194,8 +194,7 @@ namespace NzbDrone.Core.MediaFiles
{ {
_logger.Debug("Scanning '{0}' for video files", path); _logger.Debug("Scanning '{0}' for video files", path);
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var filesOnDisk = _diskProvider.GetFiles(path, allDirectories).ToList();
var filesOnDisk = _diskProvider.GetFiles(path, searchOption).ToList();
var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
.ToList(); .ToList();
@ -210,8 +209,7 @@ namespace NzbDrone.Core.MediaFiles
{ {
_logger.Debug("Scanning '{0}' for non-video files", path); _logger.Debug("Scanning '{0}' for non-video files", path);
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var filesOnDisk = _diskProvider.GetFiles(path, allDirectories).ToList();
var filesOnDisk = _diskProvider.GetFiles(path, searchOption).ToList();
var mediaFileList = filesOnDisk.Where(file => !MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) var mediaFileList = filesOnDisk.Where(file => !MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
.ToList(); .ToList();

View File

@ -111,7 +111,7 @@ namespace NzbDrone.Core.MediaFiles
try try
{ {
var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName); var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName);
var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, true).Where(f =>
Path.GetExtension(f).Equals(".rar", Path.GetExtension(f).Equals(".rar",
StringComparison.OrdinalIgnoreCase)); StringComparison.OrdinalIgnoreCase));
@ -309,7 +309,7 @@ namespace NzbDrone.Core.MediaFiles
private ImportResult CheckEmptyResultForIssue(string folder) private ImportResult CheckEmptyResultForIssue(string folder)
{ {
var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories); var files = _diskProvider.GetFiles(folder, true);
if (files.Any(file => FileExtensions.ExecutableExtensions.Contains(Path.GetExtension(file)))) if (files.Any(file => FileExtensions.ExecutableExtensions.Contains(Path.GetExtension(file))))
{ {

View File

@ -57,7 +57,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Debug("Setting last accessed: {0}", path); _logger.Debug("Setting last accessed: {0}", path);
_diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow); _diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow);
foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories)) foreach (var file in _diskProvider.GetFiles(destination, true))
{ {
SetLastWriteTime(file, DateTime.UtcNow); SetLastWriteTime(file, DateTime.UtcNow);
} }
@ -146,7 +146,7 @@ namespace NzbDrone.Core.MediaFiles
_diskProvider.DeleteFolder(folder, true); _diskProvider.DeleteFolder(folder, true);
} }
foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.TopDirectoryOnly)) foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, false))
{ {
_diskProvider.DeleteFile(file); _diskProvider.DeleteFile(file);
} }
@ -172,7 +172,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Info("Removing items older than {0} days from the recycling bin", cleanupDays); _logger.Info("Removing items older than {0} days from the recycling bin", cleanupDays);
foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.AllDirectories)) foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, true))
{ {
if (_diskProvider.FileGetLastWrite(file).AddDays(cleanupDays) > DateTime.UtcNow) if (_diskProvider.FileGetLastWrite(file).AddDays(cleanupDays) > DateTime.UtcNow)
{ {

View File

@ -1,4 +1,4 @@
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -25,7 +25,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
.Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true); .Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly)) .Setup(c => c.GetFiles("/System/Library/CoreServices/", false))
.Returns(new[] { plistPath }); .Returns(new[] { plistPath });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
@ -49,7 +49,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
.Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true); .Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly)) .Setup(c => c.GetFiles("/System/Library/CoreServices/", false))
.Returns(new[] { plistPath }); .Returns(new[] { plistPath });
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
@ -69,7 +69,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly), Times.Never()); .Verify(c => c.GetFiles(It.IsAny<string>(), false), Times.Never());
} }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
@ -29,25 +29,25 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
} }
[Test] [Test]
public void should_return_null_if_etc_doestn_exist() public void should_return_null_if_etc_doesnt_exist()
{ {
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(false); Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(false);
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly), Times.Never()); .Verify(c => c.GetFiles(It.IsAny<string>(), false), Times.Never());
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
} }
[Test] [Test]
public void should_return_null_if_release_file_doestn_exist() public void should_return_null_if_release_file_doesnt_exist()
{ {
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(true); Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(true);
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(Array.Empty<string>()); .Setup(c => c.GetFiles(It.IsAny<string>(), false)).Returns(Array.Empty<string>());
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
} }
@ -59,7 +59,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
Subject.Read().Should().BeNull(); Subject.Read().Should().BeNull();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(new[] .Setup(c => c.GetFiles(It.IsAny<string>(), false)).Returns(new[]
{ {
"/etc/lsb-release", "/etc/lsb-release",
"/etc/os-release" "/etc/os-release"

View File

@ -1,4 +1,3 @@
using System.IO;
using System.Linq; using System.Linq;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -21,7 +20,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
return null; return null;
} }
var issueFile = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("/issue")); var issueFile = _diskProvider.GetFiles("/etc/", false).SingleOrDefault(c => c.EndsWith("/issue"));
if (issueFile == null) if (issueFile == null)
{ {

View File

@ -1,4 +1,3 @@
using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NLog; using NLog;
@ -33,7 +32,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
return null; return null;
} }
var allFiles = _diskProvider.GetFiles(PLIST_DIR, SearchOption.TopDirectoryOnly); var allFiles = _diskProvider.GetFiles(PLIST_DIR, false);
var versionFile = allFiles.SingleOrDefault(c => var versionFile = allFiles.SingleOrDefault(c =>
c.EndsWith("/SystemVersion.plist") || c.EndsWith("/SystemVersion.plist") ||

View File

@ -1,4 +1,3 @@
using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -22,7 +21,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
return null; return null;
} }
var releaseFiles = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).Where(c => c.EndsWith("release")).ToList(); var releaseFiles = _diskProvider.GetFiles("/etc/", false).Where(c => c.EndsWith("release")).ToList();
var name = "Linux"; var name = "Linux";
var fullName = ""; var fullName = "";

View File

@ -1,4 +1,3 @@
using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -24,7 +23,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
return null; return null;
} }
var versionFile = _diskProvider.GetFiles("/etc.defaults/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("VERSION")); var versionFile = _diskProvider.GetFiles("/etc.defaults/", false).SingleOrDefault(c => c.EndsWith("VERSION"));
if (versionFile == null) if (versionFile == null)
{ {

View File

@ -25,7 +25,7 @@ namespace Sonarr.Api.V3.Logs
protected override IEnumerable<string> GetLogFiles() protected override IEnumerable<string> GetLogFiles()
{ {
return _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), SearchOption.TopDirectoryOnly); return _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), false);
} }
protected override string GetLogFilePath(string filename) protected override string GetLogFilePath(string filename)

View File

@ -32,7 +32,7 @@ namespace Sonarr.Api.V3.Logs
return Enumerable.Empty<string>(); return Enumerable.Empty<string>();
} }
return _diskProvider.GetFiles(_appFolderInfo.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly) return _diskProvider.GetFiles(_appFolderInfo.GetUpdateLogFolder(), false)
.Where(f => Regex.IsMatch(Path.GetFileName(f), LOGFILE_ROUTE.TrimStart('/'), RegexOptions.IgnoreCase)) .Where(f => Regex.IsMatch(Path.GetFileName(f), LOGFILE_ROUTE.TrimStart('/'), RegexOptions.IgnoreCase))
.ToList(); .ToList();
} }