2021-07-26 11:09:12 +00:00
|
|
|
//go:build linux || darwin || freebsd
|
2020-09-28 21:29:04 +00:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
2021-02-26 22:37:07 +00:00
|
|
|
import (
|
2023-05-03 08:47:02 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
2021-02-26 22:37:07 +00:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2020-09-28 21:29:04 +00:00
|
|
|
func freeSpace(stat unix.Statfs_t) uint64 {
|
|
|
|
return uint64(stat.Bavail) * uint64(stat.Bsize)
|
|
|
|
}
|
2023-05-03 08:47:02 +00:00
|
|
|
|
|
|
|
func mustRemoveDirAtomic(dir string) {
|
|
|
|
n := atomic.AddUint64(&atomicDirRemoveCounter, 1)
|
|
|
|
tmpDir := fmt.Sprintf("%s.must-remove.%d", dir, n)
|
|
|
|
if err := os.Rename(dir, tmpDir); err != nil {
|
|
|
|
logger.Panicf("FATAL: cannot move %s to %s: %s", dir, tmpDir, err)
|
|
|
|
}
|
|
|
|
MustRemoveAll(tmpDir)
|
|
|
|
}
|