Files
goclaw/internal/backup/preflight_disk_unix.go
viettranx 99da7edd01 fix(ci): resolve 4 workflow failures — tests, race, Windows build
- 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)
2026-04-09 21:45:55 +07:00

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)
}