{"record":{"id":"9cc786f062ce2c34","repo":"ipfs/kubo","slug":"writing-temp-file-w","errorCode":null,"errorMessage":"writing temp file: %w","messagePattern":"writing temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/update.go","lineNumber":735,"sourceCode":"// 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)\n\t}\n\treturn f.Name(), nil\n}\n\n// extractBinaryFromArchive extracts the kubo/ipfs binary from a tar.gz or zip archive.\nfunc extractBinaryFromArchive(data []byte) ([]byte, error) {\n\tbinName := migrations.ExeName(\"ipfs\")\n\n\t// Try tar.gz first (Unix releases), then zip (Windows releases).\n\tresult, tarErr := extractFromTarGz(data, binName)\n\tif tarErr == nil {\n\t\treturn result, nil","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/update.go#L717-L753","documentation":"`writeBinaryToTempFile` wraps a failure of `f.Write(data)` with this message while writing the downloaded kubo binary bytes into the temp executable. The write could not complete (fully or at all), so the staged binary is incomplete; the deferred cleanup removes the partial file.","triggerScenarios":"`ipfs update install` when the temp filesystem fills during the write, the storage device reports an I/O error, or the write is interrupted (fs unmounted, quota exceeded on TMPDIR).","commonSituations":"Updating a large kubo binary onto a nearly-full /tmp or small tmpfs; per-user disk quotas hit during the write; failing disk sectors; container ephemeral storage limits.","solutions":["Check free space and quota: `df -h \"$TMPDIR\"` and `quota -s`; free space or point TMPDIR at a larger filesystem.","Rerun the update — the partial temp file is removed automatically, so a retry is safe.","Check `dmesg` for block-device errors if space is not the issue.","For containers, raise the ephemeral-storage/tmpfs size or bind-mount a larger directory as TMPDIR."],"exampleFix":"// diagnosis\nls -l \"$TMPDIR\"/ipfs-*          # partial file (removed automatically)\ndf -h \"$TMPDIR\"                  # 0 available\n\n# after freeing space or repointing TMPDIR\nexport TMPDIR=/var/tmp\nipfs update install v0.30.0","handlingStrategy":"validation","validationCode":"// ensure room for the new binary before staging\nconst minFree = 200 << 20\nif free, err := freeSpace(os.TempDir()); err != nil || free < minFree {\n\t// abort early: temp filesystem cannot hold the binary\n}\n// and ensure quota headroom\nif quotaExceeded(os.Getuid()) { /* clean up or switch TMPDIR */ }","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tvar perr *os.PathError\n\tif errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOSPC) {\n\t\treturn fmt.Errorf(\"temp filesystem full; free space on %s and retry\", os.TempDir())\n\t}\n\treturn err\n}","preventionTips":["Keep several hundred MB free on the TMPDIR filesystem.","Check user disk quota on /tmp in multi-user systems before updating.","Avoid small tmpfs for TMPDIR in containers and CI.","Monitor dmesg for EIO so failing disks are replaced before updates."],"tags":["io","write","disk-full","update"],"backgroundTag":"disk-full-io-error","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"}