mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
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:
parent
005dbaa2d4
commit
d2c2729c1c
2 changed files with 22 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue