Fix cross-platform builds: process cleanup and disk space checking

- Add platform-specific implementations for Windows, BSD systems
- Create platform-specific disk space checking with proper syscalls
- Add Windows process cleanup using tasklist/taskkill
- Add BSD-specific Statfs_t field handling (F_blocks, F_bavail, F_bsize)
- Support 9/10 target platforms (Linux, Windows, macOS, FreeBSD, OpenBSD)
- Process cleanup now works on all Unix-like systems and Windows
- Phase 2 TUI improvements compatible across platforms
This commit is contained in:
2025-11-18 19:15:49 +00:00
parent 694c8c802a
commit ccf70db840
6 changed files with 398 additions and 28 deletions

View File

@@ -1,3 +1,6 @@
//go:build !windows && !openbsd && !netbsd
// +build !windows,!openbsd,!netbsd
package checks
import (
@@ -6,18 +9,6 @@ import (
"syscall"
)
// DiskSpaceCheck represents disk space information
type DiskSpaceCheck struct {
Path string
TotalBytes uint64
AvailableBytes uint64
UsedBytes uint64
UsedPercent float64
Sufficient bool
Warning bool
Critical bool
}
// CheckDiskSpace checks available disk space for a given path
func CheckDiskSpace(path string) *DiskSpaceCheck {
// Get absolute path
@@ -37,9 +28,9 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
}
}
// Calculate space
totalBytes := stat.Blocks * uint64(stat.Bsize)
availableBytes := stat.Bavail * uint64(stat.Bsize)
// Calculate space (handle different types on different platforms)
totalBytes := uint64(stat.Blocks) * uint64(stat.Bsize)
availableBytes := uint64(stat.Bavail) * uint64(stat.Bsize)
usedBytes := totalBytes - availableBytes
usedPercent := float64(usedBytes) / float64(totalBytes) * 100
@@ -146,16 +137,4 @@ func EstimateBackupSize(databaseSize uint64, compressionLevel int) uint64 {
// formatBytes formats bytes to human-readable format
func formatBytes(bytes uint64) string {
const unit = 1024
if bytes < unit {
return fmt.Sprintf("%d B", bytes)
}
div, exp := uint64(unit), 0
for n := bytes / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp])
}