ipfs/kubo · error
error creating output file '%s': %w
Error message
error creating output file '%s': %w
What it means
writeToPath opens (or creates) the output file with os.Create to receive the extracted migration binary. If the file cannot be created — because of permissions, a missing parent directory, or a path conflict with a directory — the underlying OS error is wrapped with the output path and returned. The wrapped cause identifies the exact OS-level reason.
Source
Thrown at repo/fsrepo/migrations/unpack.go:99
return fmt.Errorf("error extracting binary from archive: %w", err)
}
bin = rc
break
}
}
if bin == nil {
return errors.New("no binary found in archive")
}
return writeToPath(bin, out)
}
func writeToPath(rc io.Reader, out string) error {
binfi, err := os.Create(out)
if err != nil {
return fmt.Errorf("error creating output file '%s': %w", out, err)
}
defer binfi.Close()
_, err = io.Copy(binfi, rc)
return err
}
View on GitHub (pinned to 329838acdf)
Solutions
- Ensure the parent directory of the output path exists (os.MkdirAll) before unpacking.
- Check and fix permissions on the target path: chmod/chown or choose a writable directory.
- If writing to a system path, re-run with elevated privileges or install to a user-writable location on PATH.
- Inspect the wrapped %w cause (e.g. EACCES, ENOSPC) and address the underlying OS condition (free disk, remount rw).
Example fix
// before
err := migrations.Unpack(archivePath, out)
// after: make sure the destination dir exists first
if err := os.MkdirAll(filepath.Dir(out), 0o755); err != nil {
return err
}
err := migrations.Unpack(archivePath, out) Defensive patterns
Strategy: validation
Validate before calling
dir := filepath.Dir(out)
if err := os.MkdirAll(dir, 0o755); err != nil { return err }
if info, err := os.Stat(out); err == nil && info.IsDir() {
return fmt.Errorf("%s is a directory", out)
}
test, err := os.OpenFile(out, os.O_CREATE|os.O_WRONLY, 0o755)
if err != nil { return err }
test.Close() Prevention
- Always MkdirAll the parent directory before writing outputs.
- Choose install targets on PATH that the current user can write.
- Check free disk space before extracting binaries.
- Unwrap the %w cause with errors.As(*fs.PathError) to distinguish EACCES vs ENOSPC.
When it happens
Trigger: Calling unpackArchive/unpackTgz/unpackZip where the `out` path is unwritable: parent directory does not exist, the path is a directory, the process lacks write permission, the disk is full, or out is read-only (e.g. installing into /usr/local/bin without root).
Common situations: Running ipfs-update without elevated privileges when writing to a system bin dir, IPFS_PATH pointing at a directory deleted or recreated with different ownership, read-only container filesystems, or disk exhaustion on small VPSes.
Related errors
- opening binary %q: %w
- serveHTTPApi: SetAPIAddr() failed: %w
- %s is not writeable by the current user
- unexpected error while checking writeablility of repo root:
- cannot write to %s, incorrect permissions
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/508cb12551a52ba5.
Report an issue: GitHub.