go
system_error
ai_generated
true
error: rename /old/path /new/path: invalid cross-device link
ID: go/os-rename-file-cross-device
80%Fix Rate
86%Confidence
0Evidence
2024-12-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Attempting to rename a file across different file systems or mount points, which is not supported by os.Rename.
generic中文
尝试在不同文件系统或挂载点之间重命名文件,os.Rename不支持此操作。
Workarounds
-
90% success Implement copy-then-delete strategy with error handling
src, _ := os.Open(oldPath) dst, _ := os.Create(newPath) io.Copy(dst, src) src.Close() dst.Close() os.Remove(oldPath)
Dead Ends
Common approaches that don't work:
-
Using os.Rename with fallback to copy+delete only on error
50% fail
Does not handle atomicity; may leave partial files.