chenhg5/cc-connect · error

create temp file: %w

Error message

create temp file: %w

What it means

replaceBinary creates a temporary file (cc-connect-update-*) in the executable's directory via os.CreateTemp; failure is wrapped as "create temp file: %w". The updater writes in-place next to the binary so the final rename is atomic on the same filesystem.

Source

Thrown at core/updater.go:258

		}
	}
	return nil, fmt.Errorf("cc-connect binary not found in zip archive")
}

func replaceBinary(newBinary []byte) error {
	execPath, err := os.Executable()
	if err != nil {
		return fmt.Errorf("get executable path: %w", err)
	}
	execPath, err = filepath.EvalSymlinks(execPath)
	if err != nil {
		return fmt.Errorf("resolve symlinks: %w", err)
	}

	dir := filepath.Dir(execPath)
	tmpFile, err := os.CreateTemp(dir, "cc-connect-update-*")
	if err != nil {
		return fmt.Errorf("create temp file: %w", err)
	}
	tmpPath := tmpFile.Name()

	if _, err := tmpFile.Write(newBinary); err != nil {
		tmpFile.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("write new binary: %w", err)
	}
	tmpFile.Close()

	if err := os.Chmod(tmpPath, 0o755); err != nil {
		os.Remove(tmpPath)
		return fmt.Errorf("chmod: %w", err)
	}

	oldPath := execPath + ".old"
	os.Remove(oldPath)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Re-run the update with sufficient privileges (e.g. sudo cc-connect update) or chown/chmod the install directory so the running user can write: sudo chown $(whoami) $(dirname $(readlink -f $(which cc-connect))).
  2. Free disk space / inodes (df -h, df -i) if the volume is full.
  3. Remount the filesystem read-write if it is mounted ro, or move the installation to a writable location.
  4. Check for chattr +i (immutable) on the directory or binary and remove it.
  5. If self-update to a system path is undesirable, install the binary in a user-writable prefix (e.g. ~/.local/bin) and update from there.

Example fix

# before
$ cc-connect update
# create temp file: open /usr/local/bin/cc-connect-update-*: permission denied
# after
$ sudo chown -R $(whoami) /usr/local/bin && cc-connect update
Defensive patterns

Strategy: validation

Validate before calling

dir := filepath.Dir(realExecPath)
if info, err := os.Stat(dir); err != nil || info.Mode()&0o200 == 0 {
    return fmt.Errorf("install dir not writable: %s", dir)
}
if err := syscall.Access(dir, unix.W_OK); err != nil {
    return fmt.Errorf("no write permission in %s: %v", dir, err)
}

Try / catch

if err := selfUpdate(); err != nil {
    if strings.Contains(err.Error(), "create temp file") {
        // rerun with sudo or chown the install dir
    }
}

Prevention

When it happens

Trigger: SelfUpdate -> replaceBinary: os.CreateTemp(dir) failed — directory not writable by the running user (installed root-owned in /usr/local/bin, running as non-root), directory read-only, disk full (no inode/space), or the directory vanished after EvalSymlinks.

Common situations: Daemon running as an unprivileged user but binary owned by root (most common); immutable bit set on install dir; container filesystem mounted read-only; full disk/inode exhaustion on the host volume.

Understand the failure class

Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/81a02327de89690b. Report an issue: GitHub.