don't fail if cd is not in a drive
add used and usedPercent back in
This commit is contained in:
parent
5c8a03100e
commit
6c000b035d
|
@ -44,8 +44,8 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
|
|||
Path: path,
|
||||
Total: uint64(lpTotalNumberOfBytes),
|
||||
Free: uint64(lpTotalNumberOfFreeBytes),
|
||||
// Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes)
|
||||
// UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100
|
||||
Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes),
|
||||
UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100,
|
||||
// InodesTotal: 0,
|
||||
// InodesFree: 0,
|
||||
// InodesUsed: 0,
|
||||
|
@ -55,6 +55,7 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
|
|||
}
|
||||
|
||||
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||
fmt.Println("IN DISK PARTITIONS")
|
||||
var ret []DiskPartitionStat
|
||||
lpBuffer := make([]byte, 254)
|
||||
diskret, _, err := procGetLogicalDriveStringsW.Call(
|
||||
|
@ -93,6 +94,9 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
|||
uintptr(unsafe.Pointer(&lpFileSystemNameBuffer[0])),
|
||||
uintptr(len(lpFileSystemNameBuffer)))
|
||||
if driveret == 0 {
|
||||
if typeret == 5 {
|
||||
continue //device is not ready will happen if there is no disk in the drive
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
opts := "rw"
|
||||
|
|
Loading…
Reference in New Issue