1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-02-25 07:12:40 +00:00

Fixed: Edge case where import fails due to DB relationship mismatch

This commit is contained in:
Qstick 2020-09-06 22:40:17 -04:00
parent f66a6eea6c
commit e8e4d76d73
2 changed files with 27 additions and 4 deletions

View file

@ -92,5 +92,18 @@ public void should_be_reject_if_file_size_is_the_same()
Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeFalse();
} }
[Test]
public void should_be_accepted_if_file_cannot_be_fetched()
{
_localTrack.Tracks = Builder<Track>.CreateListOfSize(1)
.TheFirst(1)
.With(e => e.TrackFileId = 1)
.With(e => e.TrackFile = new LazyLoaded<TrackFile>((TrackFile)null))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeTrue();
}
} }
} }

View file

@ -15,9 +15,9 @@ public SameFileSpecification(Logger logger)
_logger = logger; _logger = logger;
} }
public Decision IsSatisfiedBy(LocalTrack item, DownloadClientItem downloadClientItem) public Decision IsSatisfiedBy(LocalTrack localTrack, DownloadClientItem downloadClientItem)
{ {
var trackFiles = item.Tracks.Where(e => e.TrackFileId != 0).Select(e => e.TrackFile).ToList(); var trackFiles = localTrack.Tracks.Where(e => e.TrackFileId != 0).Select(e => e.TrackFile).ToList();
if (trackFiles.Count == 0) if (trackFiles.Count == 0)
{ {
@ -31,9 +31,19 @@ public Decision IsSatisfiedBy(LocalTrack item, DownloadClientItem downloadClient
return Decision.Accept(); return Decision.Accept();
} }
if (trackFiles.First().Value.Size == item.Size) var trackFile = trackFiles.First().Value;
if (trackFile == null)
{ {
_logger.Debug("'{0}' Has the same filesize as existing file", item.Path); var track = localTrack.Tracks.First();
_logger.Trace("Unable to get track file details from the DB. TrackId: {0} TrackFileId: {1}", track.Id, track.TrackFileId);
return Decision.Accept();
}
if (trackFiles.First().Value.Size == localTrack.Size)
{
_logger.Debug("'{0}' Has the same filesize as existing file", localTrack.Path);
return Decision.Reject("Has the same filesize as existing file"); return Decision.Reject("Has the same filesize as existing file");
} }