mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-27 10:19:49 +00:00
- slack: update splitAtLimit tests to match ChunkMarkdown behavior - providerresolve: use ChatGPTOAuthRouting field instead of OtherConfig - scheduler: buffer started channel to prevent race in DropOldPolicy - backup: split checkDiskSpace into platform files (Unix/Windows)
35 lines
828 B
Go
35 lines
828 B
Go
//go:build !windows
|
|
|
|
package backup
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
)
|
|
|
|
func checkDiskSpace(dir string) (PreflightCheck, int64) {
|
|
var stat syscall.Statfs_t
|
|
if err := syscall.Statfs(dir, &stat); err != nil {
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "warning",
|
|
Detail: fmt.Sprintf("could not check disk space: %v", err),
|
|
}, 0
|
|
}
|
|
freeBytes := stat.Bavail * uint64(stat.Bsize)
|
|
const minFree = 1 << 30 // 1 GB
|
|
if freeBytes < minFree {
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "missing",
|
|
Detail: fmt.Sprintf("only %d MB free (need at least 1 GB)", freeBytes>>20),
|
|
Hint: "Free up disk space before running a backup.",
|
|
}, int64(freeBytes)
|
|
}
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "ok",
|
|
Detail: fmt.Sprintf("%d MB free", freeBytes>>20),
|
|
}, int64(freeBytes)
|
|
}
|