Fixed: Errors logged during import when existing episode file is partial removed in the DB

Fixes #3159
This commit is contained in:
Mark McDowall 2019-06-15 00:48:03 -07:00
parent 4713eaffdb
commit 7dff9bc696
4 changed files with 36 additions and 0 deletions

View File

@ -302,5 +302,18 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
[Test]
public void should_return_true_if_episode_file_is_null()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(null))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
}
}

View File

@ -194,5 +194,20 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localEpisode.Episodes.Single().EpisodeFile.Value, DeleteMediaFileReason.Upgrade), Times.Never());
}
[Test]
public void should_import_if_existing_file_doesnt_exist_in_db()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(null))
.Build()
.ToList();
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localEpisode.Episodes.Single().EpisodeFile.Value, It.IsAny<DeleteMediaFileReason>()), Times.Never());
}
}
}

View File

@ -29,6 +29,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
{
var episodeFile = episode.EpisodeFile.Value;
if (episodeFile == null)
{
_logger.Trace("Unable to get episode file details from the DB. EpisodeId: {0} EpisodeFileId: {1}", episode.Id, episode.EpisodeFileId);
continue;
}
var qualityCompare = qualityComparer.Compare(localEpisode.Quality.Quality, episodeFile.Quality.Quality);
if (qualityCompare < 0)

View File

@ -40,6 +40,7 @@ namespace NzbDrone.Core.MediaFiles
var existingFiles = localEpisode.Episodes
.Where(e => e.EpisodeFileId > 0)
.Select(e => e.EpisodeFile.Value)
.Where(e => e != null)
.GroupBy(e => e.Id)
.ToList();