diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-08-05 11:45:58 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-05 11:45:58 -0300 |
commit | 7f85bbc8fc0fd03fb1e4b01d64f334cd8d865828 (patch) | |
tree | c5f325d20aa925143a3b3a6adb3b07fc66ed4040 | |
parent | 548f0ec4be3d10bf694f1885b39561f92a74b09b (diff) | |
download | luarocks-7f85bbc8fc0fd03fb1e4b01d64f334cd8d865828.tar.gz luarocks-7f85bbc8fc0fd03fb1e4b01d64f334cd8d865828.tar.bz2 luarocks-7f85bbc8fc0fd03fb1e4b01d64f334cd8d865828.zip |
fs.unix.tools: add __gc behavior to fs lock (#1702)
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index d7334733..f1513820 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -311,6 +311,12 @@ function tools.is_superuser() | |||
311 | return fs.current_user() == "root" | 311 | return fs.current_user() == "root" |
312 | end | 312 | end |
313 | 313 | ||
314 | local lock_mt = { | ||
315 | __gc = function(lock) | ||
316 | fs.unlock_access(lock) | ||
317 | end | ||
318 | } | ||
319 | |||
314 | function tools.lock_access(dirname, force) | 320 | function tools.lock_access(dirname, force) |
315 | local ok, err = fs.make_dir(dirname) | 321 | local ok, err = fs.make_dir(dirname) |
316 | if not ok then | 322 | if not ok then |
@@ -336,10 +342,12 @@ function tools.lock_access(dirname, force) | |||
336 | local force_flag = force and " -f" or "" | 342 | local force_flag = force and " -f" or "" |
337 | 343 | ||
338 | if fs.execute(vars.LN .. force_flag, tempfile, lockfile) then | 344 | if fs.execute(vars.LN .. force_flag, tempfile, lockfile) then |
339 | return { | 345 | local lock = { |
340 | tempfile = tempfile, | 346 | tempfile = tempfile, |
341 | lockfile = lockfile, | 347 | lockfile = lockfile, |
342 | } | 348 | } |
349 | setmetatable(lock, lock_mt) | ||
350 | return lock | ||
343 | else | 351 | else |
344 | return nil, "File exists" -- same message as luafilesystem | 352 | return nil, "File exists" -- same message as luafilesystem |
345 | end | 353 | end |