diff options
| -rw-r--r-- | init.lua | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -14,6 +14,7 @@ -- If not, see <https://www.gnu.org/licenses/>. local M = {} M.directory = '${XDG_STATE_HOME:-${HOME}/.local/state}/vis/locks' +M.directory_expanded = false -- Helper to execute a command and capture its output local function capture_cmd(cmd) @@ -27,10 +28,16 @@ local function capture_cmd(cmd) return s end +local function get_lock_dir() + if not M.directory_expanded then + M.directory = capture_cmd('printf %s "' .. M.directory .. '"') + end + return M.directory +end + local function lock_file_path(path) local filename = path:gsub('/', '%%') - assert(os.execute('mkdir -p "' .. M.directory .. '"')) - return capture_cmd('printf %s "' .. M.directory .. '/' .. filename .. '.lock"') + return get_lock_dir() .. '/' .. filename .. '.lock' end -- determine vis' pid @@ -81,6 +88,9 @@ local function create_lock_file(lfile_path) end -- create the lock file with our pid + if not io.open(lfile_path, 'w') then + assert(os.execute('mkdir -p "' .. get_lock_dir() .. '"')) + end lock_file = assert(io.open(lfile_path, 'w')) lock_file:write(vis_pid) lock_file:close() |
