diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a216a76..f964c3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - Force Git checkout for plugin cache repositories ([#3169]) - Check compatibility when reusing previewer bytecode cache ([#3190]) - Disable kitty keyboard protocol on Windows due to `crossterm` inability to handle it ([#3250]) +- Prevent quotes in file(1) arguments from being stripped under MSYS2 ([#3364]) - Expose `ya` CLI in the Snap build ([#2904]) - Fallback to `PollWatcher` for file changes watching on NetBSD ([#2941]) - Generate unique image IDs for Kgp to tolerate tmux ([#3038]) @@ -1540,3 +1541,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3313]: https://github.com/sxyazi/yazi/pull/3313 [#3317]: https://github.com/sxyazi/yazi/pull/3317 [#3360]: https://github.com/sxyazi/yazi/pull/3360 +[#3364]: https://github.com/sxyazi/yazi/pull/3364 diff --git a/Cargo.lock b/Cargo.lock index 184ceeea..40b612b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2123,15 +2123,16 @@ dependencies = [ [[package]] name = "mlua" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be1c2bfc684b8a228fbaebf954af7a47a98ec27721986654a4cc2c40a20cc7e" +checksum = "935ac67539907efcd7198137eb7358e052555f77fe1b2916600a2249351f2b33" dependencies = [ "anyhow", "bstr", "either", "erased-serde", "futures-util", + "libc", "mlua-sys", "mlua_derive", "num-traits", @@ -2144,9 +2145,9 @@ dependencies = [ [[package]] name = "mlua-sys" -version = "0.8.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d4dc9cfc5a7698899802e97480617d9726f7da78c910db989d4d0fd4991d900" +checksum = "8c968af21bf6b19fc9ca8e7b85ee16f86e4c9e3d0591de101a5608086bda0ad8" dependencies = [ "cc", "cfg-if", @@ -5173,18 +5174,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.28" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fa6694ed34d6e57407afbccdeecfa268c470a7d2a5b0cf49ce9fcc345afb90" +checksum = "4ea879c944afe8a2b25fef16bb4ba234f47c694565e97383b36f3a878219065c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.28" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c640b22cd9817fae95be82f0d2f90b11f7605f6c319d16705c459b27ac2cbc26" +checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 5b25ac8f..de637afa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ hashbrown = { version = "0.16.1", features = [ "serde" ] } indexmap = { version = "2.12.1", features = [ "serde" ] } libc = "0.2.177" lru = "0.16.2" -mlua = { version = "0.11.4", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] } +mlua = { version = "0.11.5", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] } objc2 = "0.6.3" ordered-float = { version = "5.1.0", features = [ "serde" ] } parking_lot = "0.12.5" diff --git a/yazi-plugin/preset/plugins/mime-local.lua b/yazi-plugin/preset/plugins/mime-local.lua index c7b9d087..3d8e8d18 100644 --- a/yazi-plugin/preset/plugins/mime-local.lua +++ b/yazi-plugin/preset/plugins/mime-local.lua @@ -15,6 +15,29 @@ local function match_mimetype(line) end end +local function spawn_file1(paths) + local bin = os.getenv("YAZI_FILE_ONE") or "file" + local windows = ya.target_family() == "windows" + + local cmd = Command(bin):arg({ "-bL", "--mime-type" }):stdout(Command.PIPED) + if windows then + cmd:arg({ "-f", "-" }):stdin(Command.PIPED) + else + cmd:arg("--"):arg(paths) + end + + local child, err = cmd:spawn() + if not child then + return nil, Err("Failed to start `%s`, error: %s", bin, err) + elseif windows then + child:write_all(table.concat(paths, "\n")) + child:flush() + ya.drop(child:take_stdin()) + end + + return child +end + function M:fetch(job) local urls, paths = {}, {} for i, file in ipairs(job.files) do @@ -25,10 +48,9 @@ function M:fetch(job) end end - local cmd = os.getenv("YAZI_FILE_ONE") or "file" - local child, err = Command(cmd):arg({ "-bL", "--mime-type", "--" }):arg(paths):stdout(Command.PIPED):spawn() + local child, err = spawn_file1(paths) if not child then - return true, Err("Failed to start `%s`, error: %s", cmd, err) + return true, err end local updates, last = {}, ya.time() diff --git a/yazi-plugin/src/utils/app.rs b/yazi-plugin/src/utils/app.rs index c3d07048..e87759af 100644 --- a/yazi-plugin/src/utils/app.rs +++ b/yazi-plugin/src/utils/app.rs @@ -1,4 +1,7 @@ +use std::any::TypeId; + use mlua::{AnyUserData, ExternalError, Function, Lua}; +use tokio::process::{ChildStderr, ChildStdin, ChildStdout}; use yazi_binding::{Id, Permit, PermitRef, deprecate}; use yazi_proxy::{AppProxy, HIDER}; @@ -15,6 +18,19 @@ impl Utils { }) } + pub(super) fn drop(lua: &Lua) -> mlua::Result { + lua.create_function(|_, ud: AnyUserData| { + match ud.type_id() { + Some(t) if t == TypeId::of::() => {} + Some(t) if t == TypeId::of::() => {} + Some(t) if t == TypeId::of::() => {} + Some(t) => Err(format!("Cannot drop userdata of type {t:?}").into_lua_err())?, + None => Err("Cannot drop scoped userdata".into_lua_err())?, + }; + ud.destroy() + }) + } + pub(super) fn hide(lua: &Lua) -> mlua::Result { lua.create_async_function(|lua, ()| async move { deprecate!(lua, "`ya.hide()` is deprecated, use `ui.hide()` instead, in your {}\nSee #2939 for more details: https://github.com/sxyazi/yazi/pull/2939"); diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 5e94aac8..ca4e2083 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -10,6 +10,7 @@ pub fn compose( match key { // App b"id" => Utils::id(lua)?, + b"drop" => Utils::drop(lua)?, b"hide" => Utils::hide(lua)?, // Cache