- Add .golangci.yml with minimal linters (govet, ineffassign) - Run gofmt -s and goimports on all files to fix formatting - Disable fieldalignment and copylocks checks in govet
40 lines
770 B
Go
Executable File
40 lines
770 B
Go
Executable File
//go:build windows
|
|
// +build windows
|
|
|
|
package restore
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
getDiskFreeSpace = kernel32.NewProc("GetDiskFreeSpaceExW")
|
|
)
|
|
|
|
// getDiskSpace returns available disk space in bytes (Windows)
|
|
func getDiskSpace(path string) (int64, error) {
|
|
var freeBytesAvailable int64
|
|
var totalBytes int64
|
|
var totalFreeBytes int64
|
|
|
|
pathPtr, err := syscall.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
ret, _, err := getDiskFreeSpace.Call(
|
|
uintptr(unsafe.Pointer(pathPtr)),
|
|
uintptr(unsafe.Pointer(&freeBytesAvailable)),
|
|
uintptr(unsafe.Pointer(&totalBytes)),
|
|
uintptr(unsafe.Pointer(&totalFreeBytes)),
|
|
)
|
|
|
|
if ret == 0 {
|
|
return 0, err
|
|
}
|
|
|
|
return freeBytesAvailable, nil
|
|
}
|