apache/flink · error · IOException

Failed to create directory

Error message

Failed to create directory {outputFile}

What it means

Thrown while unpacking a tar entry that is a directory: File.mkdirs() returned false and the path is not an existing directory. The archive was validated (no traversal) but the filesystem refused to create the directory entry.

Solutions

  1. Check what already exists at the failing path: a stale regular file where a directory is expected must be removed
  2. Extract to a fresh, empty target directory to avoid clashes with previous runs
  3. On Windows, verify the entry name is legal (no ':' , not a reserved device name); consider extracting on a Unix-like filesystem
  4. Confirm write permissions and path-length limits of the target filesystem

Example fix

// before
CompressionUtils.extractTarFile(tarPath, reusedDirtyDir);

// after
File target = new File(freshDir);
org.apache.flink.util.FileUtils.deleteDirectoryQuietly(target); // or use a new dir per run
target.mkdirs();
CompressionUtils.extractTarFile(tarPath, target.getAbsolutePath());
Defensive patterns

Strategy: validation

Validate before calling

File target = new File(targetDirPath);
if (!target.exists() && !target.mkdirs()) throw new IOException("Cannot prepare " + target);
if (!target.canWrite()) throw new IOException("No write permission on " + target);

Try / catch

catch (IOException e) around extraction; include the failing entry name (from the message) plus target dir in the rethrown context.

Prevention

When it happens

Trigger: A tar directory entry whose name cannot be created on the target filesystem: path too long, permission denied in the parent, a regular file already exists at that path, or an invalid name for the platform (e.g. reserved Windows names like CON, or entries containing ':').

Common situations: Extracting Linux-created archives on Windows hitting reserved characters; leftover file (not directory) at the entry path from a previous extraction; read-only or full target volume; deep nesting exceeding filesystem path limits.

Related errors


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

Appendix: source

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

            TarArchiveEntry entry;
            while ((entry = tai.getNextTarEntry()) != null) {
                unpackEntry(tai, entry, targetDir);
            }
        }
    }

    private static void unpackEntry(
            TarArchiveInputStream tis, TarArchiveEntry entry, File targetDir) throws IOException {
        String targetDirPath = targetDir.getCanonicalPath() + File.separator;
        File outputFile = new File(targetDir, entry.getName());
        if (!outputFile.getCanonicalPath().startsWith(targetDirPath)) {
            throw new IOException(
                    "expanding " + entry.getName() + " would create entry outside of " + targetDir);
        }

        if (entry.isDirectory()) {
            if (!outputFile.mkdirs() && !outputFile.isDirectory()) {
                throw new IOException("Failed to create directory " + outputFile);
            }

            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()) {

View on GitHub (pinned to 2f3c205e92)