feat: commit code

This commit is contained in:
YuKun Liu committed 2022-10-03 08:47:58 -07:00
1 parent 77393b273e
commit b3dcebcc50
2 files changed
+29 -11

No files matched your search

+26 -4
View File
@@ -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)
});
}
}
+3 -7
View File
@@ -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();
}
}
}