{"record":{"id":"76a3127776ccbf25","repo":"ipfs/kubo","slug":"creating-temp-file-w","errorCode":null,"errorMessage":"creating temp file: %w","messagePattern":"creating temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/update.go","lineNumber":723,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\tif _, err := af.Write(data); err != nil {\n\t\t_ = af.Abort()\n\t\treturn err\n\t}\n\n\treturn af.Close()\n}\n\n// writeBinaryToTempFile writes data to a uniquely named executable file\n// in the system temp directory and returns its path.\nfunc writeBinaryToTempFile(data []byte, ver string) (path string, err error) {\n\tpattern := migrations.ExeName(fmt.Sprintf(\"ipfs-%s-*\", ver))\n\tf, err := os.CreateTemp(\"\", pattern)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"creating temp file: %w\", err)\n\t}\n\tdefer func() {\n\t\tif cerr := f.Close(); cerr != nil && err == nil {\n\t\t\terr = fmt.Errorf(\"closing temp file: %w\", cerr)\n\t\t}\n\t\tif err != nil {\n\t\t\tos.Remove(f.Name())\n\t\t}\n\t}()\n\n\tif _, err = f.Write(data); err != nil {\n\t\treturn \"\", fmt.Errorf(\"writing temp file: %w\", err)\n\t}\n\tif err = f.Sync(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"syncing temp file: %w\", err)\n\t}\n\tif err = f.Chmod(0o755); err != nil {\n\t\treturn \"\", fmt.Errorf(\"chmod temp file: %w\", err)","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/update.go#L705-L741","documentation":"`writeBinaryToTempFile` creates a uniquely named executable temp file (via `os.CreateTemp` with pattern `ipfs-<version>-*`) to hold a downloaded binary before it is atomically moved into place. This error wraps the `os.CreateTemp` failure, meaning no temp file could be created at all.","triggerScenarios":"`ipfs update install`/download path when the system temp dir (TMPDIR or /tmp) is unwritable or full, TMPDIR points to a nonexistent directory, or permission bits on /tmp block the current user.","commonSituations":"Disk-full /tmp; containers running as non-root with a read-only tmpfs; TMPDIR exported incorrectly in scripts; SELinux/AppArmor denying writes to the temp dir.","solutions":["Check the temp dir: `df -h /tmp` and `ls -ld /tmp` (expect drwxrwxrwt); free space or fix permissions.","Set TMPDIR to a writable directory before running the update: `TMPDIR=\"$HOME/tmp\" ipfs update ...` (create it first).","Fix directory ACLs/ownership if running as an unprivileged user in a container; or run with a writable overlayfs layer.","Investigate MAC denials (auditd/SELinux) if permissions look correct but creation still fails."],"exampleFix":"# before\nipfs update install v0.30.0   # creating temp file: open /tmp/...: no space left on device\n\n# after\nclean_tmp_space_or_choose_other_dir\nexport TMPDIR=\"$HOME/tmp\"\nmkdir -p \"$TMPDIR\"\nipfs update install v0.30.0","handlingStrategy":"validation","validationCode":"tmp := os.TempDir()\nprobe := filepath.Join(tmp, \".update-probe\")\nif err := os.WriteFile(probe, []byte(\"x\"), 0o600); err != nil {\n\t// temp dir unusable: repoint TMPDIR or fix permissions before updating\n\tos.Remove(probe)\n}\nif free, _ := freeSpace(tmp); free < 200<<20 {\n\t// less than ~200MB free: clean up first\n}","typeGuard":"func tempDirWritable() bool {\n\tf, err := os.CreateTemp(os.TempDir(), \".kubo-probe-*\")\n\tif err != nil {\n\t\treturn false\n\t}\n\tf.Close()\n\tos.Remove(f.Name())\n\treturn true\n}","tryCatchPattern":"path, err := writeBinaryToTempFile(data, ver)\nif err != nil {\n\tif strings.Contains(err.Error(), \"creating temp file\") {\n\t\t// hint: TMPDIR broken — fall back to an explicit writable dir\n\t\tos.Setenv(\"TMPDIR\", \"/var/tmp\")\n\t\treturn retryUpdate()\n\t}\n\treturn err\n}","preventionTips":["Keep TMPDIR pointing at a writable, POSIX-permission-capable local directory.","Monitor /tmp free space in automation before running updates.","In containers, ensure the writable layer or a bind-mounted TMPDIR has room.","Avoid vfat/exFAT/FUSE mounts for TMPDIR (they also break chmod/fsync later in the flow)."],"tags":["filesystem","temp-file","permissions","update"],"backgroundTag":"temp-dir-unwritable","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"}