2020-09-28 23:29:04 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2023-05-03 10:47:02 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
2020-09-28 23:29:04 +02:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func freeSpace(stat unix.Statfs_t) uint64 {
|
|
|
|
return uint64(stat.F_bavail) * uint64(stat.F_bsize)
|
|
|
|
}
|
2023-05-03 10:47:02 +02:00
|
|
|
|
|
|
|
func mustRemoveDirAtomic(dir string) {
|
|
|
|
if !IsPathExist(dir) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
parentDir := filepath.Dir(dir)
|
|
|
|
MustSyncPath(parentDir)
|
|
|
|
}
|