vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
|
215f8aeb
Keenan Nemetz
2d ago
|
1 | //go:build !unix && !windows |
| 2 | ||
| 3 | package agent | |
| 4 | ||
| 5 | import ( | |
| 6 | "errors" | |
| 7 | "os" | |
| 8 | "sync" | |
| 9 | ) | |
| 10 | ||
| 11 | var errLockBusy = errors.New("the saved checkout is locked by another process") | |
| 12 | ||
| 13 | // A platform without a kernel file lock can only serialize runners inside one | |
| 14 | // process. Two runners sharing a --dir would then repack or delete a clone under | |
| 15 | // each other's feet, which is the data loss this lock exists to prevent, so this | |
| 16 | // fallback is deliberately visible here rather than silent: Vole ships runners | |
| 17 | // for the platforms where the kernel lock exists. | |
| 18 | var ( | |
| 19 | processLocksMu sync.Mutex | |
| 20 | processLocks = map[string]*sync.Mutex{} | |
| 21 | ) | |
| 22 | ||
| 23 | func lockExclusive(f *os.File, nonBlocking bool) error { | |
| 24 | processLocksMu.Lock() | |
| 25 | mu := processLocks[f.Name()] | |
| 26 | if mu == nil { | |
| 27 | mu = &sync.Mutex{} | |
| 28 | processLocks[f.Name()] = mu | |
| 29 | } | |
| 30 | processLocksMu.Unlock() | |
| 31 | if nonBlocking { | |
| 32 | if !mu.TryLock() { | |
| 33 | return errLockBusy | |
| 34 | } | |
| 35 | return nil | |
| 36 | } | |
| 37 | mu.Lock() | |
| 38 | return nil | |
| 39 | } | |
| 40 | ||
| 41 | func unlockFile(f *os.File) error { | |
| 42 | processLocksMu.Lock() | |
| 43 | mu := processLocks[f.Name()] | |
| 44 | processLocksMu.Unlock() | |
| 45 | if mu == nil { | |
| 46 | return errLockBusy | |
| 47 | } | |
| 48 | mu.Unlock() | |
| 49 | return nil | |
| 50 | } |