init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
//go:build windows
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var getDiskFreeSpaceEx = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
|
||||
|
||||
func workspaceDiskPercent(workspaceRoot string) (float64, error) {
|
||||
volume := filepath.VolumeName(workspaceRoot)
|
||||
if volume == "" {
|
||||
volume = workspaceRoot
|
||||
} else {
|
||||
volume += `\`
|
||||
}
|
||||
var available, total, free uint64
|
||||
success, _, callErr := getDiskFreeSpaceEx.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(volume))), uintptr(unsafe.Pointer(&available)), uintptr(unsafe.Pointer(&total)), uintptr(unsafe.Pointer(&free)))
|
||||
if success == 0 {
|
||||
return 0, callErr
|
||||
}
|
||||
if total == 0 {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
return 100 * float64(total-free) / float64(total), nil
|
||||
}
|
||||
Reference in New Issue
Block a user