From 0bdd5f3278eb29be813d494fa855917a862e1a98 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 artists have the same relative path (cherry picked from commit a6a68b4cae7688506c45ff6cf10989fe6596c274) Closes #2760 --- 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 5d88a9a36..a056ca106 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 GetFilesByArtist(int artistId); List GetFilesByAlbum(int artistId, int albumId); List GetFilesByTrackFile(int trackFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int artistId, string path); } public class ExtraFileRepository : BasicRepository, IExtraFileRepository @@ -55,9 +55,9 @@ namespace NzbDrone.Core.Extras.Files return Query(c => c.TrackFileId == trackFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int artistId, string path) { - return Query(c => c.RelativePath == path).SingleOrDefault(); + return Query(c => c.ArtistId == artistId && c.RelativePath == path).SingleOrDefault(); } } } diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index a1c113a39..3f02432e0 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 GetFilesByArtist(int artistId); List GetFilesByTrackFile(int trackFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int artistId, 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.GetFilesByTrackFile(trackFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int artistId, string path) { - return _repository.FindByPath(path); + return _repository.FindByPath(artistId, 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 b5f321e61..542684e18 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 = artist.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(artist.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 = artist.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(artist.Id, relativePath); - var otherExtraFile = _otherExtraFileService.FindByPath(relativePath); if (otherExtraFile != null) { var subfolder = Path.GetDirectoryName(relativePath);