apache/seatunnel · error · IOException

Destination path already exist, cannot rename!

Error message

Destination path %s already exist, cannot rename!

What it means

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.

Solutions

  1. Delete the destination first (fs.delete(dst, false)) if overwrite is intended
  2. Use unique/attempt-specific destination names to make retries safe
  3. Make the rename idempotent: if fs.exists(dst), treat as success and skip
  4. Clean stale outputs before job submission

Example fix

// before
fs.rename(src, dst);
// after
if (fs.exists(dst)) {
    fs.delete(dst, false);
}
fs.rename(src, dst);
Defensive patterns

Strategy: validation

Validate before calling

Path dst = new Path("/data/out/result");
if (fs.exists(dst)) {
    fs.delete(dst, false); // or choose a unique dst
}

Try / catch

try {
    fs.rename(src, dst);
} catch (IOException e) {
    if (String.valueOf(e.getMessage()).contains("already exist")) {
        // treat as success if dst content is from this attempt, or delete and retry
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/ae824621598dd3c4. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java:448

        }
        return fileStats.toArray(new FileStatus[fileStats.size()]);
    }

    private boolean rename(ChannelSftp channel, Path src, Path dst) throws IOException {
        Path workDir;
        try {
            workDir = new Path(channel.pwd());
        } catch (SftpException e) {
            throw new IOException(e);
        }
        Path absoluteSrc = makeAbsolute(workDir, src);
        Path absoluteDst = makeAbsolute(workDir, dst);

        if (!exists(channel, absoluteSrc)) {
            throw new IOException(String.format(E_SPATH_NOTEXIST, src));
        }
        if (exists(channel, absoluteDst)) {
            throw new IOException(String.format(E_DPATH_EXIST, dst));
        }
        boolean renamed = true;
        try {
            final String previousCwd = channel.pwd();
            channel.cd("/");
            channel.rename(src.toUri().getPath(), dst.toUri().getPath());
            channel.cd(previousCwd);
        } catch (SftpException e) {
            renamed = false;
        }
        return renamed;
    }

    @Override
    public void initialize(URI uriInfo, Configuration conf) throws IOException {
        super.initialize(uriInfo, conf);

        setConfigurationFromURI(uriInfo, conf);

View on GitHub (pinned to cf67b549a7)