32 lines
755 B
Go
32 lines
755 B
Go
//go:build windows
|
|
|
|
package pi
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// MoveFileEx requests replacement and write-through on Windows. Directory fsync is not exposed
|
|
// by the Windows API in the same form as Unix, so callers must not claim a stronger guarantee.
|
|
func durableReplace(temporary, target, _ string) error {
|
|
from, err := windows.UTF16PtrFromString(temporary)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
to, err := windows.UTF16PtrFromString(target)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return windows.MoveFileEx(from, to, windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_WRITE_THROUGH)
|
|
}
|
|
|
|
func durableRemove(path string) error {
|
|
if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|