{"record":{"id":"7b9d3fbc6e07c6d6","repo":"elastic/elasticsearch","slug":"failed-to-create-parent-directory-s-when-creati","errorCode":null,"errorMessage":"Failed to create parent directory '%s' when creating directory '%s'","messagePattern":"Failed to create parent directory '(.+?)' when creating directory '(.+?)'","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/util/FileUtils.java","lineNumber":60,"sourceCode":"        }\n        Collections.reverse(toCreate);\n        for (File parentDirToCreate : toCreate) {\n            if (parentDirToCreate.isDirectory()) {\n                continue;\n            }\n            File parentDirToCreateParent = parentDirToCreate.getParentFile();\n            if (parentDirToCreateParent.isDirectory() == false) {\n                throw new UncheckedIOException(\n                    String.format(\n                        \"Cannot create parent directory '%s' when creating directory '%s' as '%s' is not a directory\",\n                        parentDirToCreate,\n                        dir,\n                        parentDirToCreateParent\n                    )\n                );\n            }\n            if (parentDirToCreate.mkdir() == false && parentDirToCreate.isDirectory() == false) {\n                throw new UncheckedIOException(\n                    String.format(\"Failed to create parent directory '%s' when creating directory '%s'\", parentDirToCreate, dir)\n                );\n            }\n        }\n        if (dir.mkdir() == false && dir.isDirectory() == false) {\n            throw new UncheckedIOException(String.format(\"Failed to create directory '%s'\", dir));\n        }\n    }\n\n    public static String read(File file, String encoding) {\n        try {\n            return org.apache.commons.io.FileUtils.readFileToString(file, encoding);\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n    }\n\n    public static List<String> readLines(File file, String encoding) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/util/FileUtils.java#L42-L78","documentation":"FileUtils.mkdirs() throws when an intermediate parent directory's `mkdir()` returns false AND a follow-up `isDirectory()` still returns false — i.e. the OS refused to create the directory and it isn't already there (the `&&` re-check handles races where another process created it). Distinct from #117 (ancestor is a file) and #119 (the final dir itself fails).","triggerScenarios":"Permissions denied on the parent of a directory to create; read-only filesystem; quota exceeded; a different process holds an exclusive lock; the path component has an illegal name. The parent-of-parent IS a valid directory (passed the #117 check) but creating the child still fails.","commonSituations":"Build running as a user without write permission to the build root; read-only mount (some container/CI sandboxes); disk quota hit; SELinux/AppArmor denying the create; path too long on Windows.","solutions":["Check permissions on the immediate parent of the failing directory (`ls -la <parent>`) and grant write access.","Verify the filesystem is mounted read-write (`mount | grep <path>`).","Clear disk quota issues (`quota -u <user>`) or free inodes (`df -i`).","If sandboxed (container/CI), ensure the build dir is on a writable volume."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File parent = dir.getParentFile();\nif (parent != null && parent.exists() && !parent.canWrite()) {\n  throw new IllegalStateException(\"No write permission on \" + parent + \" for mkdirs\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileUtils.mkdirs(dir);\n} catch (UncheckedIOException e) {\n  if (e.getMessage().contains(\"Failed to create parent directory\")) {\n    // verify permissions / read-only mount / quota, then remediate and retry\n  }\n  throw e;\n}","preventionTips":["Ensure the build directory and its ancestors are writable by the build user.","On CI/container hosts, mount the build volume read-write with adequate quota.","Check `df -h` / `df -i` and `mount` before large builds."],"tags":["gradle","filesystem","io","permissions","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}