From 0000814eafe1de7dbc6efdcda358cf7bba71d321 Mon Sep 17 00:00:00 2001
From: hankertrix <91734413+hankertrix@users.noreply.github.com>
Date: Wed, 18 Dec 2024 15:51:56 +0800
Subject: [PATCH] Make the code at least compile
---
yazi-plugin/src/fs/fs.rs | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs
index 447dc63f..a74ee69d 100644
--- a/yazi-plugin/src/fs/fs.rs
+++ b/yazi-plugin/src/fs/fs.rs
@@ -19,28 +19,12 @@ const TRUNCATE: u8 = 8;
const CREATE: u8 = 16;
const CREATE_NEW: u8 = 32;
-pub struct OpenOpts;
-
-impl OpenOpts {
- pub fn install(lua: &Lua) -> mlua::Result<()> {
- let open_options = lua.create_table_from([
- ("READ", READ),
- ("WRITE", WRITE),
- ("APPEND", APPEND),
- ("TRUNCATE", TRUNCATE),
- ("CREATE", CREATE),
- ("CREATE_NEW", CREATE_NEW),
- ])?;
-
- lua.globals().raw_set("OpenOpts", open_options)
- }
-}
-
pub fn compose(lua: &Lua) -> mlua::Result
{
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
b"cwd" => cwd(lua)?,
b"cha" => cha(lua)?,
+ b"open" => open(lua)?,
b"write" => write(lua)?,
b"remove" => remove(lua)?,
b"create_dir" => create_dir(lua)?,
@@ -54,6 +38,17 @@ pub fn compose(lua: &Lua) -> mlua::Result {
Ok(value)
})?;
+ let open_options = lua.create_table_from([
+ ("READ", READ),
+ ("WRITE", WRITE),
+ ("APPEND", APPEND),
+ ("TRUNCATE", TRUNCATE),
+ ("CREATE", CREATE),
+ ("CREATE_NEW", CREATE_NEW),
+ ])?;
+
+ lua.globals().raw_set("OpenOpts", open_options)?;
+
let fs = lua.create_table_with_capacity(0, 10)?;
fs.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
@@ -118,9 +113,11 @@ fn open(lua: &Lua) -> mlua::Result {
}
let result = open_opts.open(&*url).await;
-
match result {
- Ok(file) => (File::cast(&lua, file)?, Value::Nil).into_lua_multi(&lua),
+ Ok(_) => match File::cast(&lua, yazi_fs::File::from_dummy(url.clone(), None)) {
+ Ok(f) => (f, Value::Nil).into_lua_multi(&lua),
+ Err(e) => (Value::Nil, e).into_lua_multi(&lua),
+ },
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua),
}
})