diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-07-31 16:17:17 -0400 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-07-31 16:58:58 -0400 |
commit | f107f28ea45b15611b5699cb21662daf5ca0535a (patch) | |
tree | 5e220b438a4264ce8ee5a7977dba8235c9a6ab12 | |
parent | ab55ba5174097b25fe7227d1aa4e6559cc40b978 (diff) | |
download | gitano-f107f28ea45b15611b5699cb21662daf5ca0535a.tar.gz |
Add lock and unlock utility functions
-rw-r--r-- | lib/gitano/util.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index dcb41f4..76183e3 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -569,6 +569,21 @@ local function tempfile(repo) return fd, temppattern end +local function lockfile(path) + local fh = assert(sio.open(path, "cw+")) + local ok, msg = fh:lock("w", "set", 0, 0, true, false) + if not ok then + fh:close() + error(msg) + end + return fh +end + +local function unlockfile(fh) + fh:lock("", "set", 0, 0, true, false) + fh:close() +end + return { parse_cmdline = _parse_cmdline, @@ -605,4 +620,7 @@ return { check_password = check_password, run_command = run_command, + + lockfile = lockfile, + unlockfile = unlockfile, } |