{"record":{"id":"b1b77e636f18fcd0","repo":"apache/cassandra","slug":"cannot-move-the-file-to-as-the-target-file-a","errorCode":null,"errorMessage":"Cannot move the file {} to {} as the target file already exists.","messagePattern":"Cannot move the file (.+?) to (.+?) as the target file already exists\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/io/util/FileUtils.java","lineNumber":710,"sourceCode":"        logger.info(\"Moving {} to {}\" , source, target);\n\n        if (Files.isDirectory(source))\n        {\n            Files.createDirectories(target);\n\n            for (File f : new File(source).tryList())\n            {\n                String fileName = f.name();\n                moveRecursively(source.resolve(fileName), target.resolve(fileName));\n            }\n\n            deleteDirectoryIfEmpty(source);\n        }\n        else\n        {\n            if (Files.exists(target))\n            {\n                logger.warn(\"Cannot move the file {} to {} as the target file already exists.\" , source, target);\n            }\n            else\n            {\n                Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES);\n                Files.delete(source);\n            }\n        }\n    }\n\n    /**\n     * Deletes the specified directory if it is empty\n     *\n     * @param path the path to the directory\n     */\n    public static void deleteDirectoryIfEmpty(Path path) throws IOException\n    {\n        Preconditions.checkArgument(Files.isDirectory(path), String.format(\"%s is not a directory\", path));\n","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/FileUtils.java#L692-L728","documentation":"During a recursive move, FileUtils.moveRecursively finds the target file already exists, so it refuses to copy over it and only logs a warning; the source file is left in place. The move silently skips that file.","triggerScenarios":"Calling FileUtils.moveRecursively(source, target) (or a delegating move) where target directory already contains a file with the same relative name.","commonSituations":"Moving sstables into a directory that already holds a compaction or restore output; overlapping disk-move operations run concurrently; re-running an interrupted move script.","solutions":["Remove or rename the pre-existing target file, then re-run the move","Ensure only one move operation targets a directory at a time","Clean up partially-completed prior moves before retrying","Verify data integrity after the move since the moved copy is skipped"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"if (Files.exists(targetFile)) {\n    // resolve conflict before moving\n    Files.delete(targetFile); // or rename targetFile to a backup\n}\nFileUtils.moveRecursively(source, target);","typeGuard":"boolean isTargetFree(Path target) { return !Files.exists(target); }","tryCatchPattern":"try {\n    FileUtils.moveRecursively(source, target);\n} catch (FileAlreadyExistsException | IOException e) {\n    // resolve existing target, clean up, retry\n}","preventionTips":["Check target directory emptiness before moving into it","Serialize move operations so only one targets a given directory","Clean up partially-completed moves before retrying","Verify moved data afterward"],"tags":["io","filesystem","move","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}