apache/cassandra · warning
Cannot move the file
Error message
Cannot move the file {} to {} as the target file already exists. What it means
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.
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
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
if (Files.exists(targetFile)) {
// resolve conflict before moving
Files.delete(targetFile); // or rename targetFile to a backup
}
FileUtils.moveRecursively(source, target); Type guard
boolean isTargetFree(Path target) { return !Files.exists(target); } Try / catch
try {
FileUtils.moveRecursively(source, target);
} catch (FileAlreadyExistsException | IOException e) {
// resolve existing target, clean up, retry
} Prevention
- 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
When it happens
Trigger: Calling FileUtils.moveRecursively(source, target) (or a delegating move) where target directory already contains a file with the same relative name.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Cannot delete the directory
- Could not copy file to
- Could not perform startup sequence and join cluster
- ERR_WRONG_DISK_STATE
- ERR_WRONG_MACHINE_STATE
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/b1b77e636f18fcd0.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/io/util/FileUtils.java:710
logger.info("Moving {} to {}" , source, target);
if (Files.isDirectory(source))
{
Files.createDirectories(target);
for (File f : new File(source).tryList())
{
String fileName = f.name();
moveRecursively(source.resolve(fileName), target.resolve(fileName));
}
deleteDirectoryIfEmpty(source);
}
else
{
if (Files.exists(target))
{
logger.warn("Cannot move the file {} to {} as the target file already exists." , source, target);
}
else
{
Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES);
Files.delete(source);
}
}
}
/**
* Deletes the specified directory if it is empty
*
* @param path the path to the directory
*/
public static void deleteDirectoryIfEmpty(Path path) throws IOException
{
Preconditions.checkArgument(Files.isDirectory(path), String.format("%s is not a directory", path));
View on GitHub (pinned to 88fd0f6a0e)