2021-07-26 13:09:12 +02:00
|
|
|
//go:build linux || darwin || freebsd
|
2020-09-28 23:29:04 +02:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
2021-02-26 23:37:07 +01:00
|
|
|
import (
|
2023-05-03 10:47:02 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
2021-02-26 23:37:07 +01:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2020-09-28 23:29:04 +02:00
|
|
|
func freeSpace(stat unix.Statfs_t) uint64 {
|
|
|
|
return uint64(stat.Bavail) * uint64(stat.Bsize)
|
|
|
|
}
|
2023-05-03 10:47:02 +02:00
|
|
|
|
|
|
|
func mustRemoveDirAtomic(dir string) {
|
2024-02-24 01:07:51 +01:00
|
|
|
n := atomicDirRemoveCounter.Add(1)
|
2023-05-03 10:47:02 +02:00
|
|
|
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)
|
|
|
|
}
|