diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 71d09a6..b6c7081 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,9 +72,6 @@ jobs: steps: - name: Download uses: actions/download-artifact@v2 - - name: look file stucture - run: | - ls -R - name: zip windows package win32-x64 uses: TheDoctor0/zip-release@v0.2.1 with: diff --git a/src/bee/lua_filesystem.rs b/src/bee/lua_filesystem.rs index 901b696..1b87b02 100644 --- a/src/bee/lua_filesystem.rs +++ b/src/bee/lua_filesystem.rs @@ -236,7 +236,6 @@ fn copy_file(_: &Lua, (source, destination): (LuaFilePath, LuaFilePath)) -> LuaR fn absolute(_: &Lua, path: LuaFilePath) -> LuaResult { let canonical_path = std::fs::canonicalize(&path.path)?; - let full_path_str = canonical_path.to_str().unwrap_or("").to_string(); // 移除 \\?\ 前缀 @@ -360,6 +359,35 @@ fn symlink_status(_: &Lua, path: LuaFilePath) -> LuaResult { Ok(SymlinkStatus::new(file_type)) } +fn pairs(lua: &Lua, path: LuaFilePath) -> LuaResult<(mlua::Function, mlua::Table, mlua::Value)> { + let table = lua.create_table()?; + if let Ok(_) = std::fs::exists(&path.path) { + for entry in std::fs::read_dir(&path.path)? { + let entry = entry?; + let path = entry.path(); + let path = LuaFilePath::new(path.to_str().unwrap_or("").to_string()); + let file_type = match std::fs::symlink_metadata(&path.path) { + Ok(metadata) => { + if metadata.file_type().is_symlink() { + "symlink".to_string() + } else if metadata.file_type().is_file() { + "file".to_string() + } else if metadata.file_type().is_dir() { + "directory".to_string() + } else { + "unknown".to_string() + } + } + Err(_) => "unknown".to_string(), + }; + let file_status = SymlinkStatus::new(file_type); + table.set(path.clone(), file_status)?; + } + } + let next = lua.globals().get::("next").unwrap(); + Ok((next, table, mlua::Nil)) +} + pub fn bee_filesystem(lua: &Lua) -> LuaResult { let exports = lua.create_table()?; @@ -397,17 +425,7 @@ pub fn bee_filesystem(lua: &Lua) -> LuaResult
{ )?; exports.set( "pairs", - lua.create_function(|lua, path: LuaFilePath| -> LuaResult<_> { - let table = lua.create_table()?; - for entry in std::fs::read_dir(&path.path)? { - let entry = entry?; - let path = entry.path(); - let path = LuaFilePath::new(path.to_str().unwrap_or("").to_string()); - table.set(path.clone(), true)?; - } - let next = lua.globals().get::("next").unwrap(); - Ok((next, table, mlua::Nil)) - })?, + lua.create_function(pairs)?, )?; exports.set("fullpath", lua.create_function(full_path)?)?; exports.set("symlink_status", lua.create_function(symlink_status)?)?; diff --git a/src/bee/lua_filewatch.rs b/src/bee/lua_filewatch.rs index 11a4e19..b854ff9 100644 --- a/src/bee/lua_filewatch.rs +++ b/src/bee/lua_filewatch.rs @@ -2,7 +2,7 @@ use mlua::prelude::LuaResult; use mlua::prelude::*; use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher}; // use std::path::PathBuf; -use std::sync::mpsc::{channel, Receiver, Sender}; +use std::sync::mpsc::{channel, Receiver}; use super::lua_filesystem::LuaFilePath; // use std::time::Duration; @@ -43,11 +43,18 @@ impl LuaFileWatch { if let Some(rx) = &self.receiver { if let Ok(event) = rx.try_recv() { let path = event.paths[0].to_str().unwrap().to_string(); + if let Some(filter) = &self.filter { + if let Ok(result) = filter.call::(path.clone()) { + if !result { + return Ok((mlua::Nil, mlua::Nil)); + } + } + } let kind = match event.kind { notify::EventKind::Create(_) => "create", notify::EventKind::Modify(_) => "modify", notify::EventKind::Remove(_) => "remove", - _ => "unknown" + _ => "unknown", }; return Ok((kind.into_lua(lua).unwrap(), path.into_lua(lua).unwrap())); diff --git a/src/codestyle/mod.rs b/src/codestyle/mod.rs index 63d43ed..9d8c38e 100644 --- a/src/codestyle/mod.rs +++ b/src/codestyle/mod.rs @@ -1,9 +1,11 @@ use mlua::Lua; +#[allow(unused)] fn not_implement(_: &Lua, _: mlua::MultiValue) -> mlua::Result<(bool, String)> { Ok((false, "not implement".to_string())) } +#[allow(unused)] pub fn fake_code_style(lua: &Lua) -> mlua::Result { let table = lua.create_table()?; table.set("format", lua.create_function(not_implement)?)?; diff --git a/src/lua_preload.rs b/src/lua_preload.rs index fbc5ff2..e08a81a 100644 --- a/src/lua_preload.rs +++ b/src/lua_preload.rs @@ -1,6 +1,8 @@ use crate::bee; +#[allow(unused)] use crate::codestyle::fake_code_style; use crate::lua_seri; +#[allow(unused)] use crate::override_lua; use mlua::{lua_State, prelude::*}; diff --git a/src/main.rs b/src/main.rs index a98414a..184a52e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,7 @@ mod codestyle; #[macro_use] extern crate lazy_static; - use std::{env, path}; - use mlua::prelude::*; #[tokio::main(flavor = "current_thread")]