[FIX] fix build failure in windows

This commit is contained in:
barnett 2018-12-06 13:15:19 +08:00
parent c78f1e4789
commit 0400bfef40

View File

@ -21,6 +21,8 @@ package disk
import (
"syscall"
"unsafe"
"github.com/Sirupsen/logrus"
)
// disk usage of path/disk
@ -30,10 +32,13 @@ func DiskUsage(path string) (disk Status) {
lpFreeBytesAvailable := int64(0)
lpTotalNumberOfBytes := int64(0)
lpTotalNumberOfFreeBytes := int64(0)
r2, _, err := c.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("F:"))),
_, _, err := c.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
if err != nil {
logrus.Errorf("read %s disk usage info failure %s", path, err.Error())
}
disk.All = uint64(lpTotalNumberOfBytes)
disk.Free = uint64(lpTotalNumberOfFreeBytes)
disk.Used = uint64(lpTotalNumberOfBytes - lpTotalNumberOfFreeBytes)