Skip to content

Commit 25d6bd1

Browse files
authored
feat: expose upsert file operations to Lua (#4266)
1 parent 6a7fc47 commit 25d6bd1

7 files changed

Lines changed: 34 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ regex = "1.13.1"
7171
regex-syntax = "0.8.11"
7272
reqwest = { version = "0.13.4", default-features = false, features = [ "rustls-no-provider" ] }
7373
rustls = { version = "0.23.43", default-features = false, features = [ "ring", "std" ] }
74-
russh = { version = "0.62.6", default-features = false, features = [ "ring", "rsa" ] }
74+
russh = { version = "0.62.7", default-features = false, features = [ "ring", "rsa" ] }
7575
scopeguard = "1.2.0"
7676
serde = { version = "1.0.229", features = [ "derive" ] }
7777
serde_json = "1.0.151"

yazi-cli/src/cache/clear.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use yazi_config::YAZI;
22
use yazi_fs::Xdg;
3+
use yazi_macro::outln;
34

45
use crate::cache::Cache;
56

67
impl Cache {
78
pub(crate) fn clear() -> anyhow::Result<()> {
89
if YAZI.preview.cache_dir == *Xdg::temp_dir() {
9-
println!("Clearing cache directory: \n{:?}", YAZI.preview.cache_dir);
10+
outln!("Clearing cache directory: \n{:?}", YAZI.preview.cache_dir)?;
1011
std::fs::remove_dir_all(&YAZI.preview.cache_dir)?;
1112
} else {
12-
println!(
13+
outln!(
1314
"You've changed the default cache directory, for your data's safety, please clear it manually: \n{:?}",
1415
YAZI.preview.cache_dir
15-
);
16+
)?;
1617
}
1718

1819
Ok(())

yazi-cli/src/dds/draw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{Context, Result};
22
use hashbrown::HashSet;
33
use tokio::{io::AsyncWriteExt, time};
44
use yazi_dds::{ClientReader, Payload, Stream, ember::EmberHi};
5-
use yazi_macro::try_format;
5+
use yazi_macro::{outln, try_format};
66

77
use crate::dds::Dds;
88

@@ -26,7 +26,7 @@ impl Dds {
2626
Some(s) => {
2727
let kind = s.split(',').next();
2828
if matches!(kind, Some(kind) if kinds.contains(kind)) {
29-
println!("{s}");
29+
outln!("{s}")?;
3030
}
3131
}
3232
None => loop {

yazi-cli/src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@ yazi_macro::mod_pub!(cache dds env package shared);
22

33
yazi_macro::mod_flat!(args);
44

5-
use std::process::ExitCode;
6-
75
use clap::Parser;
86
use yazi_macro::{errln, outln};
97
use yazi_shared::LOCAL_SET;
108

119
#[tokio::main]
12-
async fn main() -> ExitCode {
13-
yazi_shim::init();
10+
async fn main() -> anyhow::Result<()> {
11+
yazi_shim::init()?;
1412
yazi_shared::init();
1513
yazi_fs::init();
1614

1715
match LOCAL_SET.run_until(run()).await {
18-
Ok(()) => ExitCode::SUCCESS,
16+
Ok(()) => Ok(()),
1917
Err(e) => {
2018
for cause in e.chain() {
2119
if let Some(ioerr) = cause.downcast_ref::<std::io::Error>()
2220
&& ioerr.kind() == std::io::ErrorKind::BrokenPipe
2321
{
24-
return ExitCode::from(0);
22+
return Ok(());
2523
}
2624
}
25+
2726
errln!("{e:#}").ok();
28-
ExitCode::FAILURE
27+
Err(e)
2928
}
3029
}
3130
}

yazi-plugin/src/fs/fs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ fn op(lua: &Lua) -> mlua::Result<Function> {
141141
b"part" => super::FilesOp::part(lua, t),
142142
b"done" => super::FilesOp::done(lua, t),
143143
b"size" => super::FilesOp::size(lua, t),
144+
b"upsert" => super::FilesOp::upsert(lua, t),
144145
_ => Err("Unknown operation".into_lua_err())?,
145146
})
146147
}

yazi-plugin/src/fs/op.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use mlua::{Lua, Table, UserData};
22
use yazi_codegen::FromLuaOwned;
3+
use yazi_fs::file::File;
34
use yazi_macro::impl_data_any;
4-
use yazi_shared::url::UrlBuf;
5+
use yazi_shared::{path::PathBufDyn, url::UrlBuf};
56

67
#[derive(Clone, FromLuaOwned, UserData)]
78
pub(super) struct FilesOp(yazi_fs::FilesOp);
@@ -42,4 +43,12 @@ impl FilesOp {
4243

4344
Ok(Self(yazi_fs::FilesOp::Size(url, sizes.pairs().collect::<mlua::Result<_>>()?)))
4445
}
46+
47+
pub(super) fn upsert(_: &Lua, t: Table) -> mlua::Result<Self> {
48+
let url: UrlBuf = t.raw_get("url")?;
49+
let files: Table = t.raw_get("files")?;
50+
let files = files.pairs::<PathBufDyn, File>().collect::<mlua::Result<_>>()?;
51+
52+
Ok(Self(yazi_fs::FilesOp::Upserting(url, files)))
53+
}
4554
}

0 commit comments

Comments
 (0)