kubernetes/kops · error

error creating temporary file for download %q: %v

Error message

error creating temporary file for download %q: %v

What it means

The downloader creates a hidden temp file ('.<base>.tmp') in the destination directory via os.CreateTemp, then downloads into it before an atomic rename. Failure to create the temp file (usually permissions or no space) is wrapped with this message.

Source

Thrown at upup/pkg/fi/http.go:61

			return nil, err
		}
		if match {
			return hash, nil
		}
	}

	return downloadURLToFile(ctx, url, dest, hash)
}

func downloadURLToFile(ctx context.Context, url string, destPath string, hash *hashing.Hash) (*hashing.Hash, error) {
	dir := filepath.Dir(destPath)
	if err := os.MkdirAll(dir, 0o755); err != nil {
		return nil, fmt.Errorf("error creating directories for destination file %q: %v", destPath, err)
	}

	output, err := os.CreateTemp(dir, "."+filepath.Base(destPath)+".tmp")
	if err != nil {
		return nil, fmt.Errorf("error creating temporary file for download %q: %v", destPath, err)
	}
	tempPath := output.Name()
	defer os.Remove(tempPath)

	actual, err := downloadURLToWriter(ctx, url, output, hash)
	if closeErr := output.Close(); closeErr != nil && err == nil {
		err = closeErr
	}
	if err != nil {
		return nil, err
	}
	if err := os.Chmod(tempPath, 0o644); err != nil {
		return nil, fmt.Errorf("error setting mode on downloaded file %q: %v", tempPath, err)
	}
	if err := os.Rename(tempPath, destPath); err != nil {
		return nil, fmt.Errorf("error moving downloaded file %q to %q: %v", tempPath, destPath, err)
	}
	return actual, nil

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check disk space (df -h) and free space if ENOSPC
  2. Verify the destination directory is writable by the current user
  3. Check ulimit -n if 'too many open files' appears in the wrapped error
  4. Point the download at a writable directory

Example fix

// before
df -h /usr/local  -> 100% full
// after
clean up disk space or choose a different destination, then retry the download
Defensive patterns

Strategy: validation

Validate before calling

// Check writability and free space of the target directory first
if err := unix.Access(dir, unix.W_OK); err != nil { return err }
// and: df -h <dir> / statfs for available space before large downloads

Try / catch

if _, err := fi.DownloadURL(ctx, url, dest, nil); err != nil {
    var se *os.PathError
    if errors.As(err, &se) && errors.Is(se.Err, syscall.ENOSPC) {
        return fmt.Errorf("disk full while downloading %s", dest)
    }
    return err
}

Prevention

When it happens

Trigger: os.CreateTemp(dir, "."+base+".tmp") fails: destination dir not writable, disk full, or too many open files.

Common situations: Read-only or non-writable target directory; ENOSPC on the partition; file-descriptor limits hit during large operations.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/51fd4af1b15d6589. Report an issue: GitHub.