From 46b3b76d6d9699271281567025c9b1381fb84744 Mon Sep 17 00:00:00 2001 From: Scott Kevill Date: Wed, 18 Jan 2023 13:19:26 +0800 Subject: [PATCH] lib/fs: use `unix.Statfs()` / `unix.Statvfs()` when using a path (#3663) --- lib/fs/fs_solaris.go | 9 +-------- lib/fs/fs_unix.go | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/fs/fs_solaris.go b/lib/fs/fs_solaris.go index ac94ea406c..385903896f 100644 --- a/lib/fs/fs_solaris.go +++ b/lib/fs/fs_solaris.go @@ -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) diff --git a/lib/fs/fs_unix.go b/lib/fs/fs_unix.go index bcb789c94a..daa746e6af 100644 --- a/lib/fs/fs_unix.go +++ b/lib/fs/fs_unix.go @@ -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)