From 44009e980b8f967d5f577dbce41a9bf5fb4b2b50 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 12 Apr 2022 17:46:10 -0700 Subject: [PATCH] Fixed: A potential issue when extra files for multiple authors have the same relative path (cherry picked from commit a6a68b4cae7688506c45ff6cf10989fe6596c274) Closes #1650 --- src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs | 6 +++--- src/NzbDrone.Core/Extras/Files/ExtraFileService.cs | 6 +++--- src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs index 185ae2a20..9078739af 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Extras.Files List GetFilesByAuthor(int authorId); List GetFilesByBook(int authorId, int bookId); List GetFilesByBookFile(int bookFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int authorId, string path); } public class ExtraFileRepository : BasicRepository, IExtraFileRepository @@ -55,9 +55,9 @@ namespace NzbDrone.Core.Extras.Files return Query(c => c.BookFileId == bookFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int authorId, string path) { - return Query(c => c.RelativePath == path).SingleOrDefault(); + return Query(c => c.AuthorId == authorId && c.RelativePath == path).SingleOrDefault(); } } } diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index 4822f4040..2f1561d11 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs @@ -18,7 +18,7 @@ namespace NzbDrone.Core.Extras.Files { List GetFilesByAuthor(int authorId); List GetFilesByBookFile(int bookFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int authorId, string path); void Upsert(TExtraFile extraFile); void Upsert(List extraFiles); void Delete(int id); @@ -59,9 +59,9 @@ namespace NzbDrone.Core.Extras.Files return _repository.GetFilesByBookFile(bookFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int authorId, string path) { - return _repository.FindByPath(path); + return _repository.FindByPath(authorId, path); } public void Upsert(TExtraFile extraFile) diff --git a/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs b/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs index 8f4bec1e6..8d4cfad62 100644 --- a/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs +++ b/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs @@ -41,8 +41,8 @@ namespace NzbDrone.Core.Extras.Others } var relativePath = author.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(author.Id, relativePath); - var otherExtraFile = _otherExtraFileService.FindByPath(relativePath); if (otherExtraFile != null) { var newPath = path + "-orig"; @@ -66,8 +66,8 @@ namespace NzbDrone.Core.Extras.Others } var relativePath = author.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(author.Id, relativePath); - var otherExtraFile = _otherExtraFileService.FindByPath(relativePath); if (otherExtraFile != null) { var subfolder = Path.GetDirectoryName(relativePath);