mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: support ya for miscellaneous files in folder assets
This commit is contained in:
parent
4194befb88
commit
ea75fe2b5c
2 changed files with 33 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use tokio::fs;
|
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;
|
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"][..]
|
&["init.lua", "README.md", "LICENSE"][..]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let dirs = &["assets"][..];
|
||||||
|
|
||||||
for file in files {
|
for file in files {
|
||||||
let (from, to) = (from.join(file), to.join(file));
|
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()))?;
|
.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!");
|
println!("Done!");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ async fn _copy_with_progress(from: PathBuf, to: PathBuf, cha: Cha) -> io::Result
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let mut reader = std::fs::File::open(from)?;
|
let mut reader = std::fs::File::open(from)?;
|
||||||
let mut writer = std::fs::OpenOptions::new()
|
let mut writer = std::fs::OpenOptions::new()
|
||||||
.mode(cha.mode as u32)
|
.mode(cha.mode)
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
|
|
@ -298,6 +298,23 @@ pub async fn remove_dir_clean(dir: &Path) {
|
||||||
fs::remove_dir(dir).await.ok();
|
fs::remove_dir(dir).await.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> 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
|
// Convert a file mode to a string representation
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[allow(clippy::collapsible_else_if)]
|
#[allow(clippy::collapsible_else_if)]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue