fix: add cross-platform disk detection for Windows/macOS builds
Some checks failed
CI / build-and-test (push) Failing after 2s
Release / build (amd64, darwin) (push) Successful in 6s
Release / build (amd64, linux) (push) Successful in 5s
Release / build (amd64, windows) (push) Successful in 6s
Release / build (arm64, darwin) (push) Successful in 5s
Release / build (arm64, linux) (push) Successful in 5s
Release / release (push) Successful in 11s

- Split detectDiskSpace() into platform-specific files with build tags
- disk_unix.go: Uses unix.Statfs for Linux and macOS
- disk_windows.go: Uses windows.GetDiskFreeSpaceEx for Windows
- Fixes Windows cross-compilation build errors

🤖 Generated with Claude Code
This commit is contained in:
GitCaddy
2026-01-11 19:29:27 +00:00
parent fef300dd5b
commit 48a589eb79
3 changed files with 63 additions and 28 deletions

View File

@@ -14,7 +14,6 @@ import (
"time"
"github.com/docker/docker/client"
"golang.org/x/sys/unix"
)
// DiskInfo holds disk space information
@@ -164,33 +163,6 @@ func generateSuggestedLabels(cap *RunnerCapabilities) []string {
return labels
}
// detectDiskSpace detects disk space on the root filesystem
func detectDiskSpace() *DiskInfo {
var stat unix.Statfs_t
// Get stats for root filesystem (or current working directory)
path := "/"
if runtime.GOOS == "windows" {
path = "C:\\"
}
err := unix.Statfs(path, &stat)
if err != nil {
return nil
}
total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bavail * uint64(stat.Bsize)
used := total - free
usedPercent := float64(used) / float64(total) * 100
return &DiskInfo{
Total: total,
Free: free,
Used: used,
UsedPercent: usedPercent,
}
}
// ToJSON converts capabilities to JSON string for transmission
func (c *RunnerCapabilities) ToJSON() string {

View File

@@ -0,0 +1,32 @@
//go:build unix
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package envcheck
import (
"golang.org/x/sys/unix"
)
// detectDiskSpace detects disk space on the root filesystem (Unix version)
func detectDiskSpace() *DiskInfo {
var stat unix.Statfs_t
err := unix.Statfs("/", &stat)
if err != nil {
return nil
}
total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bavail * uint64(stat.Bsize)
used := total - free
usedPercent := float64(used) / float64(total) * 100
return &DiskInfo{
Total: total,
Free: free,
Used: used,
UsedPercent: usedPercent,
}
}

View File

@@ -0,0 +1,31 @@
//go:build windows
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package envcheck
import (
"golang.org/x/sys/windows"
)
// detectDiskSpace detects disk space on the C: drive (Windows version)
func detectDiskSpace() *DiskInfo {
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64
path := windows.StringToUTF16Ptr("C:\\")
err := windows.GetDiskFreeSpaceEx(path, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes)
if err != nil {
return nil
}
used := totalNumberOfBytes - totalNumberOfFreeBytes
usedPercent := float64(used) / float64(totalNumberOfBytes) * 100
return &DiskInfo{
Total: totalNumberOfBytes,
Free: totalNumberOfFreeBytes,
Used: used,
UsedPercent: usedPercent,
}
}