apache/flink · error · IOException
Mkdirs failed to create tar internal dir {targetDir}
Error message
Mkdirs failed to create tar internal dir {targetDir} What it means
Thrown when a tar file entry's parent directory does not exist and mkdirs() on it fails. Tar archives sometimes omit directory entries for a file's parents; Flink creates them on demand, and this error means that on-demand parent creation failed (permissions, disk, conflicting file).
Source
Thrown at flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java:197
for (TarArchiveEntry e : entry.getDirectoryEntries()) {
unpackEntry(tis, e, outputFile);
}
return;
}
if (entry.isSymbolicLink()) {
// create symbolic link relative to tar parent dir
Files.createSymbolicLink(
Paths.get(new File(targetDir, entry.getName()).getCanonicalPath()),
Paths.get(entry.getLinkName()));
return;
}
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
throw new IOException("Mkdirs failed to create tar internal dir " + targetDir);
}
}
try (OutputStream o = Files.newOutputStream(Paths.get(outputFile.getCanonicalPath()))) {
IOUtils.copyBytes(tis, o, false);
}
}
/**
* Convert a os-native filename to a path that works for the shell and avoids script injection
* attacks.
*/
private static String makeSecureShellPath(String filePath) {
return filePath.replace("'", "'\\''");
}
public static void extractZipFileWithPermissions(String zipFilePath, String targetPath)
throws IOException {View on GitHub (pinned to 2f3c205e92)
Solutions
- Inspect the reported targetDir and the entry's parent chain for an existing non-directory file and remove it
- Grant write permission to the extracting user on the whole target subtree
- Extract into a clean directory to avoid residue from earlier failed runs
Example fix
// before
CompressionUtils.extractTarFile(tar, "/shared/readonly/dir");
// after
File target = new File(System.getProperty("java.io.tmpdir"), "flink-extract-" + UUID.randomUUID());
CompressionUtils.extractTarFile(tar, target.getAbsolutePath()); Defensive patterns
Strategy: validation
Validate before calling
Path parent = Paths.get(targetDirPath).toAbsolutePath();
if (!Files.isWritable(parent)) throw new IOException("Target not writable: " + parent); Try / catch
catch (IOException e) and rethrow with target dir, archive path, and user running the process for quick permission diagnosis.
Prevention
- Ensure the extracting process owns or can write the whole target subtree
- Clean partial extractions before retrying so no stale file blocks a needed parent dir
When it happens
Trigger: A tar without explicit directory entries (so getParentFile().mkdirs() is needed) extracted into a location where the parent chain cannot be created: no write permission, a file already exists somewhere along the path, or disk exhaustion.
Common situations: Extracting into a directory owned by another user; a previous partial extraction left a file where a directory is now needed; container image with read-only layer at the target path.
Related errors
- Mkdirs failed to create {targetDir}
- Failed to create directory {outputFile}
- Create dir: {outputFile.getAbsolutePath()} failed!
- Interrupted when untarring file {inFilePath}
- Error untarring file {inFilePath}. Tar process exited with e
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/7603399d4539421f.
Report an issue: GitHub.