Fixed windows compatibility
Some checks failed
Run Integration Tests / test (push) Failing after 10m8s
Some checks failed
Run Integration Tests / test (push) Failing after 10m8s
This commit is contained in:
parent
ed588e8764
commit
8dbfaae1b6
4 changed files with 64 additions and 23 deletions
36
disk_win.go
Normal file
36
disk_win.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func getTotalDiskSpace(path string) uint64 {
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
getDiskFreeSpaceExW := kernel32.NewProc("GetDiskFreeSpaceExW")
|
||||
|
||||
lpDirectoryName, err := syscall.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
printErr("Failed to encode path for Windows API: %v", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64
|
||||
|
||||
r1, _, err := getDiskFreeSpaceExW.Call(
|
||||
uintptr(unsafe.Pointer(lpDirectoryName)),
|
||||
uintptr(unsafe.Pointer(&freeBytesAvailable)),
|
||||
uintptr(unsafe.Pointer(&totalNumberOfBytes)),
|
||||
uintptr(unsafe.Pointer(&totalNumberOfFreeBytes)),
|
||||
)
|
||||
|
||||
if r1 == 0 {
|
||||
printErr("GetDiskFreeSpaceExW failed: %v", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
return totalNumberOfBytes
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue