mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Refactor
This commit is contained in:
parent
5e72032269
commit
9af51ae20d
4 changed files with 11 additions and 17 deletions
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -20,15 +20,18 @@ 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 {
|
||||
|
|
@ -36,12 +39,6 @@ impl Dependency {
|
|||
}
|
||||
}
|
||||
|
||||
#[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};
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue