From 526873bef425574974358b7f26975cdd7d7cdd1b Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 13:22:51 +0000 Subject: show locking pid on conflict; clearer prompt --- lockfiles.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lockfiles.lua') diff --git a/lockfiles.lua b/lockfiles.lua index d018bc9..e223e10 100644 --- a/lockfiles.lua +++ b/lockfiles.lua @@ -45,11 +45,14 @@ do end assert(vis_pid) +-- returns PID owning lock (possibly vis_pid) local function create_lock_file(lock_dir, lfile_path) + local lock_pid local lock_file = io.open(lfile_path) if lock_file then + lock_pid = lock_file:read('*n') lock_file:close() - return false + return lock_pid end -- create the lock file with our pid @@ -64,11 +67,9 @@ local function create_lock_file(lock_dir, lfile_path) -- detect a possible race lock_file = assert(io.open(lfile_path)) - local lock_pid = lock_file:read('*n') + lock_pid = tonumber(lock_file:read('*n')) lock_file:close() - local locked = tonumber(lock_pid) == vis_pid - - return locked + return lock_pid end local function delete_lock_file(lfile_path) @@ -79,6 +80,7 @@ local function delete_lock_file(lfile_path) end return { + vis_pid = vis_pid, capture_cmd = capture_cmd, lock_file_path = lock_file_path, delete_lock_file = delete_lock_file, -- cgit v1.2.3