apache/hadoop · error · IOException
Mkdirs failed to create " + untarDir
Error message
Mkdirs failed to create " + untarDir
What it means
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.
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)
Example fix
// before
FileUtil.unTar(in, new File("/tmp/work"), false);
// Mkdirs failed to create /tmp/work
// after
File untarDir = new File("/tmp/work");
if (untarDir.exists() && !untarDir.isDirectory()) {
Files.delete(untarDir.toPath());
}
Files.createDirectories(untarDir.toPath());
FileUtil.unTar(in, untarDir, false); Defensive patterns
Strategy: validation
Validate before calling
File untarDir = new File("/tmp/work");
if (untarDir.exists() && !untarDir.isDirectory()) {
throw new IOException("Path occupied by a file: " + untarDir);
}
Files.createDirectories(untarDir.toPath()); // pre-create; unTar tolerates existing dirs Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Mkdirs failed to create tar internal dir " + outputDir
- Mkdirs failed to create " + file.getParentFile().toString()
- Mkdirs failed to create " + parent.getAbsolutePath()
- Cannot create directory
- Error executing command.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/56199c0b8c0c1282.
Report an issue: GitHub.
Appendix: source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:990
* Given a Tar File as input it will untar the file in a the untar directory
* passed as the second parameter
*
* This utility will untar ".tar" files and ".tar.gz","tgz" files.
*
* @param inputStream The tar file as input.
* @param untarDir The untar directory where to untar the tar file.
* @param gzipped The input stream is gzipped
* TODO Use magic number and PusbackInputStream to identify
* @throws IOException an exception occurred
* @throws InterruptedException command interrupted
* @throws ExecutionException task submit failed
*/
public static void unTar(InputStream inputStream, File untarDir,
boolean gzipped)
throws IOException, InterruptedException, ExecutionException {
if (!untarDir.mkdirs()) {
if (!untarDir.isDirectory()) {
throw new IOException("Mkdirs failed to create " + untarDir);
}
}
if(Shell.WINDOWS) {
// Tar is not native to Windows. Use simple Java based implementation for
// tests and simple tar archives
unTarUsingJava(inputStream, untarDir, gzipped);
} else {
// spawn tar utility to untar archive for full fledged unix behavior such
// as resolving symlinks in tar archives
unTarUsingTar(inputStream, untarDir, gzipped);
}
}
/**
* Given a Tar File as input it will untar the file in a the untar directory
* passed as the second parameter
*View on GitHub (pinned to 2add963021)