Fix cross-platform compilation for all target platforms

- Fixed type mismatch in disk space calculation (int64 casting)
- Created platform-specific disk space implementations:
  * diskspace_unix.go (Linux, macOS, FreeBSD)
  * diskspace_windows.go (Windows)
  * diskspace_bsd.go (OpenBSD)
  * diskspace_netbsd.go (NetBSD fallback)
- All 10 platforms now compile successfully:
   Linux (amd64, arm64, armv7)
   macOS (Intel, Apple Silicon)
   Windows (amd64, arm64)
   FreeBSD, OpenBSD, NetBSD
This commit is contained in:
2025-11-07 15:16:54 +00:00
parent 2d34eca514
commit 9d1d276d39
16 changed files with 82 additions and 7 deletions

View File

@ -4,8 +4,8 @@ This directory contains pre-compiled binaries for the DB Backup Tool across mult
## Build Information
- **Version**: 1.1.0
- **Build Time**: 2025-11-07_13:27:44_UTC
- **Git Commit**: ebb77fb
- **Build Time**: 2025-11-07_15:15:58_UTC
- **Git Commit**: 2d34eca
## Recent Updates (v1.1.0)
- ✅ Fixed TUI progress display with line-by-line output

BIN
bin/dbbackup_darwin_amd64 Executable file

Binary file not shown.

BIN
bin/dbbackup_darwin_arm64 Executable file

Binary file not shown.

BIN
bin/dbbackup_freebsd_amd64 Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/dbbackup_linux_arm_armv7 Executable file

Binary file not shown.

BIN
bin/dbbackup_netbsd_amd64 Executable file

Binary file not shown.

BIN
bin/dbbackup_openbsd_amd64 Executable file

Binary file not shown.

BIN
bin/dbbackup_windows_amd64.exe Executable file

Binary file not shown.

BIN
bin/dbbackup_windows_arm64.exe Executable file

Binary file not shown.

View File

@ -0,0 +1,15 @@
// +build openbsd
package restore
import "syscall"
// getDiskSpace returns available disk space in bytes (OpenBSD)
func getDiskSpace(path string) (int64, error) {
var statfs syscall.Statfs_t
if err := syscall.Statfs(path, &statfs); err != nil {
return 0, err
}
// OpenBSD uses F_bavail and F_bsize
return int64(statfs.F_bavail) * int64(statfs.F_bsize), nil
}

View File

@ -0,0 +1,11 @@
// +build netbsd
package restore
// getDiskSpace returns available disk space in bytes (NetBSD fallback)
// NetBSD has different syscall interface, so we use a conservative estimate
func getDiskSpace(path string) (int64, error) {
// Return a large value to skip disk space check on NetBSD
// This is a fallback - restore will still work, just won't pre-check space
return 1 << 40, nil // 1 TB
}

View File

@ -0,0 +1,14 @@
// +build !windows,!openbsd,!netbsd
package restore
import "syscall"
// getDiskSpace returns available disk space in bytes (Unix/Linux/macOS/FreeBSD)
func getDiskSpace(path string) (int64, error) {
var statfs syscall.Statfs_t
if err := syscall.Statfs(path, &statfs); err != nil {
return 0, err
}
return int64(statfs.Bavail) * int64(statfs.Bsize), nil
}

View File

@ -0,0 +1,38 @@
// +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
}

View File

@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"strings"
"syscall"
"dbbackup/internal/config"
"dbbackup/internal/logger"
@ -243,14 +242,12 @@ func (s *Safety) CheckDiskSpace(archivePath string, multiplier float64) error {
requiredSpace := int64(float64(archiveSize) * multiplier)
// Get available disk space
var statfs syscall.Statfs_t
if err := syscall.Statfs(s.cfg.BackupDir, &statfs); err != nil {
availableSpace, err := getDiskSpace(s.cfg.BackupDir)
if err != nil {
s.log.Warn("Cannot check disk space", "error", err)
return nil // Don't fail if we can't check
}
availableSpace := int64(statfs.Bavail) * statfs.Bsize
if availableSpace < requiredSpace {
return fmt.Errorf("insufficient disk space: need %s, have %s",
FormatBytes(requiredSpace), FormatBytes(availableSpace))