mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
fix: fail when package source is missing (#4124)
This commit is contained in:
parent
4dab480347
commit
b25ae9f82d
3 changed files with 24 additions and 21 deletions
|
|
@ -17,8 +17,14 @@ impl Dependency {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.delete_assets().await?;
|
self.delete_assets().await?;
|
||||||
self.delete_sources().await?;
|
if !self.delete_sources().await? {
|
||||||
Ok(())
|
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<()> {
|
pub(super) async fn delete_assets(&self) -> Result<()> {
|
||||||
|
|
@ -39,7 +45,7 @@ impl Dependency {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_sources(&self) -> Result<()> {
|
pub(super) async fn delete_sources(&self) -> Result<bool> {
|
||||||
let dir = self.target();
|
let dir = self.target();
|
||||||
let files =
|
let files =
|
||||||
if self.is_flavor { Self::flavor_files() } else { Self::plugin_files(&dir).await? };
|
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()))?;
|
.with_context(|| format!("failed to delete `{}`", path.display()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok_or_not_found(Local::regular(&dir).remove_dir().await).is_ok() {
|
Ok(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(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
use std::{env, io, path::{Path, PathBuf}, str::FromStr};
|
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 serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use twox_hash::XxHash3_128;
|
use twox_hash::XxHash3_128;
|
||||||
use yazi_fs::Xdg;
|
use yazi_fs::Xdg;
|
||||||
use yazi_macro::ok_or_not_found;
|
|
||||||
use yazi_shared::BytesExt;
|
use yazi_shared::BytesExt;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
|
@ -65,8 +64,11 @@ impl Dependency {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn plugin_files(dir: &Path) -> io::Result<Vec<String>> {
|
pub(super) async fn plugin_files(dir: &Path) -> Result<Vec<String>> {
|
||||||
let mut it = ok_or_not_found!(tokio::fs::read_dir(dir).await, return Ok(vec![]));
|
let mut it = tokio::fs::read_dir(dir)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("failed to read plugin directory `{}`", dir.display()))?;
|
||||||
|
|
||||||
let mut files: Vec<String> =
|
let mut files: Vec<String> =
|
||||||
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
|
["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect();
|
||||||
while let Some(entry) = it.next_entry().await? {
|
while let Some(entry) = it.next_entry().await? {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ impl Dependency {
|
||||||
|
|
||||||
self.header("Deploying package `{name}`")?;
|
self.header("Deploying package `{name}`")?;
|
||||||
self.is_flavor = maybe_exists(&from.join("flavor.toml")).await;
|
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 to = self.target();
|
||||||
let exists = maybe_exists(&to).await;
|
let exists = maybe_exists(&to).await;
|
||||||
|
|
@ -24,18 +26,21 @@ impl Dependency {
|
||||||
self.delete_assets().await?;
|
self.delete_assets().await?;
|
||||||
|
|
||||||
let res1 = Self::deploy_assets(from.join("assets"), to.join("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()) {
|
if !exists && (res2.is_err() || res1.is_err()) {
|
||||||
self.delete_assets().await?;
|
self.delete_assets().await?;
|
||||||
self.delete_sources().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;
|
Local::regular(&to).remove_dir_clean().await;
|
||||||
self.hash = self.hash().await?;
|
|
||||||
res2?;
|
res2?;
|
||||||
res1?;
|
res1?;
|
||||||
|
|
||||||
|
self.hash = self.hash().await?;
|
||||||
outln!("Done!")?;
|
outln!("Done!")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,8 +61,7 @@ impl Dependency {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn deploy_sources(from: &Path, to: &Path, is_flavor: bool) -> Result<()> {
|
async fn deploy_sources(from: &Path, to: &Path, files: Vec<String>) -> Result<()> {
|
||||||
let files = if is_flavor { Self::flavor_files() } else { Self::plugin_files(from).await? };
|
|
||||||
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));
|
||||||
copy_and_seal(&from, &to)
|
copy_and_seal(&from, &to)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue