diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-05-02 17:10:33 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2024-05-02 17:10:33 +0200 |
| commit | d3c428b53da1ae1e1bcfc81b3ccbfc2e6c315478 (patch) | |
| tree | 62208a9afdcf338e56396b055bd43fa0ece89005 | |
| parent | 7153205928e043a00231be64f34fa59c11f19e1a (diff) | |
| download | vis-lockfiles-d3c428b53da1ae1e1bcfc81b3ccbfc2e6c315478.tar.gz vis-lockfiles-d3c428b53da1ae1e1bcfc81b3ccbfc2e6c315478.zip | |
use more native Lua code instead of os.execute
Suggested-by: Matěj Cepl <mcepl@cepl.eu>
| -rw-r--r-- | init.lua | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 |
