pkg/misc: add function to return free space for given path

This commit is contained in:
Clayton Craft
2021-08-10 13:02:44 -07:00
parent 7a92fb1608
commit 896d4fa0d0

View File

@@ -6,6 +6,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"golang.org/x/sys/unix"
) )
type StringSet map[string]bool type StringSet map[string]bool
@@ -39,3 +40,10 @@ func RelativeSymlinkTargetToDir(symPath string, dir string) (string, error) {
return path, nil return path, nil
} }
func FreeSpace(path string) (uint64, error) {
var stat unix.Statfs_t
unix.Statfs(path, &stat)
size := stat.Bavail * uint64(stat.Bsize)
return size, nil
}