mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Rename to fs.create()
This commit is contained in:
parent
c0fe851fa5
commit
f4e7829e17
1 changed files with 13 additions and 13 deletions
|
|
@ -11,8 +11,8 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
|
||||||
b"cwd" => cwd(lua)?,
|
b"cwd" => cwd(lua)?,
|
||||||
b"cha" => cha(lua)?,
|
b"cha" => cha(lua)?,
|
||||||
b"write" => write(lua)?,
|
b"write" => write(lua)?,
|
||||||
|
b"create" => create(lua)?,
|
||||||
b"remove" => remove(lua)?,
|
b"remove" => remove(lua)?,
|
||||||
b"create_dir" => create_dir(lua)?,
|
|
||||||
b"read_dir" => read_dir(lua)?,
|
b"read_dir" => read_dir(lua)?,
|
||||||
b"unique_name" => unique_name(lua)?,
|
b"unique_name" => unique_name(lua)?,
|
||||||
_ => return Ok(Value::Nil),
|
_ => return Ok(Value::Nil),
|
||||||
|
|
@ -60,14 +60,12 @@ fn write(lua: &Lua) -> mlua::Result<Function> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove(lua: &Lua) -> mlua::Result<Function> {
|
fn create(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move {
|
lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move {
|
||||||
let result = match type_.as_bytes().as_ref() {
|
let result = match type_.as_bytes().as_ref() {
|
||||||
b"file" => fs::remove_file(&*url).await,
|
b"dir" => fs::create_dir(&*url).await,
|
||||||
b"dir" => fs::remove_dir(&*url).await,
|
b"dir_all" => fs::create_dir_all(&*url).await,
|
||||||
b"dir_all" => fs::remove_dir_all(&*url).await,
|
_ => Err("Creation type must be 'dir' or 'dir_all'".into_lua_err())?,
|
||||||
b"dir_clean" => Ok(remove_dir_clean(&url).await),
|
|
||||||
_ => Err("Removal type must be 'file', 'dir', 'dir_all', or 'dir_clean'".into_lua_err())?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -77,12 +75,14 @@ fn remove(lua: &Lua) -> mlua::Result<Function> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_dir(lua: &Lua) -> mlua::Result<Function> {
|
fn remove(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_async_function(|lua, (url, recursive): (UrlRef, Option<bool>)| async move {
|
lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move {
|
||||||
let result = if recursive.unwrap_or(false) {
|
let result = match type_.as_bytes().as_ref() {
|
||||||
fs::create_dir_all(&*url).await
|
b"file" => fs::remove_file(&*url).await,
|
||||||
} else {
|
b"dir" => fs::remove_dir(&*url).await,
|
||||||
fs::create_dir(&*url).await
|
b"dir_all" => fs::remove_dir_all(&*url).await,
|
||||||
|
b"dir_clean" => Ok(remove_dir_clean(&url).await),
|
||||||
|
_ => Err("Removal type must be 'file', 'dir', 'dir_all', or 'dir_clean'".into_lua_err())?,
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue