kubernetes/kops · error
error renaming temp file %q -> %q: %w
Error message
error renaming temp file %q -> %q: %w
What it means
Thrown by writeFileContents when the atomic final step — renaming the completed temp file over the destination path — fails. Typical causes: destination is a directory, cross-device link errors if temp and destination ended up on different mounts, permission issues on the destination, or the destination file is busy/immutable.
Source
Thrown at upup/pkg/fi/files.go:101
}
}
}()
if _, err := io.Copy(tempFile, in); err != nil {
return fmt.Errorf("error writing file %q: %v", tempFile.Name(), err)
}
if err := tempFile.Chmod(fileMode); err != nil {
return fmt.Errorf("error setting mode on temp file %q: %w", tempFile.Name(), err)
}
if err := tempFile.Close(); err != nil {
return fmt.Errorf("error closing temp file %q: %w", tempFile.Name(), err)
}
closeTempFile = false
if err := os.Rename(tempFile.Name(), destPath); err != nil {
return fmt.Errorf("error renaming temp file %q -> %q: %w", tempFile.Name(), destPath, err)
}
deleteTempFile = false
return nil
}
func EnsureFileMode(destPath string, fileMode os.FileMode) (bool, error) {
changed := false
stat, err := os.Lstat(destPath)
if err != nil {
return changed, fmt.Errorf("error getting file mode for %q: %v", destPath, err)
}
if (stat.Mode() & os.ModePerm) == fileMode {
return changed, nil
}
klog.Infof("Changing file mode for %q to %s", destPath, fileMode)
err = os.Chmod(destPath, fileMode)View on GitHub (pinned to 4c8573c808)
Solutions
- Check permissions and ownership on the existing destination path
- Ensure the temp file (created in the destination directory) and destination are on the same filesystem
- Remove a stale directory occupying the destination path
- Verify the file isn't held with immutable attributes or locks preventing replace
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at upup/pkg/fi/files.go:101 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/a065d521281f3209.
Report an issue: GitHub.