kopia/kopia · error

cannot sync temporary file in dir

Error message

cannot sync temporary file in dir %s

What it means

After successfully writing data, writeTempFileAtomicImp calls tf.Sync to force the data to stable storage before the file is renamed into place. A Sync failure is wrapped with this message, which includes the directory, and aborts the atomic write. It protects durability guarantees: content is never published unless it has been flushed.

Solutions

  1. Check disk space and quota on the reported directory's volume.
  2. Verify the filesystem supports fsync (avoid problematic network/FUSE mounts for the cache).
  3. Check device health (smartctl/dmesg) for recurring sync I/O errors.
  4. Retry after resolving; the atomic design means no corrupted half-written content was published.
Defensive patterns

Strategy: try-catch

Validate before calling

// probe fsync support before writing content
pf, _ := os.CreateTemp(cacheDir, "synctest")
if pf != nil { if err := pf.Sync(); err != nil { log.Warnf("fsync unsupported/broken on %s", cacheDir) }; pf.Close(); os.Remove(pf.Name()) }

Try / catch

if err != nil && strings.Contains(err.Error(), "cannot sync temporary file in dir") {
    // non-durable write was NOT published; alert and retry on healthy storage
    alertStorageIssue(err)
    return err
}

Prevention

When it happens

Trigger: tf.Sync() fails on the just-written temp file: ENOSPC while flushing, EIO from the device, or unsupported-sync semantics on exotic filesystems/network mounts hosting dirname.

Common situations: Disks filling up exactly during a backup; failing storage devices; filesystems (some FUSE/network mounts) that do not support fsync properly; container volumes with flaky backing stores.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/6c3d2bb82601ba8c. Report an issue: GitHub.

Appendix: source

Thrown at repo/content/write_temp_file.go:82

			err = stderrors.Join(err, errors.Wrap(cerr, "can't close tmp file"))
		}

		if err != nil {
			// remove tmp file on error to avoid leaving them behind
			if rerr := fsi.Remove(tf.Name()); rerr != nil {
				err = stderrors.Join(err, errors.Wrap(rerr, "can't remove tmp file"))
			}

			filename = ""
		}
	}()

	if _, err2 := tf.Write(data); err2 != nil {
		return "", errors.Wrap(err2, "can't write to temp file")
	}

	if err2 := tf.Sync(); err2 != nil {
		return "", errors.Wrapf(err2, "cannot sync temporary file in dir %s", dirname)
	}

	return tf.Name(), nil
}

View on GitHub (pinned to 82495e54b5)