{"record":{"id":"952d36512f271b4d","repo":"apache/flink","slug":"mkdirs-failed-to-create-targetdir","errorCode":null,"errorMessage":"Mkdirs failed to create {targetDir}","messagePattern":"Mkdirs failed to create (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java","lineNumber":109,"sourceCode":"    public static void extractFile(\n            String srcFilePath, String targetDirPath, String originalFileName) throws IOException {\n        if (hasOneOfSuffixes(originalFileName, \".zip\", \".jar\")) {\n            extractZipFileWithPermissions(srcFilePath, targetDirPath);\n        } else if (hasOneOfSuffixes(originalFileName, \".tar\", \".tar.gz\", \".tgz\")) {\n            extractTarFile(srcFilePath, targetDirPath);\n        } else {\n            LOG.warn(\n                    \"Only zip, jar, tar, tgz and tar.gz suffixes are supported, found {}. Trying to extract it as zip file.\",\n                    originalFileName);\n            extractZipFileWithPermissions(srcFilePath, targetDirPath);\n        }\n    }\n\n    public static void extractTarFile(String inFilePath, String targetDirPath) throws IOException {\n        final File targetDir = new File(targetDirPath);\n        if (!targetDir.mkdirs()) {\n            if (!targetDir.isDirectory()) {\n                throw new IOException(\"Mkdirs failed to create \" + targetDir);\n            }\n        }\n        final boolean gzipped = inFilePath.endsWith(\"gz\");\n        if (isUnix()) {\n            extractTarFileUsingTar(inFilePath, targetDirPath, gzipped);\n        } else {\n            extractTarFileUsingJava(inFilePath, targetDirPath, gzipped);\n        }\n    }\n\n    // Copy and simplify from hadoop-common package that is used in YARN\n    // See\n    // https://github.com/apache/hadoop/blob/7f93349ee74da5f35276b7535781714501ab2457/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java\n    private static void extractTarFileUsingTar(\n            String inFilePath, String targetDirPath, boolean gzipped) throws IOException {\n        inFilePath = makeSecureShellPath(inFilePath);\n        targetDirPath = makeSecureShellPath(targetDirPath);\n        String untarCommand =","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the target path's parent exists and the process user has write permission (ls -ld on the parent)","Free disk space / remount read-write if the filesystem is full or read-only","Remove or rename the conflicting file occupying the target path, or choose a fresh target directory"],"exampleFix":"// before\nCompressionUtils.extractTarFile(archivePath, \"/opt/flink/work/lib\");\n\n// after\nFile target = new File(\"/opt/flink/work/lib\");\nif (target.exists() && !target.isDirectory()) {\n    throw new IOException(target + \" exists and is not a directory\");\n}\nCompressionUtils.extractTarFile(archivePath, target.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File target = new File(targetDirPath);\nif (target.exists() && !target.isDirectory()) throw new IOException(target + \" is not a directory\");\nif (!target.exists() && !target.mkdirs()) throw new IOException(\"Cannot create \" + target);","typeGuard":null,"tryCatchPattern":"catch (IOException e) around extractTarFile and rethrow with archive path + target path context for actionable logs.","preventionTips":["Pre-create and take ownership of extraction target directories before starting the job/container","Use unique per-run target dirs to avoid permission and collision residue"],"tags":["flink-core","compression","filesystem","permissions","tar"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}