From a6a68b4cae7688506c45ff6cf10989fe6596c274 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 series have the same relative path --- src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs | 6 +++--- src/NzbDrone.Core/Extras/Files/ExtraFileService.cs | 6 +++--- .../Extras/Others/OtherExtraFileRenamer.cs | 10 +++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs index 7cb4644c3..6ea20e48b 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Core.Extras.Files List GetFilesBySeries(int seriesId); List GetFilesBySeason(int seriesId, int seasonNumber); List GetFilesByEpisodeFile(int episodeFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int seriesId, string path); } public class ExtraFileRepository : BasicRepository, IExtraFileRepository @@ -54,9 +54,9 @@ namespace NzbDrone.Core.Extras.Files return Query.Where(c => c.EpisodeFileId == episodeFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int seriesId, string path) { - return Query.Where(c => c.RelativePath == path).SingleOrDefault(); + return Query.Where(c => c.SeriesId == seriesId && c.RelativePath == path).SingleOrDefault(); } } } diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index 50bd5f369..10faf6054 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 GetFilesBySeries(int seriesId); List GetFilesByEpisodeFile(int episodeFileId); - TExtraFile FindByPath(string path); + TExtraFile FindByPath(int seriesId, 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.GetFilesByEpisodeFile(episodeFileId); } - public TExtraFile FindByPath(string path) + public TExtraFile FindByPath(int seriesId, string path) { - return _repository.FindByPath(path); + return _repository.FindByPath(seriesId, 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 ff4df604f..c4ec247df 100644 --- a/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs +++ b/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; +using System.IO; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; @@ -45,8 +41,8 @@ namespace NzbDrone.Core.Extras.Others } var relativePath = series.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(series.Id, relativePath); - var otherExtraFile = _otherExtraFileService.FindByPath(relativePath); if (otherExtraFile != null) { var newPath = path + "-orig"; @@ -70,8 +66,8 @@ namespace NzbDrone.Core.Extras.Others } var relativePath = series.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(series.Id, relativePath); - var otherExtraFile = _otherExtraFileService.FindByPath(relativePath); if (otherExtraFile != null) { var subfolder = Path.GetDirectoryName(relativePath);