lib/fs: use unix.Statfs() / unix.Statvfs() when using a path (#3663)

This commit is contained in:
Scott Kevill 2023-01-18 13:19:26 +08:00 committed by Aliaksandr Valialkin
parent 09d41e05fa
commit 63653b53d6
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 2 additions and 16 deletions

View File

@ -49,15 +49,8 @@ func createFlockFile(flockFile string) (*os.File, error) {
}
func mustGetFreeSpace(path string) uint64 {
d, err := os.Open(path)
if err != nil {
logger.Panicf("FATAL: cannot open dir for determining free disk space: %s", err)
}
defer MustClose(d)
fd := d.Fd()
var stat unix.Statvfs_t
if err := unix.Fstatvfs(int(fd), &stat); err != nil {
if err := unix.Statvfs(path, &stat); err != nil {
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
}
return freeSpace(stat)

View File

@ -45,15 +45,8 @@ func createFlockFile(flockFile string) (*os.File, error) {
}
func mustGetFreeSpace(path string) uint64 {
d, err := os.Open(path)
if err != nil {
logger.Panicf("FATAL: cannot open dir for determining free disk space: %s", err)
}
defer MustClose(d)
fd := d.Fd()
var stat unix.Statfs_t
if err := unix.Fstatfs(int(fd), &stat); err != nil {
if err := unix.Statfs(path, &stat); err != nil {
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
}
return freeSpace(stat)