{"record":{"id":"48c35a8460bea3a8","repo":"MyCATApache/Mycat-Server","slug":"rename-file-failed-for-upload-file-file","errorCode":null,"errorMessage":"rename file failed for upload file {file}","messagePattern":"rename file failed for upload file (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/manager/handler/ConfFileHandler.java","lineNumber":238,"sourceCode":"\t\t\t// if succcess\n\t\t\tFile oldFile = new File(SystemConfig.getHomePath(), \"conf\"\n\t\t\t\t\t+ File.separator + fileName);\n\t\t\tif (oldFile.exists()) {\n\t\t\t\tFile backUP = new File(SystemConfig.getHomePath(), \"conf\"\n\t\t\t\t\t\t+ File.separator + fileName + \"_\"\n\t\t\t\t\t\t+ System.currentTimeMillis() + \"_auto\");\n\t\t\t\tif (!oldFile.renameTo(backUP)) {\n\t\t\t\t\tString msg = \"rename old file failed\";\n\t\t\t\t\tLOGGER.warn(msg + \" for upload file \"\n\t\t\t\t\t\t\t+ oldFile.getAbsolutePath());\n\t\t\t\t\treturn showInfo(c, buffer, packetId, msg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tFile dest = new File(SystemConfig.getHomePath(), \"conf\"\n\t\t\t\t\t+ File.separator + fileName);\n\t\t\tif (!tempFile.renameTo(dest)) {\n\t\t\t\tString msg = \"rename file failed\";\n\t\t\t\tLOGGER.warn(msg + \" for upload file \"\n\t\t\t\t\t\t+ tempFile.getAbsolutePath());\n\t\t\t\treturn showInfo(c, buffer, packetId, msg);\n\t\t\t}\n\t\t\treturn showInfo(c, buffer, packetId, \"SUCCESS SAVED FILE:\"\n\t\t\t\t\t+ fileName);\n\t\t} else {\n\t\t\treturn showInfo(c, buffer, packetId, \"UPLOAD ERROR OCCURD:\"\n\t\t\t\t\t+ fileName);\n\t\t}\n\t}\n\n\tprivate static PackageBufINf showInfo(ManagerConnection c,\n\t\t\tByteBuffer buffer, byte packetId, String string) {\n\t\tPackageBufINf bufINf = new PackageBufINf();\n\t\tRowDataPacket row = new RowDataPacket(FIELD_COUNT);\n\t\trow.add(StringUtil.encode(string, c.getCharset()));\n\t\trow.packetId = ++packetId;\n\t\tbuffer = row.write(buffer, c,true);","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/manager/handler/ConfFileHandler.java#L220-L256","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: temp in /tmp, conf on separate mount -> renameTo fails silently\nString msg = \"rename file failed\"; // returned to client\n// after: run mycat with temp dir on the same volume\n$ export JAVA_OPTS=\"$JAVA_OPTS -Djava.io.tmpdir=/usr/local/mycat/tmp\"\n# mkdir -p /usr/local/mycat/tmp && chown mycat:mycat /usr/local/mycat/tmp\n# restart and re-upload","handlingStrategy":"validation","validationCode":"// ensure temp file and destination share a filesystem and conf is writable before upload\nFile dest = new File(SystemConfig.getHomePath(), \"conf\" + File.separator + fileName);\nFile tmp = new File(System.getProperty(\"java.io.tmpdir\"));\nif (!Files.getFileStore(dest.getParentFile().toPath()).equals(Files.getFileStore(tmp.toPath()))) {\n    throw new IllegalStateException(\"temp dir and conf dir on different filesystems; set -Djava.io.tmpdir under MYCAT_HOME\");\n}\nif (!dest.getParentFile().canWrite()) throw new IllegalStateException(\"conf dir not writable: \" + dest.getParent());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["filesystem","file-rename","config-upload","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}