{"record":{"id":"fe5f2b68ad6a9027","repo":"Sonarr/Sonarr","slug":"destination-targetpath-already-exists","errorCode":null,"errorMessage":"Destination {targetPath} already exists.","messagePattern":"Destination (.+?) already exists\\.","errorType":"exception","errorClass":"DestinationAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"src/NzbDrone.Common/Disk/DiskTransferService.cs","lineNumber":378,"sourceCode":"\n                TryMoveFileVerified(sourcePath, targetPath, originalSize);\n                return TransferMode.Move;\n            }\n\n            return TransferMode.None;\n        }\n\n        private void ClearTargetPath(string sourcePath, string targetPath, bool overwrite)\n        {\n            if (_diskProvider.FileExists(targetPath))\n            {\n                if (overwrite)\n                {\n                    _diskProvider.DeleteFile(targetPath);\n                }\n                else\n                {\n                    throw new DestinationAlreadyExistsException($\"Destination {targetPath} already exists.\");\n                }\n            }\n        }\n\n        private void RollbackPartialMove(string sourcePath, string targetPath)\n        {\n            try\n            {\n                _logger.Debug(\"Rolling back incomplete file move [{0}] to [{1}].\", sourcePath, targetPath);\n\n                WaitForIO();\n\n                if (_diskProvider.FileExists(sourcePath))\n                {\n                    _diskProvider.DeleteFile(targetPath);\n                }\n                else\n                {","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/Sonarr/Sonarr/blob/da2284d7eaab22ed9b2ca698af690148d691e967/src/NzbDrone.Common/Disk/DiskTransferService.cs#L360-L396","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass overwrite=true to the transfer call if overwriting is the intended behavior.","Delete or move the existing destination file before transferring.","Check _diskProvider.FileExists(targetPath) before invoking the transfer and branch accordingly."],"exampleFix":"// before\n_diskTransferService.TransferFile(src, dst, TransferMode.Copy);\n// after\n_diskTransferService.TransferFile(src, dst, TransferMode.Copy, overwrite: true);","handlingStrategy":"validation","validationCode":"if (_diskProvider.FileExists(targetPath))\n{\n    if (!overwrite)\n    {\n        // decide: skip, delete, or overwrite\n        return;\n    }\n    _diskProvider.DeleteFile(targetPath);\n}\n_diskTransferService.TransferFile(sourcePath, targetPath, TransferMode.Copy, overwrite);","typeGuard":null,"tryCatchPattern":"try\n{\n    _diskTransferService.TransferFile(src, dst, TransferMode.Copy);\n}\ncatch (DestinationAlreadyExistsException)\n{\n    // already imported - skip or resolve conflict\n}","preventionTips":["Check FileExists(targetPath) before transferring and decide explicitly.","Pass overwrite=true only when clobbering is intended.","Catch DestinationAlreadyExistsException specifically to treat re-imports as non-fatal."],"tags":["disk","transfer","file-exists"],"backgroundTag":null,"analyzedSha":"da2284d7eaab22ed9b2ca698af690148d691e967","analyzedAt":"2026-08-13T15:53:02.562Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}