mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 05:28:07 +08:00
9991821295
See https://github.com/project-zot/zot/issues/3924 Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
31 lines
794 B
Go
31 lines
794 B
Go
//go:build windows
|
|
|
|
package local
|
|
|
|
import (
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// renameReplace moves src to dst, replacing dst if it already exists.
|
|
// When commit is true, MOVEFILE_WRITE_THROUGH is set so the rename is flushed to disk, aligning
|
|
// with the local driver's commit semantics on WriteFile/Close. When commit is false, only
|
|
// MOVEFILE_REPLACE_EXISTING is used so large moves are not forced fully synchronous.
|
|
func renameReplace(src, dst string, commit bool) error {
|
|
from, err := windows.UTF16PtrFromString(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
to, err := windows.UTF16PtrFromString(dst)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var flags uint32 = windows.MOVEFILE_REPLACE_EXISTING
|
|
if commit {
|
|
flags |= windows.MOVEFILE_WRITE_THROUGH
|
|
}
|
|
|
|
return windows.MoveFileEx(from, to, flags)
|
|
}
|