Compare commits

...

8 Commits

Author SHA1 Message Date
Dirk Wang
d2fa314d7d
Merge 49b6e77d8d into 6e0065e3df 2024-09-06 19:35:14 -07:00
sxyazi
6e0065e3df
chore: update dependencies 2024-09-07 01:10:06 +08:00
DirkFi
49b6e77d8d Merge remote-tracking branch 'origin/main' into add_tar_lua 2024-09-03 11:16:58 -07:00
DirkFi
9a4bfbba2f Change stdout to the correct option of tar 2024-09-03 11:14:57 -07:00
DirkFi
0f889f9ed8 Change format based on rustfmt 2024-09-01 15:11:26 -07:00
DirkFi
bfc51d7609 Refactor the PR according to first review
* Create a new method "create" in fs.rs
 * Delete archive:is_encrypted in tar use
 * Convert the tar command from -xvf to -xaf
 * Add more File suffix that can be unzipped with tar
2024-09-01 15:05:05 -07:00
DirkFi
69e123ea05 Merge remote-tracking branch 'origin/main' into add_tar_lua 2024-09-01 15:02:57 -07:00
DirkFi
8443f74044 Refactor to make the plugins can use tar to unzip when needed
* Add spawn_tar function and tar_compatible function
  - Create spawn_tar function to run command with tar -xvf to unzip file to tmp
    file
 * Add os.excute() line to make sure the tmp dir exists because tar
   command will not automatically create that dir
 * Refactor the logic in the try function to if the zip file can be
   unzipped with tar and no password required, use tar, otherwise use
   7z
2024-08-31 17:13:11 -07:00
9 changed files with 143 additions and 65 deletions

78
Cargo.lock generated
View File

@ -153,7 +153,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -345,9 +345,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.15"
version = "1.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6"
checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b"
dependencies = [
"jobserver",
"libc",
@ -384,9 +384,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.16"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019"
checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac"
dependencies = [
"clap_builder",
"clap_derive",
@ -394,9 +394,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.15"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6"
checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73"
dependencies = [
"anstream",
"anstyle",
@ -406,9 +406,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.5.24"
version = "4.5.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7db6eca8c205649e8d3ccd05aa5042b1800a784e56bc7c43524fde8abbfa9b"
checksum = "205d5ef6d485fa47606b98b0ddc4ead26eb850aaa86abfb562a94fb3280ecba0"
dependencies = [
"clap",
]
@ -442,7 +442,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -621,7 +621,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -632,7 +632,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178"
dependencies = [
"darling_core",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -662,7 +662,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -672,7 +672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b"
dependencies = [
"derive_builder_core",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -918,7 +918,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1176,7 +1176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b23a0c8dfe501baac4adf6ebbfa6eddf8f0c07f56b058cc1288017e32397846c"
dependencies = [
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1196,7 +1196,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1495,7 +1495,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1588,7 +1588,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -1868,7 +1868,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2170,14 +2170,14 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
name = "serde_json"
version = "1.0.127"
version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
dependencies = [
"itoa",
"memchr",
@ -2343,7 +2343,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2359,9 +2359,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.76"
version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
dependencies = [
"proc-macro2",
"quote",
@ -2425,7 +2425,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2543,14 +2543,14 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
name = "tokio-stream"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1"
dependencies = [
"futures-core",
"pin-project-lite",
@ -2559,9 +2559,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.11"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
dependencies = [
"bytes",
"futures-core",
@ -2636,7 +2636,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2818,7 +2818,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -2916,7 +2916,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
"wasm-bindgen-shared",
]
@ -2938,7 +2938,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3037,7 +3037,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -3048,7 +3048,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]
@ -3503,7 +3503,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
"syn 2.0.77",
]
[[package]]

View File

@ -15,7 +15,7 @@ anyhow = "1.0.86"
arc-swap = "1.7.1"
base64 = "0.22.1"
bitflags = "2.6.0"
clap = { version = "4.5.16", features = [ "derive" ] }
clap = { version = "4.5.17", features = [ "derive" ] }
crossterm = { version = "0.28.1", features = [ "event-stream" ] }
dirs = "5.0.1"
futures = "0.3.30"
@ -28,11 +28,11 @@ ratatui = { version = "0.28.1", features = [ "unstable-rendered-line-info"
regex = "1.10.6"
scopeguard = "1.2.0"
serde = { version = "1.0.209", features = [ "derive" ] }
serde_json = "1.0.127"
serde_json = "1.0.128"
shell-words = "1.1.0"
tokio = { version = "1.40.0", features = [ "full" ] }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"
tokio-stream = "0.1.16"
tokio-util = "0.7.12"
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }
unicode-width = "0.1.13"
uzers = "0.12.1"

View File

@ -20,7 +20,7 @@ serde = { workspace = true }
[build-dependencies]
clap = { workspace = true }
clap_complete = "4.5.24"
clap_complete = "4.5.26"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

View File

@ -28,7 +28,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.3.3" }
# External build dependencies
anyhow = { workspace = true }
clap = { workspace = true }
clap_complete = "4.5.24"
clap_complete = "4.5.26"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
serde_json = { workspace = true }

View File

@ -25,7 +25,7 @@ bitflags = { workspace = true }
crossterm = { workspace = true }
dirs = { workspace = true }
futures = { workspace = true }
notify-fork = { version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
notify = { package = "notify-fork", version = "6.1.1", default-features = false, features = [ "macos_fsevent" ] }
parking_lot = { workspace = true }
ratatui = { workspace = true }
scopeguard = { workspace = true }

View File

@ -1,7 +1,7 @@
use std::{collections::{HashMap, HashSet}, time::Duration};
use anyhow::Result;
use notify_fork::{PollWatcher, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
use notify::{PollWatcher, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
use parking_lot::RwLock;
use tokio::{fs, pin, sync::{mpsc::{self, UnboundedReceiver}, watch}};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
@ -27,7 +27,7 @@ impl Watcher {
let (out_tx, out_rx) = mpsc::unbounded_channel();
let out_tx_ = out_tx.clone();
let handler = move |res: Result<notify_fork::Event, notify_fork::Error>| {
let handler = move |res: Result<notify::Event, notify::Error>| {
let Ok(event) = res else { return };
if event.kind.is_access() {
return;
@ -37,7 +37,7 @@ impl Watcher {
}
};
let config = notify_fork::Config::default().with_poll_interval(Duration::from_millis(500));
let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
if *yazi_adapter::WSL {
tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
} else {
@ -79,7 +79,7 @@ impl Watcher {
});
}
async fn fan_in(mut rx: watch::Receiver<HashSet<Url>>, mut watcher: impl notify_fork::Watcher) {
async fn fan_in(mut rx: watch::Receiver<HashSet<Url>>, mut watcher: impl notify::Watcher) {
loop {
let (mut to_unwatch, mut to_watch): (HashSet<_>, HashSet<_>) = {
let (new, old) = (&*rx.borrow_and_update(), &*WATCHED.read());
@ -88,7 +88,7 @@ impl Watcher {
to_unwatch.retain(|u| match watcher.unwatch(u) {
Ok(_) => true,
Err(e) if matches!(e.kind, notify_fork::ErrorKind::WatchNotFound) => true,
Err(e) if matches!(e.kind, notify::ErrorKind::WatchNotFound) => true,
Err(e) => {
error!("Unwatch failed: {e:?}");
false

View File

@ -53,6 +53,15 @@ function M:seek(units)
end
end
function M:spawn_tar(args)
local stdout = args[1] and args[1]:sub(0, 2) == "-t" and Command.PIPED or Command.NULL
local child, code = Command("tar"):args(args):stdout(stdout):stderr(Command.PIPED):spawn()
if not child then
return nil, "Failed to spawn, error code: " .. tostring(code)
end
return child, nil
end
function M:spawn_7z(args)
local last_error = nil
local try = function(name)

View File

@ -36,6 +36,38 @@ function M:entry(args)
end
end
function M:is_tar_compatible(url)
local tar_extensions = {
".tar.bz2",
".tb2",
".tbz",
".tbz2",
".tz2",
".tar.gz",
".tgz",
".taz",
".tar.lz",
".tlz",
".tar.lzma",
".tar.lzo",
".tar.xz",
".txz",
".tar.Z",
".tZ",
".taZ",
".tar.zst",
".tzst",
}
for _, ext in ipairs(tar_extensions) do
if url:find(ext .. "$") then
return true
end
end
return false
end
function M:try_with(url, pwd)
local parent = url:parent()
if not parent then
@ -48,22 +80,44 @@ function M:try_with(url, pwd)
end
local archive = require("archive")
local child, code = archive:spawn_7z { "x", "-aou", "-p" .. pwd, "-o" .. tostring(tmp), tostring(url) }
if not child then
fail("Spawn `7z` and `7zz` both commands failed, error code %s", code)
end
if self:is_tar_compatible(tostring(url)) and pwd == "" then
fs.create("dir", tmp)
local child, code = archive:spawn_tar { "-xaf", tostring(url), "-C", tostring(tmp) }
if not child then
fail("Failed to spawn `tar` command, error code %s", code)
end
local output, err = child:wait_with_output()
if output and output.status.code == 2 and archive:is_encrypted(output.stderr) then
fs.remove("dir_clean", tmp)
return true -- Needs retry
end
local output, err = child:wait_with_output()
if output and output.status.code == 2 then
fs.remove("dir_clean", tmp)
return true -- Needs retry
end
self:tidy(url, tmp)
if not output then
fail("7zip failed to output when extracting '%s', error code %s", err, url)
elseif output.status.code ~= 0 then
fail("7zip exited when extracting '%s', error code %s", url, output.status.code)
self:tidy(url, tmp)
if not output then
fail("tar failed to output when extracting '%s', error code %s", err, url)
elseif output.status.code ~= 0 then
fail("tar exited when extracting '%s', error code %s", url, output.status.code)
end
else
-- Fall back to 7z for other file types or needs password authentification
local child, code = archive:spawn_7z { "x", "-aou", "-p" .. pwd, "-o" .. tostring(tmp), tostring(url) }
if not child then
fail("Spawn `7z` and `7zz` both commands failed, error code %s", code)
end
local output, err = child:wait_with_output()
if output and output.status.code == 2 and archive:is_encrypted(output.stderr) then
fs.remove("dir_clean", tmp)
return true -- Needs retry
end
self:tidy(url, tmp)
if not output then
fail("7zip failed to output when extracting '%s', error code %s", err, url)
elseif output.status.code ~= 0 then
fail("7zip exited when extracting '%s', error code %s", url, output.status.code)
end
end
end

View File

@ -52,6 +52,21 @@ pub fn install(lua: &Lua) -> mlua::Result<()> {
}
})?,
),
(
"create",
lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move {
let result = match type_.to_str()? {
"file" => fs::File::create(&*url).await.map(|_| ()),
"dir" => fs::create_dir(&*url).await,
_ => Err("Creation type must be 'file', 'dir'".into_lua_err())?,
};
match result {
Ok(_) => (true, Value::Nil).into_lua_multi(lua),
Err(e) => (false, e.raw_os_error()).into_lua_multi(lua),
}
})?,
),
(
"read_dir",
lua.create_async_function(|lua, (url, options): (UrlRef, Table)| async move {