commit 76f6c76c269f7af0a6785745393a3a69740c93bb
parent 37f35309d47ff89682e9e8a586304beb7e5290b2
Author: phoebos <ben@bvnf.space>
Date: Tue, 18 Jul 2023 02:14:18 +0100
archive.tar_extract: permit not moving up if >1 top-level file
Diffstat:
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/bliss/archive.lua b/bliss/archive.lua
@@ -10,16 +10,17 @@ local function tar_extract(tarball)
end
local top = dirent.dir()
- if #top > 3 then utils.die("more than 1 top-level directory in tarball " .. tarball) end
- for _,v in ipairs(top) do if v ~= "." and v ~= ".." then top = v break end end
-
- local d = dirent.dir(top)
- for _,file in ipairs(d) do
- if file ~= "." and file ~= ".." then
- assert(file:sub(1,1) ~= "/")
- local ok, e = stdio.rename(top.."/"..file, file)
- if not ok then
- utils.die("couldn't rename " .. file .. ": " .. e)
+ if #top <= 3 then
+ for _,v in ipairs(top) do if v ~= "." and v ~= ".." then top = v break end end
+
+ local d = dirent.dir(top)
+ for _,file in ipairs(d) do
+ if file ~= "." and file ~= ".." then
+ assert(file:sub(1,1) ~= "/")
+ local ok, e = stdio.rename(top.."/"..file, file)
+ if not ok then
+ utils.die("couldn't rename " .. file .. ": " .. e)
+ end
end
end
end