返回 DeepSeek-Reasonix
rename_noreplace_windows.go
根目录 / internal / repair / rename_noreplace_windows.go
1 //go:build windows
2
3 package repair
4
5 import (
6 "os"
7
8 "golang.org/x/sys/windows"
9 )
10
11 func renameRepairNodeNoReplace(oldPath, newPath string) error {
12 from, err := windows.UTF16PtrFromString(oldPath)
13 if err != nil {
14 return &os.LinkError{Op: "rename", Old: oldPath, New: newPath, Err: err}
15 }
16 to, err := windows.UTF16PtrFromString(newPath)
17 if err != nil {
18 return &os.LinkError{Op: "rename", Old: oldPath, New: newPath, Err: err}
19 }
20 // MoveFileEx without MOVEFILE_REPLACE_EXISTING fails atomically when newPath
21 // already exists. os.Rename cannot be used here: Go passes the replace flag
22 // on Windows.
23 if err := windows.MoveFileEx(from, to, windows.MOVEFILE_WRITE_THROUGH); err != nil {
24 return &os.LinkError{Op: "rename", Old: oldPath, New: newPath, Err: err}
25 }
26 return nil
27 }
28
28 lines GO