Commit 67fad8d6 authored by Kunal Taitkar's avatar Kunal Taitkar
Browse files

Build failed on mac os( filemdl_darwin.go had windows sys calls)

parent d2647d21
2 merge requests!180Mep release 07042020,!179Build failed on mac os( filemdl_darwin.go had windows sys calls)
Showing with 4 additions and 40 deletions
// TODO: Build flag needs to be passed while building exe/executable
// +build !windows
package filemdl
import (
"os"
"syscall"
"unsafe"
)
const (
moveFileReplacExisting = 0x1
moveFileWriteThrough = 0x8
)
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
)
//sys moveFileEx(lpExistingFileName *uint16, lpNewFileName *uint16, dwFlags uint32) (err error) = MoveFileExW
// AtomicReplaceFile atomically replaces the destination file or directory with the
// source. It is guaranteed to either replace the target file entirely, or not
// change either file.
func AtomicReplaceFile(source, destination string) error {
src, err := syscall.UTF16PtrFromString(source)
if err != nil {
return &os.LinkError{"replace", source, destination, err}
}
dest, err := syscall.UTF16PtrFromString(destination)
if err != nil {
return &os.LinkError{"replace", source, destination, err}
}
// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
if err := moveFileEx(src, dest, moveFileReplacExisting|moveFileWriteThrough); err != nil {
return &os.LinkError{"replace", source, destination, err}
}
return nil
}
func moveFileEx(lpExistingFileName *uint16, lpNewFileName *uint16, dwFlags uint32) (err error) {
r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(lpExistingFileName)), uintptr(unsafe.Pointer(lpNewFileName)), uintptr(dwFlags))
if r1 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
return os.Rename(source, destination)
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment