Sonarr/Sonarr · error · DestinationAlreadyExistsException

Destination {targetPath} already exists.

Error message

Destination {targetPath} already exists.

What it means

Thrown as DestinationAlreadyExistsException by ClearTargetPath when the destination file already exists and the caller did not set overwrite=true. It is a deliberate guard against silently clobbering an existing file during a transfer.

Source

Thrown at src/NzbDrone.Common/Disk/DiskTransferService.cs:378

                TryMoveFileVerified(sourcePath, targetPath, originalSize);
                return TransferMode.Move;
            }

            return TransferMode.None;
        }

        private void ClearTargetPath(string sourcePath, string targetPath, bool overwrite)
        {
            if (_diskProvider.FileExists(targetPath))
            {
                if (overwrite)
                {
                    _diskProvider.DeleteFile(targetPath);
                }
                else
                {
                    throw new DestinationAlreadyExistsException($"Destination {targetPath} already exists.");
                }
            }
        }

        private void RollbackPartialMove(string sourcePath, string targetPath)
        {
            try
            {
                _logger.Debug("Rolling back incomplete file move [{0}] to [{1}].", sourcePath, targetPath);

                WaitForIO();

                if (_diskProvider.FileExists(sourcePath))
                {
                    _diskProvider.DeleteFile(targetPath);
                }
                else
                {

View on GitHub (pinned to da2284d7ea)

Solutions

  1. Pass overwrite=true to the transfer call if overwriting is the intended behavior.
  2. Delete or move the existing destination file before transferring.
  3. Check _diskProvider.FileExists(targetPath) before invoking the transfer and branch accordingly.

Example fix

// before
_diskTransferService.TransferFile(src, dst, TransferMode.Copy);
// after
_diskTransferService.TransferFile(src, dst, TransferMode.Copy, overwrite: true);
Defensive patterns

Strategy: validation

Validate before calling

if (_diskProvider.FileExists(targetPath))
{
    if (!overwrite)
    {
        // decide: skip, delete, or overwrite
        return;
    }
    _diskProvider.DeleteFile(targetPath);
}
_diskTransferService.TransferFile(sourcePath, targetPath, TransferMode.Copy, overwrite);

Try / catch

try
{
    _diskTransferService.TransferFile(src, dst, TransferMode.Copy);
}
catch (DestinationAlreadyExistsException)
{
    // already imported - skip or resolve conflict
}

Prevention

When it happens

Trigger: TransferFile is invoked with overwrite=false (the default) while a file already exists at targetPath. Any subsequent transfer to a previously-imported media file triggers it.

Common situations: Re-importing an episode that already exists in the library, or a download being moved/copied to a destination that was only partially cleaned up.

Related errors


AI-assisted analysis of Sonarr/Sonarr@da2284d7ea (2026-08-13). Data as JSON: /api/errors/fe5f2b68ad6a9027. Report an issue: GitHub.