//go:build windows package config import ( "os" "syscall" "unsafe" ) var moveFileEx = syscall.NewLazyDLL("kernel32.dll").NewProc("MoveFileExW") func replaceFile(source, destination string) error { sourcePtr, err := syscall.UTF16PtrFromString(source) if err != nil { return err } destinationPtr, err := syscall.UTF16PtrFromString(destination) if err != nil { return err } result, _, callErr := moveFileEx.Call( uintptr(unsafe.Pointer(sourcePtr)), uintptr(unsafe.Pointer(destinationPtr)), 0x1|0x8, // MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ) if result == 0 { if callErr != syscall.Errno(0) { return callErr } return os.ErrInvalid } return nil }