{"record":{"id":"299fffd1d29a545f","repo":"hashicorp/packer","slug":"unable-to-create-dir-s","errorCode":null,"errorMessage":"unable to create dir: %s","messagePattern":"unable to create dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/checksum/post-processor.go","lineNumber":136,"sourceCode":"\n\tnewartifact := NewArtifact(artifact.Files())\n\n\tfor _, ct := range p.config.ChecksumTypes {\n\t\th = getHash(ct)\n\t\tgeneratedData[\"ChecksumType\"] = ct\n\t\tp.config.ctx.Data = generatedData\n\n\t\tfor _, art := range files {\n\t\t\tchecksumFile, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, true, err\n\t\t\t}\n\n\t\t\tif _, err := os.Stat(checksumFile); err != nil {\n\t\t\t\tnewartifact.files = append(newartifact.files, checksumFile)\n\t\t\t}\n\t\t\tif err := os.MkdirAll(filepath.Dir(checksumFile), os.FileMode(0755)); err != nil {\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to create dir: %s\", err.Error())\n\t\t\t}\n\t\t\tfw, err := os.OpenFile(checksumFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0644))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to create file %s: %s\", checksumFile, err.Error())\n\t\t\t}\n\t\t\tfr, err := os.Open(art)\n\t\t\tif err != nil {\n\t\t\t\tfw.Close()\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to open file %s: %s\", art, err.Error())\n\t\t\t}\n\n\t\t\tif _, err = io.Copy(h, fr); err != nil {\n\t\t\t\tfr.Close()\n\t\t\t\tfw.Close()\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to compute %s hash for %s\", ct, art)\n\t\t\t}\n\t\t\tfr.Close()\n\t\t\t_, _ = fw.WriteString(fmt.Sprintf(\"%x\\t%s\\n\", h.Sum(nil), filepath.Base(art)))","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/checksum/post-processor.go#L118-L154","documentation":"PostProcess-time failure in the checksum post-processor: before writing each checksum file it ensures the parent directory exists with os.MkdirAll; if that fails (permission denied, path is a file, read-only volume) the whole post-process aborts with keep=true. The wrapped OS error details the cause.","triggerScenarios":"The rendered output template resolves to a directory that cannot be created, e.g. output = \"/etc/packer/out.checksum\" (no permission), output under a read-only mount, or a path component exists as a regular file so MkdirAll returns ENOTDIR.","commonSituations":"Absolute paths pointing into protected system directories; output on a read-only container volume; existing FILE conflicting with an intended directory in the path; SELinux/AppArmor denials.","solutions":["Set `output` to a path under a writable directory you control (relative paths resolve under the working/output directory)","Check ownership/permissions of the target's parent and pre-create the directory yourself","Ensure no file exists at a path component where a directory is required","Verify mount flags / security policies if running in a container"],"exampleFix":"// before\noutput = \"/usr/local/share/packer/{{.BuildName}}.checksum\"\n// after\noutput = \"out/{{.BuildName}}.checksum\"","handlingStrategy":"validation","validationCode":"// shell: pre-flight check that the output directory is creatable/writable\nOUT=\"$(pwd)/out\"\nmkdir -p \"$OUT\" || { echo \"cannot create $OUT\"; exit 1; }\ntest -w \"$OUT\" || { echo \"$OUT not writable\"; exit 1; }\n# also ensure no file occupies a path component:\nwhile [ -f \"$(dirname \"$OUT\")\" ]; do echo \"conflict\"; exit 1; done","typeGuard":null,"tryCatchPattern":"artifact, _, _, err := pp.PostProcess(ctx, ui, art)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to create dir\") {\n        // fix permissions / path collision, rerun\n    }\n    return err\n}","preventionTips":["Keep `output` under a directory the Packer user owns","Avoid absolute paths into system directories (/etc, /usr)","Pre-create and chmod the output directory in CI before the build","Check for existing files that collide with required directory components","Account for SELinux/AppArmor and read-only mounts in containers"],"tags":["packer","post-processor","checksum","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}