Fixed: A potential issue when extra files for multiple authors have the same relative path

(cherry picked from commit a6a68b4cae7688506c45ff6cf10989fe6596c274)

Closes #1650
pull/3324/head
Mark McDowall 2 years ago committed by Bogdan
parent 02fd733223
commit 44009e980b

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Extras.Files
List<TExtraFile> GetFilesByAuthor(int authorId); List<TExtraFile> GetFilesByAuthor(int authorId);
List<TExtraFile> GetFilesByBook(int authorId, int bookId); List<TExtraFile> GetFilesByBook(int authorId, int bookId);
List<TExtraFile> GetFilesByBookFile(int bookFileId); List<TExtraFile> GetFilesByBookFile(int bookFileId);
TExtraFile FindByPath(string path); TExtraFile FindByPath(int authorId, string path);
} }
public class ExtraFileRepository<TExtraFile> : BasicRepository<TExtraFile>, IExtraFileRepository<TExtraFile> public class ExtraFileRepository<TExtraFile> : BasicRepository<TExtraFile>, IExtraFileRepository<TExtraFile>
@ -55,9 +55,9 @@ namespace NzbDrone.Core.Extras.Files
return Query(c => c.BookFileId == bookFileId); 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();
} }
} }
} }

@ -18,7 +18,7 @@ namespace NzbDrone.Core.Extras.Files
{ {
List<TExtraFile> GetFilesByAuthor(int authorId); List<TExtraFile> GetFilesByAuthor(int authorId);
List<TExtraFile> GetFilesByBookFile(int bookFileId); List<TExtraFile> GetFilesByBookFile(int bookFileId);
TExtraFile FindByPath(string path); TExtraFile FindByPath(int authorId, string path);
void Upsert(TExtraFile extraFile); void Upsert(TExtraFile extraFile);
void Upsert(List<TExtraFile> extraFiles); void Upsert(List<TExtraFile> extraFiles);
void Delete(int id); void Delete(int id);
@ -59,9 +59,9 @@ namespace NzbDrone.Core.Extras.Files
return _repository.GetFilesByBookFile(bookFileId); 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) public void Upsert(TExtraFile extraFile)

@ -41,8 +41,8 @@ namespace NzbDrone.Core.Extras.Others
} }
var relativePath = author.Path.GetRelativePath(path); var relativePath = author.Path.GetRelativePath(path);
var otherExtraFile = _otherExtraFileService.FindByPath(author.Id, relativePath);
var otherExtraFile = _otherExtraFileService.FindByPath(relativePath);
if (otherExtraFile != null) if (otherExtraFile != null)
{ {
var newPath = path + "-orig"; var newPath = path + "-orig";
@ -66,8 +66,8 @@ namespace NzbDrone.Core.Extras.Others
} }
var relativePath = author.Path.GetRelativePath(path); var relativePath = author.Path.GetRelativePath(path);
var otherExtraFile = _otherExtraFileService.FindByPath(author.Id, relativePath);
var otherExtraFile = _otherExtraFileService.FindByPath(relativePath);
if (otherExtraFile != null) if (otherExtraFile != null)
{ {
var subfolder = Path.GetDirectoryName(relativePath); var subfolder = Path.GetDirectoryName(relativePath);

Loading…
Cancel
Save