kovidgoyal/kitty · error

Failed to rename temporary file used for downloading to dest

Error message

Failed to rename temporary file used for downloading to destination: %s with error: %w

What it means

When saving clipboard data with a temporary file, the final step renames the temp file onto the destination path. If os.Rename fails (cross-device link, permissions, destination is a directory), the temp file is removed and the error is wrapped with the destination path.

Source

Thrown at kittens/clipboard/read.go:138

		if err != nil {
			self.err = fmt.Errorf("Failed to encode image data to %s with error: %w", self.mime_type, err)
		}
	} else {
		self.dest.Close()
		if !self.is_stream {
			f, err := os.OpenFile(self.arg, os.O_CREATE|os.O_RDONLY, 0666)
			if err == nil {
				fi, err := f.Stat()
				if err == nil {
					self.dest.Chmod(fi.Mode().Perm())
				}
				f.Close()
				os.Remove(f.Name())
			}
			self.err = os.Rename(self.dest.Name(), self.arg)
			if self.err != nil {
				os.Remove(self.dest.Name())
				self.err = fmt.Errorf("Failed to rename temporary file used for downloading to destination: %s with error: %w", self.arg, self.err)
			}
		}
	}
	self.dest = nil
}

func (self *Output) assign_mime_type(available_mimes []string, aliases map[string][]string) (err error) {
	if self.mime_type == "." {
		self.remote_mime_type = "."
		return
	}
	if slices.Contains(available_mimes, self.mime_type) {
		self.remote_mime_type = self.mime_type
		return
	}
	if len(aliases[self.mime_type]) > 0 {
		for _, alias := range aliases[self.mime_type] {
			if slices.Contains(available_mimes, alias) {

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Set TMPDIR to a directory on the same filesystem as the destination: `TMPDIR=/path/to/dest/dir kitten clipboard getfile dest`
  2. Fix write permissions on the destination directory
  3. Ensure the destination is a file path, not an existing directory

Example fix

# before
TMPDIR=/tmp kitten clipboard getfile /mnt/nfs/out.png   # EXDEV
# after
TMPDIR=/mnt/nfs kitten clipboard getfile /mnt/nfs/out.png
Defensive patterns

Strategy: validation

Validate before calling

# same-filesystem tmp dir prevents EXDEV
export TMPDIR="$(dirname "$(readlink -f "$DEST")")"

Prevention

When it happens

Trigger: `kitten clipboard getfile dest` where the temp directory (TMPDIR or /tmp) and the destination are on different filesystems so rename(2) returns EXDEV; destination directory not writable; destination path is an existing directory.

Common situations: /tmp mounted as tmpfs while the destination is on a network mount (NFS, FUSE, sshfs); read-only or permission-restricted download directories; containers where /tmp and the volume differ in mount device.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/a06f679543b7487c. Report an issue: GitHub.