one-copy: the single-copy lock, its Go package and Rust crate #1
Loading…
Reference in a new issue
No description provided.
Delete branch "AHT-218-lock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The single-copy lock every interactive home app takes (AHT-218, for FP-17), as a Go package and a Rust crate with the same behavior, laid out as logline is. Its merge is the first release,
v0.1.0.What it adds (the repository held only its README before):
Claim(name)/claim(name): a per-user named lock. Windows: the named mutexLocal\one-copy-<name>, its handle not inheritable, gone when the process ends. macOS and Linux: an flock onone-copy/<name>.lockin$XDG_RUNTIME_DIRor the user's cache folder, opened close-on-exec (Go keeps a bare descriptor, so garbage collection can't close it).tmux respawn-pane -k, which terminates the old copy and starts the new one in one step (at-tmuxwin32/win32-pty.c:416-418). The doc comments say so.ONE_COPY_SCOPE, appended to the name when set, so a test copy on a throwaway tmux server runs beside his.ClaimOrExit/claim_or_exit: holds the lock for the process's life, or prints<name> is already opento stderr and exits 1. A lock the OS won't make is reported on stderr and the app starts anyway.claim_or_focusandfocus_running. The holder records its process id in the named shared memoryLocal\one-copy-<name>-pid; a second copy finds that process's visible unowned top-level window, restores it if minimized, callsSetForegroundWindowand exits 0. On macOS and Linux there is no window to find, so it just exits 0.What it doesn't do: take the library up in any app (that is FP-17's next work), forward anything to the running copy (at keeps all focusing of terminal apps), or give Go the window part (no Go desktop app needs it).
Tests, the same cases in both languages: a second claim refused and the name free after release, the scope giving a separate lock, a claim made while the holder ends taking it, and child processes showing the stderr line with exit 1 and a lock freed when its holder exits without letting it go. Go's also cover a lock nothing refers to staying held through garbage collection; Rust's on Windows read back the recorded process id. Nothing opens a window, so the bring-forward is checked by hand in String Lab when it takes the crate.
Checked before the push:
ci-check(both languages' format, lints and Windows tests), Go vet for Linux, macOS and FreeBSD, Go's tests run on Linux under WSL, and clippy for Linux and macOS targets.