mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Safer deletion
This commit is contained in:
parent
6fc52713b5
commit
41487dac43
2 changed files with 17 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use yazi_fs::must_exists;
|
use yazi_fs::maybe_exists;
|
||||||
use yazi_macro::outln;
|
use yazi_macro::outln;
|
||||||
|
|
||||||
use super::Dependency;
|
use super::Dependency;
|
||||||
|
|
@ -10,16 +10,21 @@ impl Dependency {
|
||||||
self.header("Deleting package `{name}`")?;
|
self.header("Deleting package `{name}`")?;
|
||||||
|
|
||||||
let dir = self.target();
|
let dir = self.target();
|
||||||
if must_exists(&dir).await {
|
if !maybe_exists(&dir).await {
|
||||||
fs::remove_dir_all(&dir).await?;
|
return Ok(outln!("Not found, skipping")?);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if self.hash != self.hash().await? {
|
||||||
bail!(
|
bail!(
|
||||||
"The package.toml file states that `{}` exists, but the directory was not found. The entry will be removed from package.toml.",
|
"You have modified the contents of the `{}` {}. For safety, the operation has been aborted.
|
||||||
self.name
|
Please manually delete it from: {}",
|
||||||
|
self.name,
|
||||||
|
if self.is_flavor { "flavor" } else { "plugin" },
|
||||||
|
dir.display()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
outln!("Done!")?;
|
fs::remove_dir_all(&dir).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,11 @@ impl Dependency {
|
||||||
let to = self.target();
|
let to = self.target();
|
||||||
if maybe_exists(&to).await && self.hash != self.hash().await? {
|
if maybe_exists(&to).await && self.hash != self.hash().await? {
|
||||||
bail!(
|
bail!(
|
||||||
"The user has modified the contents of the `{}` package. For safety, the operation has been aborted.
|
"You have modified the contents of the `{}` {}. For safety, the operation has been aborted.
|
||||||
Please manually delete it from your plugins/flavors directory and re-run the command.",
|
Please manually delete it from `{}` and re-run the command.",
|
||||||
self.name
|
self.name,
|
||||||
|
if self.is_flavor { "flavor" } else { "plugin" },
|
||||||
|
to.display()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue