mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
35c1fad517
With this commit we rename the existing AvailableDiskSpace function to its correct name AvailableDiskSpaceRatio as it only returns a ratio. We then go ahead and add a new function that returns the actual number of free bytes available on a file system. This also fixes some comments and always returns an error instead of panicking.
32 lines
815 B
Go
32 lines
815 B
Go
package healthcheck
|
|
|
|
import "golang.org/x/sys/windows"
|
|
|
|
// AvailableDiskSpaceRatio returns ratio of available disk space to total
|
|
// capacity for windows.
|
|
func AvailableDiskSpaceRatio(path string) (float64, error) {
|
|
var free, total, avail uint64
|
|
|
|
pathPtr, err := windows.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, &total, &avail)
|
|
|
|
return float64(avail) / float64(total), nil
|
|
}
|
|
|
|
// AvailableDiskSpace returns the available disk space in bytes of the given
|
|
// file system for windows.
|
|
func AvailableDiskSpace(path string) (uint64, error) {
|
|
var free, total, avail uint64
|
|
|
|
pathPtr, err := windows.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, &total, &avail)
|
|
|
|
return avail, nil
|
|
}
|