Move OS-related modules into a sub-package. NFC

Historically git-pages did not use those, but the codebase is growing
a bit out of hand and it seems like a good place to start.
This commit is contained in:
Catherine
2026-05-28 13:36:21 +00:00
parent 6e232b5229
commit de3162bba2
5 changed files with 12 additions and 9 deletions
+6 -4
View File
@@ -12,6 +12,8 @@ import (
"path/filepath"
"strings"
"time"
sys "codeberg.org/git-pages/git-pages/src/sys"
)
type FSBackend struct {
@@ -66,8 +68,8 @@ func checkAtomicCAS(root *os.Root) bool {
root.Remove(fileName)
defer file.Close()
flockErr := FileLock(file)
funlockErr := FileUnlock(file)
flockErr := sys.FileLock(file)
funlockErr := sys.FileUnlock(file)
return (flockErr == nil && funlockErr == nil)
}
@@ -295,7 +297,7 @@ func lockManifest(fs *os.Root, name string) (*manifestLockGuard, error) {
} else if err != nil {
return nil, fmt.Errorf("open: %w", err)
}
if err := FileLock(file); err != nil {
if err := sys.FileLock(file); err != nil {
file.Close()
return nil, fmt.Errorf("flock(LOCK_EX): %w", err)
}
@@ -304,7 +306,7 @@ func lockManifest(fs *os.Root, name string) (*manifestLockGuard, error) {
func (guard *manifestLockGuard) Unlock() {
if guard.file != nil {
FileUnlock(guard.file)
sys.FileUnlock(guard.file)
guard.file.Close()
}
}
+3 -2
View File
@@ -22,6 +22,7 @@ import (
"strings"
"time"
sys "codeberg.org/git-pages/git-pages/src/sys"
automemlimit "github.com/KimMachineGun/automemlimit/memlimit"
"github.com/c2h5oh/datasize"
"github.com/fatih/color"
@@ -720,7 +721,7 @@ func Main(versionInfo string) {
//
// Note that not all of the configuration is updated on reload. Listeners are kept as-is.
// The backend is not recreated (this is intentional as it allows preserving the cache).
OnReload(func() {
sys.OnReload(func() {
if newConfig, err := Configure(*configTomlPath, *secretTomlPath); err != nil {
logc.Println(ctx, "config: reload err:", err)
} else {
@@ -778,7 +779,7 @@ func Main(versionInfo string) {
logc.Println(ctx, "serve: ready")
}
WaitForInterrupt()
sys.WaitForInterrupt()
logc.Println(ctx, "serve: exiting")
}
}
@@ -1,6 +1,6 @@
//go:build !unix
package git_pages
package os
import (
"fmt"
@@ -1,6 +1,6 @@
//go:build unix
package git_pages
package os
import (
"os"
+1 -1
View File
@@ -2,7 +2,7 @@
// will do on Windows (tl;dr nothing calls the reload handler, the interrupt handler works
// more or less how you'd expect).
package git_pages
package os
import (
"os"