apache/flink · error · IOException

Mkdirs failed to create {targetDir}

Error message

Mkdirs failed to create {targetDir}

What it means

Thrown by CompressionUtils.extractTarFile when the target directory cannot be created with mkdirs(). This is the first step of tar/tgz extraction; if the target dir cannot be created (and does not already exist as a directory), extraction aborts before touching the archive.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java:109

    public static void extractFile(
            String srcFilePath, String targetDirPath, String originalFileName) throws IOException {
        if (hasOneOfSuffixes(originalFileName, ".zip", ".jar")) {
            extractZipFileWithPermissions(srcFilePath, targetDirPath);
        } else if (hasOneOfSuffixes(originalFileName, ".tar", ".tar.gz", ".tgz")) {
            extractTarFile(srcFilePath, targetDirPath);
        } else {
            LOG.warn(
                    "Only zip, jar, tar, tgz and tar.gz suffixes are supported, found {}. Trying to extract it as zip file.",
                    originalFileName);
            extractZipFileWithPermissions(srcFilePath, targetDirPath);
        }
    }

    public static void extractTarFile(String inFilePath, String targetDirPath) throws IOException {
        final File targetDir = new File(targetDirPath);
        if (!targetDir.mkdirs()) {
            if (!targetDir.isDirectory()) {
                throw new IOException("Mkdirs failed to create " + targetDir);
            }
        }
        final boolean gzipped = inFilePath.endsWith("gz");
        if (isUnix()) {
            extractTarFileUsingTar(inFilePath, targetDirPath, gzipped);
        } else {
            extractTarFileUsingJava(inFilePath, targetDirPath, gzipped);
        }
    }

    // Copy and simplify from hadoop-common package that is used in YARN
    // See
    // https://github.com/apache/hadoop/blob/7f93349ee74da5f35276b7535781714501ab2457/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
    private static void extractTarFileUsingTar(
            String inFilePath, String targetDirPath, boolean gzipped) throws IOException {
        inFilePath = makeSecureShellPath(inFilePath);
        targetDirPath = makeSecureShellPath(targetDirPath);
        String untarCommand =

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Verify the target path's parent exists and the process user has write permission (ls -ld on the parent)
  2. Free disk space / remount read-write if the filesystem is full or read-only
  3. Remove or rename the conflicting file occupying the target path, or choose a fresh target directory

Example fix

// before
CompressionUtils.extractTarFile(archivePath, "/opt/flink/work/lib");

// after
File target = new File("/opt/flink/work/lib");
if (target.exists() && !target.isDirectory()) {
    throw new IOException(target + " exists and is not a directory");
}
CompressionUtils.extractTarFile(archivePath, target.getAbsolutePath());
Defensive patterns

Strategy: validation

Validate before calling

File target = new File(targetDirPath);
if (target.exists() && !target.isDirectory()) throw new IOException(target + " is not a directory");
if (!target.exists() && !target.mkdirs()) throw new IOException("Cannot create " + target);

Try / catch

catch (IOException e) around extractTarFile and rethrow with archive path + target path context for actionable logs.

Prevention

When it happens

Trigger: Extracting a tar/tgz (e.g. a Flink distribution or user JAR bundle in YARN/Kubernetes setup) to a path whose parent is not writable, that collides with an existing file, or that lacks permission on the working directory.

Common situations: Insufficient permissions in the container/YARN container working dir; disk full or read-only mount; a stale file exists at the exact target path; path typos pointing at a non-creatable location.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/952d36512f271b4d. Report an issue: GitHub.