mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-26 00:23:30 +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)
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
//go:build windows
|
|
|
|
package backup
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func checkDiskSpace(dir string) (PreflightCheck, int64) {
|
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
|
proc := kernel32.NewProc("GetDiskFreeSpaceExW")
|
|
dirPtr, err := syscall.UTF16PtrFromString(dir)
|
|
if err != nil {
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "warning",
|
|
Detail: fmt.Sprintf("could not check disk space: %v", err),
|
|
}, 0
|
|
}
|
|
var freeBytesAvailable uint64
|
|
ret, _, callErr := proc.Call(
|
|
uintptr(unsafe.Pointer(dirPtr)),
|
|
uintptr(unsafe.Pointer(&freeBytesAvailable)),
|
|
0,
|
|
0,
|
|
)
|
|
if ret == 0 {
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "warning",
|
|
Detail: fmt.Sprintf("could not check disk space: %v", callErr),
|
|
}, 0
|
|
}
|
|
const minFree = 1 << 30 // 1 GB
|
|
if freeBytesAvailable < uint64(minFree) {
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "missing",
|
|
Detail: fmt.Sprintf("only %d MB free (need at least 1 GB)", freeBytesAvailable>>20),
|
|
Hint: "Free up disk space before running a backup.",
|
|
}, int64(freeBytesAvailable)
|
|
}
|
|
return PreflightCheck{
|
|
Name: "disk_space",
|
|
Status: "ok",
|
|
Detail: fmt.Sprintf("%d MB free", freeBytesAvailable>>20),
|
|
}, int64(freeBytesAvailable)
|
|
}
|