mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-18 05:43:42 +00:00
fix: repair free-disk-space build on illumos, Solaris, NetBSD and OpenBSD (#1416)
The runner did not build on illumos, Solaris, NetBSD and OpenBSD: `internal/pkg/disk` called `unix.Statfs`, which `golang.org/x/sys/unix` lacks on illumos, Solaris and NetBSD (they have `statvfs(2)`) and exposes with `F_`-prefixed fields on OpenBSD. Each now has an implementation matching its syscall. FreeBSD and DragonFly report a negative available-block count once root writes into the reserved blocks. It wrapped to ~16 EiB free, so the disk health check and cache eviction saw plenty of space exactly when the disk was full. A shared helper clamps it to zero and absorbs the per-platform integer types. CI only built for the host, which let this and https://gitea.com/gitea/runner/pulls/1098 through. `make cross-check` vets code and tests on one target per distinct set of platform files, plus linux/arm for its 32-bit syscall fields, and runs as its own job in parallel to the others. It also surfaced docker-only tests lacking the docker build tag, which are fixed too. Assisted-by: Claude Code:claude-opus-5-5 Co-authored-by: rosekanari <[email protected]>
This commit is contained in:
1 parent
0e4c8b6b78
commit
bcc0b715cd
18 files changed
+122
-17
No files matched your search
@@ -0,0 +1,17 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build openbsd
|
||||
|
||||
package disk
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||
func FreeBytes(path string) (uint64, error) {
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Statfs(path, &stat); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return availableBytes(stat.F_bavail, stat.F_bsize), nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows
|
||||
//go:build !unix && !windows
|
||||
|
||||
package disk
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build aix || darwin || dragonfly || freebsd || linux
|
||||
|
||||
package disk
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||
func FreeBytes(path string) (uint64, error) {
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Statfs(path, &stat); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return availableBytes(stat.Bavail, stat.Bsize), nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build netbsd || solaris
|
||||
|
||||
package disk
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||
func FreeBytes(path string) (uint64, error) {
|
||||
var stat unix.Statvfs_t
|
||||
if err := unix.Statvfs(path, &stat); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// statvfs(2) counts blocks in f_frsize units, f_bsize is the preferred I/O size and differs on ZFS
|
||||
return availableBytes(stat.Bavail, stat.Frsize), nil
|
||||
}
|
||||
@@ -1,17 +1,10 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
//go:build unix
|
||||
|
||||
package disk
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||
func FreeBytes(path string) (uint64, error) {
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Statfs(path, &stat); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(stat.Bavail) * uint64(stat.Bsize), nil //nolint:unconvert // Bavail/Bsize signedness differs by platform
|
||||
func availableBytes[Count, Size ~int32 | ~int64 | ~uint32 | ~uint64](count Count, size Size) uint64 {
|
||||
return uint64(max(count, 0)) * uint64(size) // signed BSD counts go negative once root fills the reserved blocks
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build unix
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFreeBytes(t *testing.T) {
|
||||
free, err := FreeBytes(t.TempDir())
|
||||
require.NoError(t, err)
|
||||
assert.Positive(t, free)
|
||||
|
||||
assert.Equal(t, uint64(1536), availableBytes(int64(3), uint32(512)))
|
||||
assert.Zero(t, availableBytes(int64(-3), uint32(512)))
|
||||
}
|
||||
Reference in new issue
Block a user