Skip to content

Commit 543afd6

Browse files
committed
* more debug
1 parent d74f4a0 commit 543afd6

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

atomic/file_windows.go

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

35
import (
46
"fmt"
5-
"os"
67
"syscall"
8+
"unsafe"
79
)
810

911
const (
@@ -16,20 +18,38 @@ const (
1618
// ReplaceFile atomically replaces the destination file or directory with the
1719
// source. It is guaranteed to either replace the target file entirely, or not
1820
// change either file.
19-
func ReplaceFile(source, destination string) error {
21+
func Rename(src, dst string) error {
2022
fmt.Println("=>=>=>=>", "Replace WINDOWS")
21-
src, err := syscall.UTF16PtrFromString(source)
23+
kernel32, err := syscall.LoadLibrary("kernel32.dll")
24+
if err != nil {
25+
return err
26+
}
27+
defer syscall.FreeLibrary(kernel32)
28+
moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
29+
if err != nil {
30+
return err
31+
}
32+
33+
srcString, err := syscall.UTF16PtrFromString(src)
2234
if err != nil {
23-
return &os.LinkError{"replace", source, destination, err}
35+
return err
2436
}
25-
dest, err := syscall.UTF16PtrFromString(destination)
37+
38+
dstString, err := syscall.UTF16PtrFromString(dst)
2639
if err != nil {
27-
return &os.LinkError{"replace", source, destination, err}
40+
return err
2841
}
2942

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}
43+
srcPtr := uintptr(unsafe.Pointer(srcString))
44+
dstPtr := uintptr(unsafe.Pointer(dstString))
45+
46+
MOVEFILE_REPLACE_EXISTING := 0x1
47+
flag := uintptr(MOVEFILE_REPLACE_EXISTING)
48+
49+
_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
50+
if callErr != 0 {
51+
return callErr
3352
}
53+
3454
return nil
3555
}

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)