MyCATApache/Mycat-Server · error
rename file failed for upload file
Error message
rename file failed for upload file {file} What it means
In ConfFileHandler.upLoadConfigFile(), after a successful backup, the uploaded temp file is renamed to its final destination conf/<fileName>; if File.renameTo fails, the handler logs 'rename file failed for upload file <tempPath>' and returns that message to the manager client, leaving the config unsaved. It means the temp file could not be moved into place in the conf directory.
Solutions
- Verify the Mycat process can write/rename in MYCAT_HOME/conf and fix permissions (chown/chmod) accordingly.
- Ensure the temp file and the conf destination are on the same filesystem/mount; remount or relocate MYCAT_HOME so rename is possible.
- Retry the upload after resolving; confirm the expected 'SUCCESS SAVED FILE:<name>' response.
Example fix
// before: temp in /tmp, conf on separate mount -> renameTo fails silently String msg = "rename file failed"; // returned to client // after: run mycat with temp dir on the same volume $ export JAVA_OPTS="$JAVA_OPTS -Djava.io.tmpdir=/usr/local/mycat/tmp" # mkdir -p /usr/local/mycat/tmp && chown mycat:mycat /usr/local/mycat/tmp # restart and re-upload
Defensive patterns
Strategy: validation
Validate before calling
// ensure temp file and destination share a filesystem and conf is writable before upload
File dest = new File(SystemConfig.getHomePath(), "conf" + File.separator + fileName);
File tmp = new File(System.getProperty("java.io.tmpdir"));
if (!Files.getFileStore(dest.getParentFile().toPath()).equals(Files.getFileStore(tmp.toPath()))) {
throw new IllegalStateException("temp dir and conf dir on different filesystems; set -Djava.io.tmpdir under MYCAT_HOME");
}
if (!dest.getParentFile().canWrite()) throw new IllegalStateException("conf dir not writable: " + dest.getParent()); Prevention
- Set java.io.tmpdir to a directory on the same volume as MYCAT_HOME/conf.
- Grant the mycat process user write/rename permission on the conf directory.
- Avoid mounting conf on a different filesystem than the temp dir.
- After failed uploads, check for orphaned temp files and clean them before retrying.
When it happens
Trigger: tempFile.renameTo(dest) returns false — the temp file's directory or the conf destination is not writable by the Mycat process, temp and destination lie on different filesystems (renameTo cannot cross mount points), or dest exists as an unrenamable entry.
Common situations: Manager-console (9066) config uploads in containers where the uploaded temp file (e.g. in /tmp) and MYCAT_HOME/conf are on different mounts; read-only conf volume; permission mismatch between the temp dir and conf dir users.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- rename old file failed for upload file
- rehashNodeDir must be writable
- Mkdirs failed to create
- Failed to create local dir in $newDir.
- Failed to delete:
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/48c35a8460bea3a8.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/manager/handler/ConfFileHandler.java:238
// if succcess
File oldFile = new File(SystemConfig.getHomePath(), "conf"
+ File.separator + fileName);
if (oldFile.exists()) {
File backUP = new File(SystemConfig.getHomePath(), "conf"
+ File.separator + fileName + "_"
+ System.currentTimeMillis() + "_auto");
if (!oldFile.renameTo(backUP)) {
String msg = "rename old file failed";
LOGGER.warn(msg + " for upload file "
+ oldFile.getAbsolutePath());
return showInfo(c, buffer, packetId, msg);
}
}
File dest = new File(SystemConfig.getHomePath(), "conf"
+ File.separator + fileName);
if (!tempFile.renameTo(dest)) {
String msg = "rename file failed";
LOGGER.warn(msg + " for upload file "
+ tempFile.getAbsolutePath());
return showInfo(c, buffer, packetId, msg);
}
return showInfo(c, buffer, packetId, "SUCCESS SAVED FILE:"
+ fileName);
} else {
return showInfo(c, buffer, packetId, "UPLOAD ERROR OCCURD:"
+ fileName);
}
}
private static PackageBufINf showInfo(ManagerConnection c,
ByteBuffer buffer, byte packetId, String string) {
PackageBufINf bufINf = new PackageBufINf();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(string, c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c,true);View on GitHub (pinned to 65f8d8beb7)