fix: check archive type with 7z

This commit is contained in:
itsvyle 2026-01-07 13:07:09 +01:00
parent ccce37ed7f
commit 29fa4a5a36
No known key found for this signature in database
GPG key ID: 4C5297BA5EC3107B

View file

@ -242,26 +242,17 @@ function M.is_encrypted(s) return s:find(" Wrong password", 1, true) end
function M.is_tar(path) return M.list_meta { "-p", tostring(path) } == "tar" end function M.is_tar(path) return M.list_meta { "-p", tostring(path) } == "tar" end
function M.is_nested_tar_path(path) function M.is_nested_tar_path(path)
-- stylua: ignore -- Warning: doing -slt will *not* print the .tar file, it will only print the .tar.* file
local exts = { -- doing -ba will print the .tar file in the listing, as the first line
-- Formats supported by 7z for tar archives local child = M.spawn_7z { "l", "-ba", "-sccUTF-8", "-p", path }
".tar.gz", ".tgz", ".tar.gzip", if not child then
".tar.bz2", ".tbz", ".tbz2", return false
".tar.xz", ".txz",
".tar.lzma", ".tlz",
-- Might be supported one day (and are supported by https://github.com/mcmilk/7-Zip-zstd)
".tar.zst", ".tzst",
".tar.br",
".tar.lz4", ".tar.lz5",
}
for _, ext in ipairs(exts) do
if path:sub(-#ext) == ext then
return true
end
end end
return false local next, event = child:read_line()
child:start_kill()
return event == 0 and next:match("(.+%.tar)[\r\n]+$") ~= nil
end end
return M return M