-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
ya pack -d
subcommand to delete packages (#2181)
Co-authored-by: sxyazi <[email protected]>
- Loading branch information
Showing
9 changed files
with
130 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use anyhow::{Context, Result, bail}; | ||
use tokio::fs; | ||
use yazi_fs::{maybe_exists, ok_or_not_found, remove_dir_clean}; | ||
use yazi_macro::outln; | ||
|
||
use super::Dependency; | ||
|
||
impl Dependency { | ||
pub(super) async fn delete(&self) -> Result<()> { | ||
self.header("Deleting package `{name}`")?; | ||
|
||
let dir = self.target(); | ||
if !maybe_exists(&dir).await { | ||
return Ok(outln!("Not found, skipping")?); | ||
} | ||
|
||
if self.hash != self.hash().await? { | ||
bail!( | ||
"You have modified the contents of the `{}` {}. For safety, the operation has been aborted. | ||
Please manually delete it from: {}", | ||
self.name, | ||
if self.is_flavor { "flavor" } else { "plugin" }, | ||
dir.display() | ||
); | ||
} | ||
|
||
let files = if self.is_flavor { | ||
&["flavor.toml", "tmtheme.xml", "README.md", "preview.png", "LICENSE", "LICENSE-tmtheme"][..] | ||
} else { | ||
&["main.lua", "README.md", "LICENSE"][..] | ||
}; | ||
for p in files.iter().map(|&f| dir.join(f)) { | ||
ok_or_not_found(fs::remove_file(&p).await) | ||
.with_context(|| format!("failed to delete `{}`", p.display()))?; | ||
} | ||
|
||
self.delete_assets().await?; | ||
if ok_or_not_found(fs::remove_dir(&dir).await).is_ok() { | ||
outln!("Done!")?; | ||
} else { | ||
outln!( | ||
"Done! | ||
For safety, user data has been preserved, please manually delete them within: {}", | ||
dir.display() | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(super) async fn delete_assets(&self) -> Result<()> { | ||
let assets = self.target().join("assets"); | ||
match fs::read_dir(&assets).await { | ||
Ok(mut it) => { | ||
while let Some(entry) = it.next_entry().await? { | ||
fs::remove_file(entry.path()) | ||
.await | ||
.with_context(|| format!("failed to remove `{}`", entry.path().display()))?; | ||
} | ||
} | ||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} | ||
Err(e) => Err(e).context(format!("failed to read `{}`", assets.display()))?, | ||
}; | ||
|
||
remove_dir_clean(&assets).await; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters