sipeed/picoclaw · error
failed to rename temp file
Error message
failed to rename temp file: %w
What it means
os.Rename from the temp file to the target path failed — the final atomic swap step of WriteFileAtomic (target busy/locked on Windows, cross-device issue, permission change). The original file is still intact; the deferred cleanup removes the orphaned temp file.
Solutions
- On Windows, ensure no process has the target file open/locked
- Verify temp and target are on the same filesystem/mount
- Check directory write permission (rename needs it on POSIX) and retry
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at pkg/fileutil/file.go:106 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/027c5a7f4243d1bd.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/fileutil/file.go:106
if err := tmpFile.Sync(); err != nil {
return fmt.Errorf("failed to sync temp file: %w", err)
}
// Set file permissions before closing
if err := tmpFile.Chmod(perm); err != nil {
return fmt.Errorf("failed to set permissions: %w", err)
}
// Close file before rename (required on Windows)
if err := tmpFile.Close(); err != nil {
return fmt.Errorf("failed to close temp file: %w", err)
}
// Atomic rename: temp file becomes the target
// On POSIX: rename() is atomic
// On Windows: Rename() is atomic for files
if err := os.Rename(tmpPath, path); err != nil {
return fmt.Errorf("failed to rename temp file: %w", err)
}
// Sync directory to ensure rename is durable
// This prevents the renamed file from disappearing after a crash
if dirFile, err := os.Open(dir); err == nil {
_ = dirFile.Sync()
_ = dirFile.Close()
}
// Success: skip cleanup (file was renamed, no temp to remove)
cleanup = false
return nil
}
func CopyFile(src, dst string, perm os.FileMode) error {
data, err := os.ReadFile(src)
if err != nil {
return errView on GitHub (pinned to 49183d7e8d)