Prevent exception when renaming after script import

This commit is contained in:
Jendrik Weise 2023-08-16 21:56:44 +02:00 committed by Mark McDowall
parent 1273656c8e
commit 2166e4dce4
1 changed files with 10 additions and 16 deletions

View File

@ -121,29 +121,23 @@ namespace NzbDrone.Core.MediaFiles
throw new SameFilenameException("File not moved, source and destination are the same", episodeFilePath); throw new SameFilenameException("File not moved, source and destination are the same", episodeFilePath);
} }
var transfer = true;
episodeFile.RelativePath = series.Path.GetRelativePath(destinationFilePath); episodeFile.RelativePath = series.Path.GetRelativePath(destinationFilePath);
if (localEpisode is not null) if (localEpisode is not null && _scriptImportDecider.TryImport(episodeFilePath, destinationFilePath, localEpisode, episodeFile, mode) is var scriptImportDecision && scriptImportDecision != ScriptImportDecision.DeferMove)
{ {
var scriptImportDecision = _scriptImportDecider.TryImport(episodeFilePath, destinationFilePath, localEpisode, episodeFile, mode); if (scriptImportDecision == ScriptImportDecision.RenameRequested)
{
switch (scriptImportDecision) try
{ {
case ScriptImportDecision.DeferMove:
break;
case ScriptImportDecision.RenameRequested:
MoveEpisodeFile(episodeFile, series, episodeFile.Episodes); MoveEpisodeFile(episodeFile, series, episodeFile.Episodes);
transfer = false; }
break; catch (SameFilenameException)
case ScriptImportDecision.MoveComplete: {
transfer = false; _logger.Debug("No rename was required. File already exists at destination.");
break;
} }
} }
}
if (transfer) else
{ {
_diskTransferService.TransferFile(episodeFilePath, destinationFilePath, mode); _diskTransferService.TransferFile(episodeFilePath, destinationFilePath, mode);
} }