Split DirectoryExists and FileExists

This commit is contained in:
Cody Robibero 2022-03-02 19:55:44 -07:00
parent 71a9ae3150
commit 1b3e56bae3
6 changed files with 30 additions and 17 deletions

View File

@ -705,9 +705,15 @@ namespace Emby.Server.Implementations.IO
}
/// <inheritdoc />
public virtual bool Exists(string path)
public virtual bool DirectoryExists(string path)
{
return Directory.Exists(path) || File.Exists(path);
return Directory.Exists(path);
}
/// <inheritdoc />
public virtual bool FileExists(string path)
{
return File.Exists(path);
}
private EnumerationOptions GetEnumerationOptions(bool recursive)

View File

@ -202,10 +202,17 @@ namespace MediaBrowser.Model.IO
IEnumerable<FileSystemMetadata> GetDrives();
/// <summary>
/// Determines whether the directory or file exists.
/// Determines whether the directory exists.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>Whether the path exists.</returns>
bool Exists(string path);
bool DirectoryExists(string path);
/// <summary>
/// Determines whether the file exists.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>Whether the path exists.</returns>
bool FileExists(string path);
}
}

View File

@ -154,7 +154,7 @@ namespace MediaBrowser.Providers.MediaInfo
// Check if video folder exists
string folder = video.ContainingFolderPath;
if (!_fileSystem.Exists(folder))
if (!_fileSystem.DirectoryExists(folder))
{
return Array.Empty<ExternalPathParserResult>();
}
@ -163,7 +163,7 @@ namespace MediaBrowser.Providers.MediaInfo
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
var internalMetadataPath = video.GetInternalMetadataPath();
if (_fileSystem.Exists(internalMetadataPath))
if (_fileSystem.DirectoryExists(internalMetadataPath))
{
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache));
}

View File

@ -47,9 +47,9 @@ public class AudioResolverTests
}));
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
.Returns(true);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
.Returns(true);
_audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());

View File

@ -63,11 +63,11 @@ public class MediaInfoResolverTests
}));
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.Exists(It.IsAny<string>()))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsAny<string>()))
.Returns(false);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(VideoDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
.Returns(true);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MetadataDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
.Returns(true);
_subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
@ -300,9 +300,9 @@ public class MediaInfoResolverTests
}));
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(VideoDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
.Returns(true);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MetadataDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
.Returns(true);
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
@ -372,9 +372,9 @@ public class MediaInfoResolverTests
}));
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(VideoDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
.Returns(true);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MetadataDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
.Returns(true);
var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());

View File

@ -47,9 +47,9 @@ public class SubtitleResolverTests
}));
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
.Returns(true);
fileSystem.Setup(fs => fs.Exists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
.Returns(true);
_subtitleResolver = new SubtitleResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());