{"record":{"id":"48b7dfd0967de4ed","repo":"apache/seatunnel","slug":"can-t-make-directory-for-path-s-since-it-is-a-fil-48b7df","errorCode":null,"errorMessage":"Can't make directory for path %s since it is a file.","messagePattern":"Can't make directory for path (.+?) since it is a file\\.","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":329,"sourceCode":"        if (!exists(client, absolute)) {\n            Path parent = absolute.getParent();\n            created = parent == null || mkdirs(client, parent, FsPermission.getDefault());\n            if (created) {\n                String parentDir = parent.toUri().getPath();\n                boolean succeeded = true;\n                try {\n                    final String previousCwd = client.pwd();\n                    client.cd(parentDir);\n                    LOG.debug(\"Creating directory \" + pathName);\n                    client.mkdir(pathName);\n                    client.cd(previousCwd);\n                } catch (SftpException e) {\n                    throw new IOException(String.format(E_MAKE_DIR_FORPATH, pathName, parentDir));\n                }\n                created = created & succeeded;\n            }\n        } else if (isFile(client, absolute)) {\n            throw new IOException(String.format(E_DIR_CREATE_FROMFILE, absolute));\n        } else {\n            LOG.debug(\"Skipping creation of existing directory \" + file);\n        }\n        if (!created) {\n            LOG.debug(\"Failed to create \" + file);\n        }\n        return created;\n    }\n\n    private boolean isFile(ChannelSftp channel, Path file) throws IOException {\n        try {\n            return !getFileStatus(channel, file).isDirectory();\n        } catch (FileNotFoundException e) {\n            return false; // file does not exist\n        } catch (IOException ioe) {\n            throw new IOException(E_FILE_CHECK_FAILED, ioe);\n        }\n    }","sourceCodeStart":311,"sourceCodeEnd":347,"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#L311-L347","documentation":"When the target path of mkdirs() already exists as a regular file, the code throws IOException(\"Can't make directory for path %s since it is a file.\"). It is a path-type conflict: a directory operation was requested on something that is not a directory.","triggerScenarios":"mkdirs() (directly, via create()'s implicit parent creation, or via a recursive parent step) finds the existing entry isFile() == true.","commonSituations":"A file was previously written at the exact path where a directory is now required (e.g. output path collides with a marker file); wrong configured output path pointing to a file; leftover file from a previous run with a changed schema layout.","solutions":["Remove or rename the existing file at that path so the directory can be created","Fix the configured output/directory path so it does not collide with a file","Verify with fs.isFile() or getFileStatus().isDirectory() before calling mkdirs in custom code","Clean stale state from previous runs instead of reusing the same base path"],"exampleFix":"// before\nfs.mkdirs(new Path(\"/data/out\")); // /data/out is an existing file\n// after\nPath out = new Path(\"/data/out\");\nif (fs.isFile(out)) { // or getFileStatus(out).isDirectory() == false\n    fs.delete(out, false); // remove conflicting file\n}\nfs.mkdirs(out);","handlingStrategy":"validation","validationCode":"Path p = new Path(\"/data/out\"); if (fs.exists(p) && fs.getFileStatus(p).isDirectory() == false) { throw new IllegalStateException(\"Path is a file: \" + p); }","typeGuard":null,"tryCatchPattern":"try { fs.mkdirs(p); } catch (IOException e) { throw new IllegalStateException(\"Output path conflicts with an existing file: \" + p, e); }","preventionTips":["Choose output base paths distinct from any marker/summary files","Clean stale output dirs from previous runs","Check path type before mkdirs in custom code","Avoid reusing a file path as a directory root across job versions","Verify configured paths against the actual server layout"],"tags":["sftp","mkdir","path-conflict","file-vs-directory"],"backgroundTag":"path-is-not-a-directory","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"}