Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support assets installation for the ya pack subcommand #1973

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion yazi-cli/src/package/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::path::PathBuf;

use anyhow::{Context, Result, bail};
use tokio::fs;
use yazi_shared::{Xdg, fs::{maybe_exists, must_exists}};
use yazi_shared::{Xdg, fs::{maybe_exists, must_exists, remove_dir_clean}};

use super::Package;

Expand Down Expand Up @@ -44,7 +46,42 @@ For safety, please manually delete it from your plugin/flavor directory and re-r
.with_context(|| format!("failed to copy `{}` to `{}`", from.display(), to.display()))?;
}

Self::deploy_assets(from.join("assets"), to.join("assets")).await?;

println!("Done!");
Ok(())
}

async fn deploy_assets(from: PathBuf, to: PathBuf) -> Result<()> {
use std::io::ErrorKind::NotFound;

match fs::read_dir(&to).await {
Ok(mut it) => {
while let Some(entry) = it.next_entry().await? {
fs::remove_file(entry.path())
.await
.with_context(|| format!("failed to remove `{}`", entry.path().display()))?;
}
}
Err(e) if e.kind() == NotFound => {}
Err(e) => Err(e).context(format!("failed to read `{}`", to.display()))?,
};

remove_dir_clean(&to).await;
match fs::read_dir(&from).await {
Ok(mut it) => {
fs::create_dir_all(&to).await?;
while let Some(entry) = it.next_entry().await? {
let (src, dist) = (entry.path(), to.join(entry.file_name()));
fs::copy(&src, &dist).await.with_context(|| {
format!("failed to copy `{}` to `{}`", src.display(), dist.display())
})?;
}
}
Err(e) if e.kind() == NotFound => {}
Err(e) => Err(e).context(format!("failed to read `{}`", from.display()))?,
}

Ok(())
}
}
2 changes: 1 addition & 1 deletion yazi-shared/src/fs/fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async fn _copy_with_progress(from: PathBuf, to: PathBuf, cha: Cha) -> io::Result
tokio::task::spawn_blocking(move || {
let mut reader = std::fs::File::open(from)?;
let mut writer = std::fs::OpenOptions::new()
.mode(cha.mode as u32)
.mode(cha.mode)
.write(true)
.create(true)
.truncate(true)
Expand Down
Loading