From de3162bba202c7a09ca77ffd98d83693c01311dc Mon Sep 17 00:00:00 2001 From: Catherine Date: Thu, 28 May 2026 13:36:21 +0000 Subject: [PATCH] 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. --- src/backend_fs.go | 10 ++++++---- src/main.go | 5 +++-- src/{ => sys}/flock_other.go | 2 +- src/{ => sys}/flock_posix.go | 2 +- src/{ => sys}/signal.go | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) rename src/{ => sys}/flock_other.go (91%) rename src/{ => sys}/flock_posix.go (92%) rename src/{ => sys}/signal.go (96%) diff --git a/src/backend_fs.go b/src/backend_fs.go index 35218be..3bd44ac 100644 --- a/src/backend_fs.go +++ b/src/backend_fs.go @@ -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() } } diff --git a/src/main.go b/src/main.go index 08cfb64..fa5f4a5 100644 --- a/src/main.go +++ b/src/main.go @@ -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") } } diff --git a/src/flock_other.go b/src/sys/flock_other.go similarity index 91% rename from src/flock_other.go rename to src/sys/flock_other.go index 121a887..49280f4 100644 --- a/src/flock_other.go +++ b/src/sys/flock_other.go @@ -1,6 +1,6 @@ //go:build !unix -package git_pages +package os import ( "fmt" diff --git a/src/flock_posix.go b/src/sys/flock_posix.go similarity index 92% rename from src/flock_posix.go rename to src/sys/flock_posix.go index 8326ecf..226da1a 100644 --- a/src/flock_posix.go +++ b/src/sys/flock_posix.go @@ -1,6 +1,6 @@ //go:build unix -package git_pages +package os import ( "os" diff --git a/src/signal.go b/src/sys/signal.go similarity index 96% rename from src/signal.go rename to src/sys/signal.go index 8962536..4f8b94e 100644 --- a/src/signal.go +++ b/src/sys/signal.go @@ -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"