fix: fail when package source is missing (#4124)

This commit is contained in:
三咲雅 misaki masa 2026-07-14 01:11:34 +08:00 committed by GitHub
parent 4dab480347
commit b25ae9f82d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 21 deletions

View file

@ -17,8 +17,14 @@ impl Dependency {
}
self.delete_assets().await?;
self.delete_sources().await?;
Ok(())
if !self.delete_sources().await? {
outln!(
"For safety, user data will be preserved, manually delete them from: {}",
dir.display()
)?;
}
Ok(outln!("Done!")?)
}
pub(super) async fn delete_assets(&self) -> Result<()> {
@ -39,7 +45,7 @@ impl Dependency {
Ok(())
}
pub(super) async fn delete_sources(&self) -> Result<()> {
pub(super) async fn delete_sources(&self) -> Result<bool> {
let dir = self.target();
let files =
if self.is_flavor { Self::flavor_files() } else { Self::plugin_files(&dir).await? };
@ -49,15 +55,6 @@ impl Dependency {
.with_context(|| format!("failed to delete `{}`", path.display()))?;
}
if ok_or_not_found(Local::regular(&dir).remove_dir().await).is_ok() {
outln!("Done!")?;
} else {
outln!(
"Done!
For safety, user data has been preserved, please manually delete them within: {}",
dir.display()
)?;
}
Ok(())
Ok(ok_or_not_found(Local::regular(&dir).remove_dir().await).is_ok())
}
}

View file

@ -1,10 +1,9 @@
use std::{env, io, path::{Path, PathBuf}, str::FromStr};
use anyhow::{Result, bail};
use anyhow::{Context, Result, bail};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use twox_hash::XxHash3_128;
use yazi_fs::Xdg;
use yazi_macro::ok_or_not_found;
use yazi_shared::BytesExt;
#[derive(Clone, Default)]
@ -65,8 +64,11 @@ impl Dependency {
Ok(())
}
pub(super) async fn plugin_files(dir: &Path) -> io::Result<Vec<String>> {
let mut it = ok_or_not_found!(tokio::fs::read_dir(dir).await, return Ok(vec![]));
pub(super) async fn plugin_files(dir: &Path) -> Result<Vec<String>> {
let mut it = tokio::fs::read_dir(dir)
.await
.with_context(|| format!("failed to read plugin directory `{}`", dir.display()))?;
let mut files: Vec<String> =
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
while let Some(entry) = it.next_entry().await? {

View file

@ -13,6 +13,8 @@ impl Dependency {
self.header("Deploying package `{name}`")?;
self.is_flavor = maybe_exists(&from.join("flavor.toml")).await;
let files =
if self.is_flavor { Self::flavor_files() } else { Self::plugin_files(&from).await? };
let to = self.target();
let exists = maybe_exists(&to).await;
@ -24,18 +26,21 @@ impl Dependency {
self.delete_assets().await?;
let res1 = Self::deploy_assets(from.join("assets"), to.join("assets")).await;
let res2 = Self::deploy_sources(&from, &to, self.is_flavor).await;
let res2 = Self::deploy_sources(&from, &to, files).await;
if !exists && (res2.is_err() || res1.is_err()) {
self.delete_assets().await?;
self.delete_sources().await?;
} else if exists && (res2.is_err() || res1.is_err()) {
self.hash = self.hash().await?;
}
Local::regular(&to).remove_dir_clean().await;
self.hash = self.hash().await?;
res2?;
res1?;
self.hash = self.hash().await?;
outln!("Done!")?;
Ok(())
}
@ -56,8 +61,7 @@ impl Dependency {
Ok(())
}
async fn deploy_sources(from: &Path, to: &Path, is_flavor: bool) -> Result<()> {
let files = if is_flavor { Self::flavor_files() } else { Self::plugin_files(from).await? };
async fn deploy_sources(from: &Path, to: &Path, files: Vec<String>) -> Result<()> {
for file in files {
let (from, to) = (from.join(&file), to.join(&file));
copy_and_seal(&from, &to)