{"record":{"id":"8268c459d50f32c8","repo":"apache/hadoop","slug":"can-t-make-directory-for-path-s-it-is-a-file","errorCode":null,"errorMessage":"Can't make directory for path '%s', it is a file.","messagePattern":"Can't make directory for path '(.+?)', it is a file\\.","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java","lineNumber":493,"sourceCode":"\n  /**\n   * Validate the path from the bottom up.\n   *\n   * @param path The path to be validated\n   * @throws FileAlreadyExistsException The specified path is an existing file\n   * @throws IOException                Getting the file status of the\n   *                                    specified path occurs\n   *                                    an IOException.\n   */\n  private void validatePath(Path path) throws IOException {\n    Path parent = path.getParent();\n    do {\n      try {\n        FileStatus fileStatus = getFileStatus(parent);\n        if (fileStatus.isDirectory()) {\n          break;\n        } else {\n          throw new FileAlreadyExistsException(String.format(\n              \"Can't make directory for path '%s', it is a file.\", parent));\n        }\n      } catch (FileNotFoundException e) {\n        LOG.debug(\"The Path: [{}] does not exist.\", path);\n      }\n      parent = parent.getParent();\n    } while (parent != null);\n  }\n\n  @Override\n  public boolean mkdirs(Path f, FsPermission permission) throws IOException {\n    try {\n      FileStatus fileStatus = getFileStatus(f);\n      if (fileStatus.isDirectory()) {\n        return true;\n      } else {\n        throw new FileAlreadyExistsException(\"Path is a file: \" + f);\n      }","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java#L475-L511","documentation":"Before creating directories, validatePath walks every ancestor of the requested path; if any ancestor exists as a FILE it throws FileAlreadyExistsException naming that ancestor. This is the object-store equivalent of POSIX ENOTDIR: a directory cannot be created beneath something that is a file. The check walks upward until it finds an existing directory or the root.","triggerScenarios":"fs.mkdirs('/a/b/c') where '/a' or '/a/b' already exists as a file object; chained directory creation after an earlier create() wrote a file at a level now needed as a directory.","commonSituations":"Path layout changed between runs (yesterday /dt=2026 was a file, today /dt=2026/hour=00 needs it as a directory); a partition value collides with an existing file; stale files left by aborted jobs or schema evolution.","solutions":["Locate the offending ancestor (the message names it) and delete or rename it.","Stop reusing a former file path as a directory level; choose a non-colliding layout.","Retry fs.mkdirs after the conflict is removed."],"exampleFix":"// before\nfs.mkdirs(new Path('/data/dt=2026-08-22/hour=00')); // FileAlreadyExistsException: Can't make directory for path '/data/dt=2026-08-22', it is a file.\n\n// after\nPath conflicting = new Path('/data/dt=2026-08-22');\nif (fs.exists(conflicting) && fs.getFileStatus(conflicting).isFile()) {\n  fs.delete(conflicting, false);\n}\nfs.mkdirs(new Path('/data/dt=2026-08-22/hour=00'));","handlingStrategy":"validation","validationCode":"for (Path anc = f.getParent(); anc != null; anc = anc.getParent()) {\n  if (!fs.exists(anc)) { break; } // everything above will be created\n  if (fs.getFileStatus(anc).isFile()) {\n    throw new IllegalStateException('Ancestor exists as a file: ' + anc);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(f);\n} catch (FileAlreadyExistsException e) {\n  // message names the offending ancestor; surface it to the operator\n  throw new IllegalStateException('Conflicting file in path chain: ' + e.getMessage(), e);\n}","preventionTips":["Never let a path prefix be a file at one time and a directory level later","Validate partition paths before writing partitioned data","Clean abandoned files before re-partitioning the same keyspace"],"tags":["cosn","hadoop","mkdirs","enotdir","ancestor-is-file"],"backgroundTag":"parent-path-is-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}