Skip to content

Commit 8884b81

Browse files
committed
* more debug
1 parent d74f4a0 commit 8884b81

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

atomic/file_windows.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//go:build windows
2+
13
package atomic
24

35
import (
4-
"fmt"
5-
"os"
66
"syscall"
7+
"unsafe"
78
)
89

910
const (
@@ -16,20 +17,38 @@ const (
1617
// ReplaceFile atomically replaces the destination file or directory with the
1718
// source. It is guaranteed to either replace the target file entirely, or not
1819
// change either file.
19-
func ReplaceFile(source, destination string) error {
20+
func Rename(src, dst string) error {
2021
fmt.Println("=>=>=>=>", "Replace WINDOWS")
21-
src, err := syscall.UTF16PtrFromString(source)
22+
kernel32, err := syscall.LoadLibrary("kernel32.dll")
23+
if err != nil {
24+
return err
25+
}
26+
defer syscall.FreeLibrary(kernel32)
27+
moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
28+
if err != nil {
29+
return err
30+
}
31+
32+
srcString, err := syscall.UTF16PtrFromString(src)
2233
if err != nil {
23-
return &os.LinkError{"replace", source, destination, err}
34+
return err
2435
}
25-
dest, err := syscall.UTF16PtrFromString(destination)
36+
37+
dstString, err := syscall.UTF16PtrFromString(dst)
2638
if err != nil {
27-
return &os.LinkError{"replace", source, destination, err}
39+
return err
2840
}
2941

30-
// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
31-
if err := moveFileEx(src, dest, movefile_replace_existing|movefile_write_through); err != nil {
32-
return &os.LinkError{"replace", source, destination, err}
42+
srcPtr := uintptr(unsafe.Pointer(srcString))
43+
dstPtr := uintptr(unsafe.Pointer(dstString))
44+
45+
MOVEFILE_REPLACE_EXISTING := 0x1
46+
flag := uintptr(MOVEFILE_REPLACE_EXISTING)
47+
48+
_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
49+
if callErr != 0 {
50+
return callErr
3351
}
52+
3453
return nil
3554
}

atomic/zfile_windows.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

remote_fetch.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func decompressResponse(bodyBytes []byte, contentLength int64, cacheLocator Cach
107107

108108
cacheLocation, _ := cacheLocator()
109109

110-
fmt.Println("=>=>=>=>=>=> creating dir", filepath.Dir(cacheLocation))
111110
if err := os.MkdirAll(filepath.Dir(cacheLocation), 0755); err != nil {
112111
return errorExtractingPostgres(err)
113112
}

0 commit comments

Comments
 (0)