From 68557e2a210584cde68b508553e6177f4bb2e381 Mon Sep 17 00:00:00 2001 From: Cidwel Highwind Date: Fri, 3 Apr 2026 21:32:21 +0200 Subject: [PATCH] Fix lock file: timestamp-based staleness, periodic refresh - Lock file now contains a timestamp, refreshed every 0.5s - Stale locks (>5s old) are ignored and cleaned up automatically - Fixes: Aseprite crash leaving orphan lock, lock not cleaned on close - Silent ignore still works for active instances --- aniphallow.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/aniphallow.lua b/aniphallow.lua index 78fd118..25e2f92 100644 --- a/aniphallow.lua +++ b/aniphallow.lua @@ -1267,6 +1267,11 @@ local function removeLockFile() os.remove(LOCK_FILE) end +local function refreshLockFile() + local lf = io.open(LOCK_FILE, "w") + if lf then lf:write(tostring(os.time())); lf:close() end +end + ---------------------------------------------------------------------- -- Preview Window (primary window) ---------------------------------------------------------------------- @@ -1502,6 +1507,7 @@ openPreviewWindow = function() interval = 0.5, ontick = function() refreshSource() + refreshLockFile() pcall(function() previewDlg:repaint() end) -- Auto-detect file change @@ -3273,14 +3279,21 @@ local function run() return end -- Check if already running via lock file - silently ignore + -- Lock file contains a timestamp; if older than 5 seconds, consider it stale local lockF = io.open(LOCK_FILE, "r") if lockF then + local content = lockF:read("*a") lockF:close() - return + local lockTime = tonumber(content) + if lockTime and (os.time() - lockTime) < 5 then + return -- Still running, ignore + end + -- Stale lock, remove and continue + os.remove(LOCK_FILE) end - -- Create lock file + -- Create lock file with current timestamp local lf = io.open(LOCK_FILE, "w") - if lf then lf:write("running"); lf:close() end + if lf then lf:write(tostring(os.time())); lf:close() end S.currentTab = "Animations" refreshSource()