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 windows |
| 2 | ||
| 3 | package agent | |
| 4 | ||
| 5 | import ( | |
| 6 | "os" | |
| 7 | ||
| 8 | "golang.org/x/sys/windows" | |
| 9 | ) | |
| 10 | ||
| 11 | // lockExclusive takes the saved checkout's exclusive lock, waiting unless | |
| 12 | // nonBlocking is set. Windows releases a file lock when the handle closes, | |
| 13 | // including when the process is killed, so a runner that dies mid-repack leaves | |
| 14 | // nothing a later run has to clean up — the same guarantee flock gives. | |
| 15 | // | |
| 16 | // One byte at offset zero is locked rather than the whole file: the lock is a | |
| 17 | // convention between runners, and the file's contents are never read. | |
| 18 | func lockExclusive(f *os.File, nonBlocking bool) error { | |
| 19 | flags := uint32(windows.LOCKFILE_EXCLUSIVE_LOCK) | |
| 20 | if nonBlocking { | |
| 21 | flags |= windows.LOCKFILE_FAIL_IMMEDIATELY | |
| 22 | } | |
| 23 | var overlap windows.Overlapped | |
| 24 | return windows.LockFileEx(windows.Handle(f.Fd()), flags, 0, 1, 0, &overlap) | |
| 25 | } | |
| 26 | ||
| 27 | // unlockFile releases the lock taken by lockExclusive. | |
| 28 | func unlockFile(f *os.File) error { | |
| 29 | var overlap windows.Overlapped | |
| 30 | return windows.UnlockFileEx(windows.Handle(f.Fd()), 0, 1, 0, &overlap) | |
| 31 | } |