mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: simply the code
This commit is contained in:
parent
828331e830
commit
3fcbfc75c2
1 changed files with 17 additions and 17 deletions
|
|
@ -75,27 +75,27 @@ end
|
||||||
function M.spawn_7z_piped(argsX, argsL)
|
function M.spawn_7z_piped(argsX, argsL)
|
||||||
local last_err = nil
|
local last_err = nil
|
||||||
local try = function(name)
|
local try = function(name)
|
||||||
local childX, err = Command(name):arg(argsX):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
|
local src, err = Command(name):arg(argsX):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
|
||||||
if not childX then
|
if not src then
|
||||||
last_err = err
|
last_err = err
|
||||||
return childX, nil
|
return src
|
||||||
end
|
end
|
||||||
local childL, err =
|
local dst, err =
|
||||||
Command(name):arg(argsL):stdin(childX:take_stdout()):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
|
Command(name):arg(argsL):stdin(src:take_stdout()):stdout(Command.PIPED):stderr(Command.PIPED):spawn()
|
||||||
if not childL then
|
if not dst then
|
||||||
last_err = err
|
last_err = err
|
||||||
end
|
end
|
||||||
return childX, childL
|
return src, dst
|
||||||
end
|
end
|
||||||
|
|
||||||
local childX, childL = try("7zz")
|
local src, dst = try("7zz")
|
||||||
if not childX or not childL then
|
if not src then
|
||||||
childX, childL = try("7z")
|
src, dst = try("7z")
|
||||||
end
|
end
|
||||||
if not childX or not childL then
|
if not dst then
|
||||||
return ya.err("Failed to start either `7zz` or `7z`, error: " .. last_err)
|
return ya.err("Failed to start either `7zz` or `7z`, error: " .. last_err)
|
||||||
end
|
end
|
||||||
return childX, childL, last_err
|
return src, dst, last_err
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parse the output of a "7z l -slt" command. The caller is responsible for killing the child process right after the execution of this function
|
-- Parse the output of a "7z l -slt" command. The caller is responsible for killing the child process right after the execution of this function
|
||||||
|
|
@ -178,17 +178,17 @@ end
|
||||||
---@return integer bound
|
---@return integer bound
|
||||||
---@return Error? err
|
---@return Error? err
|
||||||
function M.list_tar_files(args, skip, limit)
|
function M.list_tar_files(args, skip, limit)
|
||||||
local childX, childL = M.spawn_7z_piped(
|
local src, dst = M.spawn_7z_piped(
|
||||||
{ "x", "-so", table.unpack(args) },
|
{ "x", "-so", table.unpack(args) },
|
||||||
{ "l", "-ba", "-slt", "-ttar", "-sccUTF-8", "-si" }
|
{ "l", "-ba", "-slt", "-ttar", "-sccUTF-8", "-si" }
|
||||||
)
|
)
|
||||||
if not childX or not childL then
|
if not src or not dst then
|
||||||
return {}, 0, Err("Failed to start either `7zz` or `7z`. Do you have 7-zip installed?")
|
return {}, 0, Err("Failed to start either `7zz` or `7z`. Do you have 7-zip installed?")
|
||||||
end
|
end
|
||||||
|
|
||||||
local files, bound, err = M.parse_7z_list(childL, skip, limit)
|
local files, bound, err = M.parse_7z_list(dst, skip, limit)
|
||||||
childL:start_kill()
|
dst:start_kill()
|
||||||
childX:start_kill()
|
src:start_kill()
|
||||||
|
|
||||||
return files, bound, err
|
return files, bound, err
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue