From d3c428b53da1ae1e1bcfc81b3ccbfc2e6c315478 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 2 May 2024 17:10:33 +0200 Subject: use more native Lua code instead of os.execute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested-by: Matěj Cepl --- init.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index ff38679..8b8a8c6 100644 --- a/init.lua +++ b/init.lua @@ -75,18 +75,19 @@ end local created_locks = {} local function create_lock_file(lfile_path) - local already_locked = os.execute('test -e ' .. '"' .. lfile_path .. '"') - if already_locked then + local lock_file = io.open(lfile_path) + if lock_file then + lock_file:close() return false end -- create the lock file with our pid - local cmd = 'echo ' .. vis_pid .. ' > "' .. lfile_path .. '"' - assert(os.execute(cmd)) + lock_file = assert(io.open(lfile_path, 'w')) + lock_file:write(vis_pid) + lock_file:close() -- detect a possible race - local lock_file = io.open(lfile_path) - assert(lock_file) + lock_file = assert(io.open(lfile_path)) local lock_pid = lock_file:read('*n') lock_file:close() local locked = tonumber(lock_pid) == vis_pid @@ -100,7 +101,10 @@ local function create_lock_file(lfile_path) end local function delete_lock_file(lfile_path) - os.execute('rm ' .. '"' .. lfile_path .. '"') + local success, err = os.remove(lfile_path) + if not success then + vis:info('vis-lockfiles: ' .. err) + end created_locks[lfile_path] = nil end -- cgit v1.2.3