Refactor the PR according to first review

* Create a new method "create" in fs.rs
 * Delete archive:is_encrypted in tar use
 * Convert the tar command from -xvf to -xaf
 * Add more File suffix that can be unzipped with tar
This commit is contained in:
DirkFi 2024-09-01 15:05:05 -07:00 committed by sxyazi
parent 005dbaa2d4
commit d2c2729c1c
No known key found for this signature in database
2 changed files with 22 additions and 4 deletions

View file

@ -54,10 +54,8 @@ function M:seek(units)
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()
local child, code = Command("tar"):args(args):stdout(stdout):stderr(Command.PIPED):spawn()
if not child then
return nil, "Failed to spawn, error code: " .. tostring(code)
end

View file

@ -3,7 +3,12 @@ use mlua::{ExternalError, ExternalResult, IntoLuaMulti, Lua, Table, Value};
use tokio::fs;
use yazi_shared::fs::remove_dir_clean;
use crate::{bindings::Cast, cha::Cha, file::File, url::{Url, UrlRef}};
use crate::{
bindings::Cast,
cha::Cha,
file::File,
url::{Url, UrlRef},
};
pub fn install(lua: &Lua) -> mlua::Result<()> {
lua.globals().raw_set(
@ -52,6 +57,21 @@ pub fn install(lua: &Lua) -> mlua::Result<()> {
}
})?,
),
(
"create",
lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move {
let result = match type_.to_str()? {
"file" => fs::File::create(&*url).await.map(|_| ()),
"dir" => fs::create_dir(&*url).await,
_ => Err("Creation type must be 'file', 'dir'".into_lua_err())?,
};
match result {
Ok(_) => (true, Value::Nil).into_lua_multi(lua),
Err(e) => (false, e.raw_os_error()).into_lua_multi(lua),
}
})?,
),
(
"read_dir",
lua.create_async_function(|lua, (dir, options): (UrlRef, Table)| async move {