{"record":{"id":"ae824621598dd3c4","repo":"apache/seatunnel","slug":"destination-path-s-already-exist-cannot-rename","errorCode":null,"errorMessage":"Destination path %s already exist, cannot rename!","messagePattern":"Destination path (.+?) already exist, cannot rename!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java","lineNumber":448,"sourceCode":"        }\n        return fileStats.toArray(new FileStatus[fileStats.size()]);\n    }\n\n    private boolean rename(ChannelSftp channel, Path src, Path dst) throws IOException {\n        Path workDir;\n        try {\n            workDir = new Path(channel.pwd());\n        } catch (SftpException e) {\n            throw new IOException(e);\n        }\n        Path absoluteSrc = makeAbsolute(workDir, src);\n        Path absoluteDst = makeAbsolute(workDir, dst);\n\n        if (!exists(channel, absoluteSrc)) {\n            throw new IOException(String.format(E_SPATH_NOTEXIST, src));\n        }\n        if (exists(channel, absoluteDst)) {\n            throw new IOException(String.format(E_DPATH_EXIST, dst));\n        }\n        boolean renamed = true;\n        try {\n            final String previousCwd = channel.pwd();\n            channel.cd(\"/\");\n            channel.rename(src.toUri().getPath(), dst.toUri().getPath());\n            channel.cd(previousCwd);\n        } catch (SftpException e) {\n            renamed = false;\n        }\n        return renamed;\n    }\n\n    @Override\n    public void initialize(URI uriInfo, Configuration conf) throws IOException {\n        super.initialize(uriInfo, conf);\n\n        setConfigurationFromURI(uriInfo, conf);","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java#L430-L466","documentation":"rename() throws IOException(E_DPATH_EXIST) when the destination path already exists; SFTP rename does not overwrite, so the operation aborts before channel.rename is attempted. This protects against silently clobbering an existing remote file or directory.","triggerScenarios":"fs.rename(src, dst) where dst already exists on the server — e.g. re-running a job without cleanup, or a partially completed prior rename left dst in place.","commonSituations":"Idempotency issues on retries: first attempt renamed successfully but the client saw an error and retried; leftover output from previous runs; committing to a fixed filename like part-0.","solutions":["Delete the destination first (fs.delete(dst, false)) if overwrite is intended","Use unique/attempt-specific destination names to make retries safe","Make the rename idempotent: if fs.exists(dst), treat as success and skip","Clean stale outputs before job submission"],"exampleFix":"// before\nfs.rename(src, dst);\n// after\nif (fs.exists(dst)) {\n    fs.delete(dst, false);\n}\nfs.rename(src, dst);","handlingStrategy":"validation","validationCode":"Path dst = new Path(\"/data/out/result\");\nif (fs.exists(dst)) {\n    fs.delete(dst, false); // or choose a unique dst\n}","typeGuard":null,"tryCatchPattern":"try {\n    fs.rename(src, dst);\n} catch (IOException e) {\n    if (String.valueOf(e.getMessage()).contains(\"already exist\")) {\n        // treat as success if dst content is from this attempt, or delete and retry\n    } else { throw e; }\n}","preventionTips":["Use unique destination names per run/attempt","Clean stale outputs before submission","Design rename steps to be idempotent on retries"],"tags":["sftp","rename","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}