Fixed: Exclude OS X Metadata files when scanning for files

Fixes #533
This commit is contained in:
Mark McDowall 2015-05-11 17:23:55 -07:00
parent 6e7a2af86b
commit c3acfe34fe
2 changed files with 24 additions and 3 deletions

View File

@ -27,6 +27,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
@"C:\Test\movie"
};
GivenFiles();
}
private void GivenFiles()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<String>(), SearchOption.AllDirectories))
.Returns(_files);
@ -69,8 +74,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
public void should_return_video_files_only()
{
var path = @"C:\Test\";
var test = Subject.GetVideoFiles(path);
Subject.GetVideoFiles(path).Should().HaveCount(4);
}
[Test]
public void should_exclude_osx_metadata_files()
{
var path = @"C:\Test\";
_files = new [] { "._24 The Status Quo Combustion.mp4", "24 The Status Quo Combustion.mp4" };
GivenFiles();
Subject.GetVideoFiles(path).Should().HaveCount(1);
}
}
}

View File

@ -60,6 +60,7 @@ namespace NzbDrone.Core.MediaFiles
private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(extras|@eadir)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFoldersRegex = new Regex(@"(?:\\|\/)(\..+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public void Scan(Series series)
{
@ -124,7 +125,9 @@ namespace NzbDrone.Core.MediaFiles
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var filesOnDisk = _diskProvider.GetFiles(path, searchOption);
var mediaFileList = filesOnDisk.Where(c => MediaFileExtensions.Extensions.Contains(Path.GetExtension(c).ToLower())).ToList();
var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file).ToLower()))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
.ToList();
_logger.Debug("{0} video files were found in {1}", mediaFileList.Count, path);
return mediaFileList.ToArray();
@ -133,7 +136,8 @@ namespace NzbDrone.Core.MediaFiles
private IEnumerable<string> FilterFiles(Series series, IEnumerable<string> videoFiles)
{
return videoFiles.Where(file => !ExcludedSubFoldersRegex.IsMatch(series.Path.GetRelativePath(file)))
.Where(file => !ExcludedFoldersRegex.IsMatch(file));
.Where(file => !ExcludedFoldersRegex.IsMatch(file))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)));
}
private void SetPermissions(String path)