Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jan 11, 2025
1 parent 550df93 commit 7003816
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
7 changes: 3 additions & 4 deletions yazi-cli/src/package/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ impl Dependency {
pub(super) async fn delete(&self) -> Result<()> {
self.header("Deleting package `{name}`")?;

let path = self.deployed_directory();

if must_exists(&path).await {
fs::remove_dir_all(&path).await?;
let dir = self.target();
if must_exists(&dir).await {
fs::remove_dir_all(&dir).await?;
} else {
bail!(
"The package.toml file states that `{}` exists, but the directory was not found. The entry will be removed from package.toml.",
Expand Down
15 changes: 6 additions & 9 deletions yazi-cli/src/package/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@ pub(crate) struct Dependency {
}

impl Dependency {
#[inline]
pub(super) fn local(&self) -> PathBuf {
Xdg::state_dir()
.join("packages")
.join(format!("{:x}", XxHash3_128::oneshot(self.remote().as_bytes())))
}

#[inline]
pub(super) fn deployed_directory(&self) -> PathBuf {
pub(super) fn remote(&self) -> String {
// Support more Git hosting services in the future
format!("https://github.com/{}.git", self.parent)
}

pub(super) fn target(&self) -> PathBuf {
if self.is_flavor {
Xdg::config_dir().join(format!("flavors/{}", self.name))
} else {
Xdg::config_dir().join(format!("plugins/{}", self.name))
}
}

#[inline]
pub(super) fn remote(&self) -> String {
// Support more Git hosting services in the future
format!("https://github.com/{}.git", self.parent)
}

pub(super) fn header(&self, s: &str) -> Result<()> {
use crossterm::style::{Attribute, Print, SetAttributes};

Expand Down
3 changes: 1 addition & 2 deletions yazi-cli/src/package/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ impl Dependency {
self.header("Deploying package `{name}`")?;
self.is_flavor = maybe_exists(&from.join("flavor.toml")).await;

let to = self.deployed_directory();

let to = self.target();
if maybe_exists(&to).await && self.hash != self.hash().await? {
bail!(
"The user has modified the contents of the `{}` package. For safety, the operation has been aborted.
Expand Down
3 changes: 1 addition & 2 deletions yazi-cli/src/package/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use super::Dependency;

impl Dependency {
pub(crate) async fn hash(&self) -> Result<String> {
let dir = self.deployed_directory();

let dir = self.target();
let files = if self.is_flavor {
&[
"LICENSE",
Expand Down

0 comments on commit 7003816

Please sign in to comment.