{"record":{"id":"c6b9985fbc7e7350","repo":"lingochamp/FileDownloader","slug":"can-t-rename-the-temp-downloaded-file-s-to-the","errorCode":null,"errorMessage":"Can't rename the  temp downloaded file(%s) to the target file(%s)","messagePattern":"Can't rename the  temp downloaded file\\((.+?)\\) to the target file\\((.+?)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/download/DownloadStatusCallback.java","lineNumber":316,"sourceCode":"\n            if (targetFile.exists()) {\n                final long oldTargetFileLength = targetFile.length();\n                if (!targetFile.delete()) {\n                    throw new IOException(FileDownloadUtils.formatString(\n                            \"Can't delete the old file([%s], [%d]), \"\n                                    + \"so can't replace it with the new downloaded one.\",\n                            targetPath, oldTargetFileLength\n                    ));\n                } else {\n                    FileDownloadLog.w(this, \"The target file([%s], [%d]) will be replaced with\"\n                                    + \" the new downloaded file[%d]\",\n                            targetPath, oldTargetFileLength, tempFile.length());\n                }\n            }\n\n            renameFailed = !tempFile.renameTo(targetFile);\n            if (renameFailed) {\n                throw new IOException(FileDownloadUtils.formatString(\n                        \"Can't rename the  temp downloaded file(%s) to the target file(%s)\",\n                        tempPath, targetPath\n                ));\n            }\n        } finally {\n            if (renameFailed && tempFile.exists()) {\n                if (!tempFile.delete()) {\n                    FileDownloadLog.w(this,\n                            \"delete the temp file(%s) failed, on completed downloading.\",\n                            tempPath);\n                }\n            }\n        }\n    }\n\n    @Override\n    public boolean handleMessage(Message msg) {\n        handlingMessage = true;","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/download/DownloadStatusCallback.java#L298-L334","documentation":"Thrown by DownloadStatusCallback.renameTempFile (called from handleCompleted) when File.renameTo from the temp path (.tmp) to the final target path returns false after the download completed. The rename is atomic on most filesystems but fails when paths are on different mount points, the target directory is missing, or permissions are insufficient — leaving the fully downloaded data unusable until finalized.","triggerScenarios":"Thrown at library/src/main/java/com/liulishuo/filedownloader/download/DownloadStatusCallback.java:316 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make sure the temp file and target file are on the same filesystem/volume and the target directory exists.","Check and fix write permissions on the target directory.","Manually copy the temp file to the target path as a fallback, then delete the temp file.","Catch the IOException in the download error callback and retry the task after cleaning up leftover temp/target files."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}