From 005dbaa2d403b0ab1bb147922aed79ecebcdab71 Mon Sep 17 00:00:00 2001 From: DirkFi Date: Sat, 31 Aug 2024 17:13:11 -0700 Subject: [PATCH] Refactor to make the plugins can use tar to unzip when needed * Add spawn_tar function and tar_compatible function - Create spawn_tar function to run command with tar -xvf to unzip file to tmp file * Add os.excute() line to make sure the tmp dir exists because tar command will not automatically create that dir * Refactor the logic in the try function to if the zip file can be unzipped with tar and no password required, use tar, otherwise use 7z --- yazi-plugin/preset/plugins/archive.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/yazi-plugin/preset/plugins/archive.lua b/yazi-plugin/preset/plugins/archive.lua index 3b3f2658..b39ca58d 100644 --- a/yazi-plugin/preset/plugins/archive.lua +++ b/yazi-plugin/preset/plugins/archive.lua @@ -53,6 +53,17 @@ function M:seek(units) end end +function M:spawn_tar(args) + local command = "tar" + + local stdout = args[1] == "l" and Command.PIPED or Command.NULL + local child, code = Command(command):args(args):stdout(stdout):stderr(Command.PIPED):spawn() + if not child then + return nil, "Failed to spawn, error code: " .. tostring(code) + end + return child, nil +end + function M:spawn_7z(args) local last_error = nil local try = function(name)