{"record":{"id":"baf63744c11a6c51","repo":"hashicorp/packer","slug":"unable-to-create-file-s-s","errorCode":null,"errorMessage":"unable to create file %s: %s","messagePattern":"unable to create file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/checksum/post-processor.go","lineNumber":140,"sourceCode":"\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)))\n\t\t\tfw.Close()\n\t\t\th.Reset()\n\t\t}\n\t}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/checksum/post-processor.go#L122-L158","documentation":"PostProcess-time failure in the checksum post-processor: after creating parent directories, it opens the checksum output file with os.OpenFile (O_WRONLY|O_APPEND|O_CREATE, 0644); failure (permission denied, path is a directory, disk full) aborts with keep=true. The path and wrapped OS error are included.","triggerScenarios":"The rendered checksum file path cannot be opened for writing — e.g. output template resolves to an existing DIRECTORY (checksumFile collides with a directory name), the directory isn't writable by the Packer user, or the filesystem is out of space/inodes.","commonSituations":"Output path ending in \"/\" or resolving to a directory; prior build created a directory with the same name; running Packer as a non-root user against a root-owned directory; read-only volume or full disk in CI.","solutions":["Make sure `output` resolves to a file path, not a directory, and doesn't collide with existing directories","Grant write permission on the target directory to the user running Packer","Free disk space / check inode usage on the target filesystem","Choose a fresh output name (the file is opened in append mode, so consider removing stale checksum files first)"],"exampleFix":"// before\noutput = \"out/{{.BuildName}}/\"  // resolves to a directory\n// after\noutput = \"out/{{.BuildName}}.sha256.checksum\"","handlingStrategy":"validation","validationCode":"// shell: ensure the checksum output path is a writable file path\nOUT=\"$(pwd)/out/packer.checksum\"\ntest ! -d \"$OUT\" || { echo \"$OUT is a directory\"; exit 1; }\nmkdir -p \"$(dirname \"$OUT\")\"\ntest -w \"$(dirname \"$OUT\")\" || { echo \"dir not writable\"; exit 1; }\ndf -h \"$(dirname \"$OUT\")\" | awk 'NR==2 {if ($5+0 >= 95) {print \"disk nearly full\"; exit 1}}'","typeGuard":null,"tryCatchPattern":"artifact, _, _, err := pp.PostProcess(ctx, ui, art)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to create file\") {\n        // fix path collision/permissions/space, then rerun\n    }\n    return err\n}","preventionTips":["Make the `output` template resolve to a file, never a directory or trailing slash","Run Packer as a user with write access to the output directory","Monitor disk space/inodes on the output filesystem","Remove stale checksum files from prior runs (output opens in append mode)"],"tags":["packer","post-processor","checksum","filesystem","permissions"],"backgroundTag":"file-write-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"}