From a29de48e644cbf7153679dd6c2b5af8756fd45b6 Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 5 Aug 2020 01:52:41 -0400 Subject: [PATCH] Fixed: Block Video Extras from Overriding Movie File --- src/NzbDrone.Core/Extras/ExtraService.cs | 2 +- src/NzbDrone.Core/Extras/Files/ExtraFileManager.cs | 10 +++++++++- src/NzbDrone.Core/Extras/Others/OtherExtraService.cs | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/Extras/ExtraService.cs b/src/NzbDrone.Core/Extras/ExtraService.cs index c361ffb73..d1a29d5ab 100644 --- a/src/NzbDrone.Core/Extras/ExtraService.cs +++ b/src/NzbDrone.Core/Extras/ExtraService.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Extras var sourcePath = localMovie.Path; var sourceFolder = _diskProvider.GetParentFolder(sourcePath); var sourceFileName = Path.GetFileNameWithoutExtension(sourcePath); - var files = _diskProvider.GetFiles(sourceFolder, SearchOption.TopDirectoryOnly); + var files = _diskProvider.GetFiles(sourceFolder, SearchOption.TopDirectoryOnly).Where(f => f != localMovie.Path); var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(e => e.Trim(' ', '.')) diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileManager.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileManager.cs index 882b0edb3..bcbcf3e5c 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileManager.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileManager.cs @@ -49,7 +49,8 @@ namespace NzbDrone.Core.Extras.Files protected TExtraFile ImportFile(Movie movie, MovieFile movieFile, string path, bool readOnly, string extension, string fileNameSuffix = null) { - var newFolder = Path.GetDirectoryName(Path.Combine(movie.Path, movieFile.RelativePath)); + var movieFilePath = Path.Combine(movie.Path, movieFile.RelativePath); + var newFolder = Path.GetDirectoryName(movieFilePath); var filenameBuilder = new StringBuilder(Path.GetFileNameWithoutExtension(movieFile.RelativePath)); if (fileNameSuffix.IsNotNullOrWhiteSpace()) @@ -60,6 +61,13 @@ namespace NzbDrone.Core.Extras.Files filenameBuilder.Append(extension); var newFileName = Path.Combine(newFolder, filenameBuilder.ToString()); + + if (newFileName == movieFilePath) + { + _logger.Debug("Extra file {0} not imported, due to naming interference with movie file", path); + return null; + } + var transferMode = TransferMode.Move; if (readOnly) diff --git a/src/NzbDrone.Core/Extras/Others/OtherExtraService.cs b/src/NzbDrone.Core/Extras/Others/OtherExtraService.cs index 77fd5a4c9..73be18bf9 100644 --- a/src/NzbDrone.Core/Extras/Others/OtherExtraService.cs +++ b/src/NzbDrone.Core/Extras/Others/OtherExtraService.cs @@ -68,8 +68,11 @@ namespace NzbDrone.Core.Extras.Others { var extraFile = ImportFile(movie, movieFile, path, readOnly, extension, null); - _mediaFileAttributeService.SetFilePermissions(path); - _otherExtraFileService.Upsert(extraFile); + if (extraFile != null) + { + _mediaFileAttributeService.SetFilePermissions(path); + _otherExtraFileService.Upsert(extraFile); + } return extraFile; }