Split DirectoryExists and FileExists

pull/7370/head
Cody Robibero 3 years ago
parent 71a9ae3150
commit 1b3e56bae3

@ -705,9 +705,15 @@ namespace Emby.Server.Implementations.IO
} }
/// <inheritdoc /> /// <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) private EnumerationOptions GetEnumerationOptions(bool recursive)

@ -202,10 +202,17 @@ namespace MediaBrowser.Model.IO
IEnumerable<FileSystemMetadata> GetDrives(); IEnumerable<FileSystemMetadata> GetDrives();
/// <summary> /// <summary>
/// Determines whether the directory or file exists. /// Determines whether the directory exists.
/// </summary> /// </summary>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>Whether the path exists.</returns> /// <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);
} }
} }

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

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

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

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

Loading…
Cancel
Save