diff --git a/yazi-cli/src/package/deploy.rs b/yazi-cli/src/package/deploy.rs index 6bdc1056..82739260 100644 --- a/yazi-cli/src/package/deploy.rs +++ b/yazi-cli/src/package/deploy.rs @@ -1,6 +1,6 @@ use anyhow::{Context, Result, bail}; use tokio::fs; -use yazi_shared::{Xdg, fs::{maybe_exists, must_exists}}; +use yazi_shared::{Xdg, fs::{copy_dir_all, maybe_exists, must_exists}}; use super::Package; @@ -36,6 +36,8 @@ For safety, please manually delete it from your plugin/flavor directory and re-r &["init.lua", "README.md", "LICENSE"][..] }; + let dirs = &["assets"][..]; + for file in files { let (from, to) = (from.join(file), to.join(file)); @@ -44,6 +46,18 @@ 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()))?; } + for dir in dirs { + let (from, to) = (from.join(dir), to.join(dir)); + + if !from.exists() { + continue; + } + + copy_dir_all(&from, &to).await.with_context(|| { + format!("failed to copy dir `{}` to `{}`", from.display(), to.display()) + })?; + } + println!("Done!"); Ok(()) } diff --git a/yazi-shared/src/fs/fns.rs b/yazi-shared/src/fs/fns.rs index 0ce8a9b5..776967d5 100644 --- a/yazi-shared/src/fs/fns.rs +++ b/yazi-shared/src/fs/fns.rs @@ -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) @@ -298,6 +298,23 @@ pub async fn remove_dir_clean(dir: &Path) { fs::remove_dir(dir).await.ok(); } +pub async fn copy_dir_all(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + fs::create_dir_all(&dst).await?; + let mut entries = fs::read_dir(src).await?; + + while let Some(entry) = entries.next_entry().await? { + let file_type = entry.file_type().await?; + let dest_path = dst.as_ref().join(entry.file_name()); + + if file_type.is_dir() { + Box::pin(copy_dir_all(entry.path(), dest_path)).await?; + } else { + fs::copy(entry.path(), dest_path).await.ok(); + } + } + Ok(()) +} + // Convert a file mode to a string representation #[cfg(unix)] #[allow(clippy::collapsible_else_if)]