1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

Add FileInfo utility functions to DiskProvider

This commit is contained in:
ta264 2020-10-07 21:06:03 +01:00 committed by Qstick
parent 024e4df99c
commit f917d0e9bc
3 changed files with 14 additions and 6 deletions

View File

@ -731,7 +731,7 @@ private void WithEmulatedDiskProvider()
// Note: never returns anything. // Note: never returns anything.
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetFileInfos(It.IsAny<string>())) .Setup(v => v.GetFileInfos(It.IsAny<string>(), SearchOption.TopDirectoryOnly))
.Returns(new List<FileInfo>()); .Returns(new List<FileInfo>());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
@ -765,8 +765,8 @@ private void WithRealDiskProvider()
.Returns<string>(v => new DirectoryInfo(v).GetDirectories().ToList()); .Returns<string>(v => new DirectoryInfo(v).GetDirectories().ToList());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetFileInfos(It.IsAny<string>())) .Setup(v => v.GetFileInfos(It.IsAny<string>(), SearchOption.TopDirectoryOnly))
.Returns<string>(v => new DirectoryInfo(v).GetFiles().ToList()); .Returns<string, SearchOption>((v, _) => new DirectoryInfo(v).GetFiles().ToList());
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetFileSize(It.IsAny<string>())) .Setup(v => v.GetFileSize(It.IsAny<string>()))

View File

@ -505,13 +505,20 @@ public List<DirectoryInfo> GetDirectoryInfos(string path)
return di.GetDirectories().ToList(); return di.GetDirectories().ToList();
} }
public List<FileInfo> GetFileInfos(string path) public FileInfo GetFileInfo(string path)
{
Ensure.That(path, () => path).IsValidPath();
return new FileInfo(path);
}
public List<FileInfo> GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly)
{ {
Ensure.That(path, () => path).IsValidPath(); Ensure.That(path, () => path).IsValidPath();
var di = new DirectoryInfo(path); var di = new DirectoryInfo(path);
return di.GetFiles().ToList(); return di.GetFiles("*", searchOption).ToList();
} }
public void RemoveEmptySubfolders(string path) public void RemoveEmptySubfolders(string path)

View File

@ -52,7 +52,8 @@ public interface IDiskProvider
List<IMount> GetMounts(); List<IMount> GetMounts();
IMount GetMount(string path); IMount GetMount(string path);
List<DirectoryInfo> GetDirectoryInfos(string path); List<DirectoryInfo> GetDirectoryInfos(string path);
List<FileInfo> GetFileInfos(string path); FileInfo GetFileInfo(string path);
List<FileInfo> GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly);
void RemoveEmptySubfolders(string path); void RemoveEmptySubfolders(string path);
void SaveStream(Stream stream, string path); void SaveStream(Stream stream, string path);
bool IsValidFilePermissionMask(string mask); bool IsValidFilePermissionMask(string mask);