{"record":{"id":"56199c0b8c0c1282","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-untardir","errorCode":null,"errorMessage":"Mkdirs failed to create \" + untarDir","messagePattern":"Mkdirs failed to create \" \\+ untarDir","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":990,"sourceCode":"   * Given a Tar File as input it will untar the file in a the untar directory\n   * passed as the second parameter\n   *\n   * This utility will untar \".tar\" files and \".tar.gz\",\"tgz\" files.\n   *\n   * @param inputStream The tar file as input.\n   * @param untarDir The untar directory where to untar the tar file.\n   * @param gzipped The input stream is gzipped\n   *                TODO Use magic number and PusbackInputStream to identify\n   * @throws IOException an exception occurred\n   * @throws InterruptedException command interrupted\n   * @throws ExecutionException task submit failed\n   */\n  public static void unTar(InputStream inputStream, File untarDir,\n                           boolean gzipped)\n      throws IOException, InterruptedException, ExecutionException {\n    if (!untarDir.mkdirs()) {\n      if (!untarDir.isDirectory()) {\n        throw new IOException(\"Mkdirs failed to create \" + untarDir);\n      }\n    }\n\n    if(Shell.WINDOWS) {\n      // Tar is not native to Windows. Use simple Java based implementation for\n      // tests and simple tar archives\n      unTarUsingJava(inputStream, untarDir, gzipped);\n    } else {\n      // spawn tar utility to untar archive for full fledged unix behavior such\n      // as resolving symlinks in tar archives\n      unTarUsingTar(inputStream, untarDir, gzipped);\n    }\n  }\n\n  /**\n   * Given a Tar File as input it will untar the file in a the untar directory\n   * passed as the second parameter\n   *","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L972-L1008","documentation":"unTar(InputStream inputStream, File untarDir, boolean gzipped) starts by calling untarDir.mkdirs(); if that returns false and untarDir.isDirectory() is still false it throws IOException(\"Mkdirs failed to create <untarDir>\"). The re-check tolerates a directory that already exists or was concurrently created, so the throw means the extraction target could not be created at all. This fails before any archive bytes are read.","triggerScenarios":"untarDir's parent is not writable; a regular FILE exists at the untarDir path; read-only mount or SELinux denial; the path component is a symlink to a nonexistent location.","commonSituations":"Extracting to /tmp/${user}-dirs after /tmp was locked down; target path pre-existing as a file from a prior run; containers with read-only rootfs; NFS permission mismatches.","solutions":["Check for and remove any regular file occupying untarDir, or pick a fresh unique directory","Ensure the parent of untarDir is writable by the process user (mkdir -p by hand to see the OS error)","Pre-create the directory yourself with Files.createDirectories() and pass it in — unTar tolerates existing dirs","On denials, fix mount options or policy (rw, exec, SELinux context)"],"exampleFix":"// before\nFileUtil.unTar(in, new File(\"/tmp/work\"), false);\n// Mkdirs failed to create /tmp/work\n\n// after\nFile untarDir = new File(\"/tmp/work\");\nif (untarDir.exists() && !untarDir.isDirectory()) {\n  Files.delete(untarDir.toPath());\n}\nFiles.createDirectories(untarDir.toPath());\nFileUtil.unTar(in, untarDir, false);","handlingStrategy":"validation","validationCode":"File untarDir = new File(\"/tmp/work\");\nif (untarDir.exists() && !untarDir.isDirectory()) {\n  throw new IOException(\"Path occupied by a file: \" + untarDir);\n}\nFiles.createDirectories(untarDir.toPath()); // pre-create; unTar tolerates existing dirs","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the untar directory and let unTar see it already exists","Never let a regular file occupy the untarDir path","Confirm parent writability and rw mount before extraction jobs"],"tags":["mkdir-failed","untar","permissions","archive-extraction"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}