{"record":{"id":"3d684102d03b5b2e","repo":"ipfs/kubo","slug":"creating-temporary-file-for-s-w","errorCode":null,"errorMessage":"creating temporary file for %s: %w","messagePattern":"creating temporary file for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/keystore.go","lineNumber":368,"sourceCode":"\tif err == nil {\n\t\tif info.Mode()&inPlaceModes != 0 {\n\t\t\treturn writeExportedKeyInPlace(outPath, writeKey)\n\t\t}\n\t\tif !info.Mode().IsRegular() {\n\t\t\treturn fmt.Errorf(\"refusing to export key to %s: not a regular file, character device or pipe\", outPath)\n\t\t}\n\t}\n\n\t// The key is written next to the target and renamed over it, so replace\n\t// what a symlink points at rather than the symlink itself.\n\toutPath, err = resolveSymlink(outPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfile, err := atomicfile.New(outPath, exportedKeyFileMode)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating temporary file for %s: %w\", outPath, err)\n\t}\n\tif err := writeKey(file); err != nil {\n\t\treturn errors.Join(err, file.Abort())\n\t}\n\t// Flush before the rename, so a crash cannot leave an empty file where the\n\t// previous export was.\n\tif err := file.Sync(); err != nil {\n\t\treturn errors.Join(fmt.Errorf(\"flushing %s: %w\", outPath, err), file.Abort())\n\t}\n\tif err := file.Close(); err != nil {\n\t\treturn fmt.Errorf(\"writing %s: %w\", outPath, err)\n\t}\n\treturn nil\n}\n\n// resolveSymlink returns the path a chain of symlinks ends at.\n// filepath.EvalSymlinks cannot be used on the path as a whole: it fails when\n// the last link points at a file that does not exist yet, and such a link","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/keystore.go#L350-L386","documentation":"Before writing, writeExportedKey creates a temporary file next to the target via atomicfile.New (so the final file is renamed into place atomically with 0600 permissions). This error wraps the failure of that temp-file creation: atomicfile needs the parent directory to exist and be writable. The key is never touched — nothing was written yet.","triggerScenarios":"`ipfs key export <name> -o <path>` where the target's parent directory does not exist, is not writable, or the resolved path (after symlink resolution) is invalid — e.g. exporting into a read-only volume or a path under a nonexistent directory.","commonSituations":"Typo in the output directory path; exporting to a read-only bind mount (atomic-file rename is impossible there); container with read-only filesystem; missing directory created by a previous step that failed.","solutions":["Ensure the parent directory of -o exists: `mkdir -p $(dirname <path>)`","Check write permission on the parent directory for the user running the node","Use a writable location (the error's %w shows the underlying errno — ENOENT vs EACCES vs EROFS)","On read-only mounts, export elsewhere and copy, since atomic rename cannot target read-only directories"],"exampleFix":"// before\nipfs key export mykey -o /nonexistent/dir/mykey.pem\n// after\nmkdir -p /nonexistent/dir && ipfs key export mykey -o /nonexistent/dir/mykey.pem","handlingStrategy":"validation","validationCode":"test -d \"$(dirname \"$out\")\" && test -w \"$(dirname \"$out\")\" || { mkdir -p \"$(dirname \"$out\")\"; }\n# and confirm the fs is writable:\ntouch \"$(dirname \"$out\")/.wtest\" 2>/dev/null && rm \"$(dirname \"$out\")/.wtest\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["mkdir -p the output directory before exporting","Avoid read-only mounts as export targets (atomic rename needs a writable dir)","In containers, mount the key-export volume read-write"],"tags":["cli","keystore","filesystem","permissions"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}