ipfs/kubo · error
creating temp file: %w
Error message
creating temp file: %w
What it means
`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.
Source
Thrown at core/commands/update.go:723
if err != nil {
return err
}
if _, err := af.Write(data); err != nil {
_ = af.Abort()
return err
}
return af.Close()
}
// writeBinaryToTempFile writes data to a uniquely named executable file
// in the system temp directory and returns its path.
func writeBinaryToTempFile(data []byte, ver string) (path string, err error) {
pattern := migrations.ExeName(fmt.Sprintf("ipfs-%s-*", ver))
f, err := os.CreateTemp("", pattern)
if err != nil {
return "", fmt.Errorf("creating temp file: %w", err)
}
defer func() {
if cerr := f.Close(); cerr != nil && err == nil {
err = fmt.Errorf("closing temp file: %w", cerr)
}
if err != nil {
os.Remove(f.Name())
}
}()
if _, err = f.Write(data); err != nil {
return "", fmt.Errorf("writing temp file: %w", err)
}
if err = f.Sync(); err != nil {
return "", fmt.Errorf("syncing temp file: %w", err)
}
if err = f.Chmod(0o755); err != nil {
return "", fmt.Errorf("chmod temp file: %w", err)View on GitHub (pinned to 329838acdf)
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.
Example fix
# before ipfs update install v0.30.0 # creating temp file: open /tmp/...: no space left on device # after clean_tmp_space_or_choose_other_dir export TMPDIR="$HOME/tmp" mkdir -p "$TMPDIR" ipfs update install v0.30.0
Defensive patterns
Strategy: validation
Validate before calling
tmp := os.TempDir()
probe := filepath.Join(tmp, ".update-probe")
if err := os.WriteFile(probe, []byte("x"), 0o600); err != nil {
// temp dir unusable: repoint TMPDIR or fix permissions before updating
os.Remove(probe)
}
if free, _ := freeSpace(tmp); free < 200<<20 {
// less than ~200MB free: clean up first
} Type guard
func tempDirWritable() bool {
f, err := os.CreateTemp(os.TempDir(), ".kubo-probe-*")
if err != nil {
return false
}
f.Close()
os.Remove(f.Name())
return true
} Try / catch
path, err := writeBinaryToTempFile(data, ver)
if err != nil {
if strings.Contains(err.Error(), "creating temp file") {
// hint: TMPDIR broken — fall back to an explicit writable dir
os.Setenv("TMPDIR", "/var/tmp")
return retryUpdate()
}
return err
} Prevention
- 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).
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- reading stash directory: %w
- chmod temp file: %w
- serveHTTPApi: SetAPIAddr() failed: %w
- %s is not writeable by the current user
- cannot write to %s, incorrect permissions
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/76a3127776ccbf25.
Report an issue: GitHub.