diff --git a/src/plugin/interface/fs.rs b/src/plugin/interface/fs.rs index afe9a8183..cf90d171c 100644 --- a/src/plugin/interface/fs.rs +++ b/src/plugin/interface/fs.rs @@ -2,9 +2,11 @@ use std::{ fs::{create_dir, create_dir_all, remove_dir_all}, path::PathBuf, io::{Read, Write}, }; +use std::fs::File; use mlua::UserData; - +use flate2::read::GzDecoder; +use tar::Archive; use crate::tools::extract_zip; pub struct PluginFileSystem; @@ -48,10 +50,30 @@ impl UserData for PluginFileSystem { let file = PathBuf::from(args.0); let target = PathBuf::from(args.1); let res = extract_zip(&file, &target); - if let Err(e) = res { - return Err(mlua::Error::RuntimeError(e.to_string())); + if let Err(_) = res { + return Ok(false); } - Ok(()) + Ok(true) + }); + methods.add_function("untar_gz_file", |_, args: (String, String)| { + + let file = PathBuf::from(args.0); + let target = PathBuf::from(args.1); + + let tar_gz = if let Ok(v) = File::open(file) { + v + } else { + return Ok(false); + }; + + let tar = GzDecoder::new(tar_gz); + let mut archive = Archive::new(tar); + if archive.unpack(&target).is_err() { + return Ok(false); + } + + + Ok(true) }); } } diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 2e02b8946..4253280a1 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -4,7 +4,7 @@ use std::{ sync::Mutex, }; -use mlua::{AsChunk, chunk, Lua, Table}; +use mlua::{AsChunk, Lua, Table}; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -136,10 +136,10 @@ impl PluginManager { } Err(e) => { // plugin init failed + log::warn!("Plugin init failed: {e}"); let _ = lua.load(mlua::chunk! { table.remove(manager, $idx) }).exec(); - log::warn!("Plugin init failed: {e}"); } } } @@ -289,8 +289,4 @@ impl PluginManager { res } - - pub fn plugin_status() { - let lua = LUA.lock().unwrap(); - } -} +} \ No newline at end of file