Files
dbbackup/internal/restore/diskspace_windows.go
Renz 0cf21cd893 feat: Complete MEDIUM priority security features with testing
- Implemented TUI auto-select for automated testing
- Fixed TUI automation: autoSelectMsg handling in Update()
- Auto-database selection in DatabaseSelector
- Created focused test suite (test_as_postgres.sh)
- Created retention policy test (test_retention.sh)
- All 10 security tests passing

Features validated:
 Backup retention policy (30 days, min backups)
 Rate limiting (exponential backoff)
 Privilege checks (root detection)
 Resource limit validation
 Path sanitization
 Checksum verification (SHA-256)
 Audit logging
 Secure permissions
 Configuration persistence
 TUI automation framework

Test results: 10/10 passed
Backup files created with .dump, .sha256, .info
Retention cleanup verified (old files removed)
2025-11-25 15:25:56 +00:00

39 lines
751 B
Go
Executable File

// +build windows
package restore
import (
"syscall"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
getDiskFreeSpace = kernel32.NewProc("GetDiskFreeSpaceExW")
)
// getDiskSpace returns available disk space in bytes (Windows)
func getDiskSpace(path string) (int64, error) {
var freeBytesAvailable int64
var totalBytes int64
var totalFreeBytes int64
pathPtr, err := syscall.UTF16PtrFromString(path)
if err != nil {
return 0, err
}
ret, _, err := getDiskFreeSpace.Call(
uintptr(unsafe.Pointer(pathPtr)),
uintptr(unsafe.Pointer(&freeBytesAvailable)),
uintptr(unsafe.Pointer(&totalBytes)),
uintptr(unsafe.Pointer(&totalFreeBytes)),
)
if ret == 0 {
return 0, err
}
return freeBytesAvailable, nil
}