Rename to --overwrite

This commit is contained in:
sxyazi 2026-03-20 14:40:03 +08:00
parent c11064c3aa
commit 82f4222385
No known key found for this signature in database
13 changed files with 52 additions and 72 deletions

39
Cargo.lock generated
View file

@ -1388,9 +1388,9 @@ checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59"
[[package]]
name = "euclid"
version = "0.22.13"
version = "0.22.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df61bf483e837f88d5c2291dcf55c67be7e676b3a51acc48db3a7b163b91ed63"
checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06"
dependencies = [
"num-traits",
]
@ -1879,15 +1879,6 @@ dependencies = [
"digest 0.10.7",
]
[[package]]
name = "home"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d"
dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "hybrid-array"
version = "0.4.8"
@ -2106,9 +2097,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.17"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "jobserver"
@ -3697,9 +3688,9 @@ dependencies = [
[[package]]
name = "russh"
version = "0.57.1"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afe62631a04a1f4d71a14b99505483b95ff97c503b67d876c042fce659186956"
checksum = "30f6ce4f5d5105b934cfb4b8b3028aab4d5dcdff863cb8dda9edd06d39b8c4e8"
dependencies = [
"aes",
"bitflags 2.11.0",
@ -3722,7 +3713,6 @@ dependencies = [
"getrandom 0.2.17",
"hex-literal",
"hmac",
"home",
"inout",
"internal-russh-forked-ssh-key",
"libcrux-ml-kem",
@ -3750,7 +3740,7 @@ dependencies = [
"spki 0.7.3",
"ssh-encoding",
"subtle",
"thiserror 1.0.69",
"thiserror 2.0.18",
"tokio",
"typenum",
"zeroize",
@ -3758,15 +3748,14 @@ dependencies = [
[[package]]
name = "russh-cryptovec"
version = "0.52.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb0ed583ff0f6b4aa44c7867dd7108df01b30571ee9423e250b4cc939f8c6cf"
checksum = "cc109749696a6853cf2c3fba3537635264f3519a78a9f43c6b08c91edc024384"
dependencies = [
"libc",
"log",
"nix",
"ssh-encoding",
"winapi",
"windows-sys 0.59.0",
]
[[package]]
@ -6239,18 +6228,18 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.8.42"
version = "0.8.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3"
checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.42"
version = "0.8.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f"
checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89"
dependencies = [
"proc-macro2",
"quote",

View file

@ -62,7 +62,7 @@ percent-encoding = "2.3.2"
rand = { version = "0.9.2", default-features = false, features = [ "os_rng", "small_rng", "std" ] }
ratatui = { version = "0.30.0", features = [ "serde", "unstable-rendered-line-info", "unstable-widget-ref" ] }
regex = "1.12.3"
russh = { version = "0.57.1", default-features = false, features = [ "ring", "rsa" ] }
russh = { version = "0.58.0", default-features = false, features = [ "ring", "rsa" ] }
scopeguard = "1.2.0"
serde = { version = "1.0.228", features = [ "derive" ] }
serde_json = "1.0.149"

View file

@ -77,16 +77,16 @@ pub(super) enum CommandPkg {
Delete {
/// Packages to delete.
#[arg(index = 1, num_args = 1..)]
ids: Vec<String>,
/// Force delete, skipping local modification checks.
#[arg(short, long)]
force: bool,
ids: Vec<String>,
/// Overwrite any local changes made to packages.
#[arg(long)]
overwrite: bool,
},
/// Install all packages.
Install {
/// Force install, skipping local modification checks.
#[arg(short, long)]
force: bool,
/// Overwrite any local changes made to packages.
#[arg(long)]
overwrite: bool,
},
/// List all packages.
List,
@ -94,10 +94,10 @@ pub(super) enum CommandPkg {
Upgrade {
/// Packages to upgrade, upgrade all if unspecified.
#[arg(index = 1, num_args = 0..)]
ids: Vec<String>,
/// Force upgrade, skipping local modification checks.
ids: Vec<String>,
/// Overwrite any local changes made to packages.
#[arg(short, long)]
force: bool,
overwrite: bool,
},
}

View file

@ -44,11 +44,11 @@ impl Dds {
}
pub(super) fn ensure_version(version: Option<&str>) -> Result<()> {
if version.as_deref() != Some(EmberHi::version()) {
if version != Some(EmberHi::version()) {
bail!(
"Incompatible version (Ya {}, Yazi {}). Restart all `ya` and `yazi` processes if you upgrade either one.",
EmberHi::version(),
version.as_deref().unwrap_or("Unknown")
version.unwrap_or("Unknown")
);
}
Ok(())

View file

@ -78,10 +78,10 @@ async fn run() -> anyhow::Result<()> {
let mut pkg = package::Package::load().await?;
match cmd {
CommandPkg::Add { ids } => pkg.add_many(&ids).await?,
CommandPkg::Delete { ids, force } => pkg.delete_many(&ids, force).await?,
CommandPkg::Install { force } => pkg.install(force).await?,
CommandPkg::Delete { ids, overwrite } => pkg.delete_many(&ids, overwrite).await?,
CommandPkg::Install { overwrite } => pkg.install(overwrite).await?,
CommandPkg::List => pkg.print()?,
CommandPkg::Upgrade { ids, force } => pkg.upgrade_many(&ids, force).await?,
CommandPkg::Upgrade { ids, overwrite } => pkg.upgrade_many(&ids, overwrite).await?,
}
}

View file

@ -4,7 +4,7 @@ use super::{Dependency, Git};
use crate::shared::must_exists;
impl Dependency {
pub(super) async fn add(&mut self, force: bool) -> Result<()> {
pub(super) async fn add(&mut self, overwrite: bool) -> Result<()> {
self.header("Upgrading package `{name}`")?;
let path = self.local();
@ -14,7 +14,7 @@ impl Dependency {
Git::clone(&self.remote(), &path).await?;
};
self.deploy(force).await?;
self.deploy(overwrite).await?;
self.rev = Git::revision(&path).await?;
Ok(())
}

View file

@ -6,22 +6,18 @@ use super::Dependency;
use crate::shared::{maybe_exists, remove_sealed};
impl Dependency {
pub(super) async fn delete(&self, force: bool) -> Result<()> {
pub(super) async fn delete(&self, overwrite: bool) -> Result<()> {
self.header("Deleting package `{name}`")?;
let dir = self.target();
if !maybe_exists(&dir).await {
return Ok(outln!("Not found, skipping")?);
}
if force {
outln!("Warning: skipping local modification check for `{}`", self.name)?;
} else {
} else if !overwrite {
self.hash_check().await?;
}
self.delete_assets().await?;
self.delete_sources().await?;
Ok(())
}

View file

@ -8,7 +8,7 @@ use super::Dependency;
use crate::shared::{copy_and_seal, maybe_exists};
impl Dependency {
pub(super) async fn deploy(&mut self, force: bool) -> Result<()> {
pub(super) async fn deploy(&mut self, overwrite: bool) -> Result<()> {
let from = self.local().join(&self.child);
self.header("Deploying package `{name}`")?;
@ -16,12 +16,8 @@ impl Dependency {
let to = self.target();
let exists = maybe_exists(&to).await;
if exists {
if force {
outln!("Warning: skipping local modification check for `{}`", self.name)?;
} else {
self.hash_check().await?;
}
if exists && !overwrite {
self.hash_check().await?;
}
Local::regular(&to).create_dir_all().await?;

View file

@ -46,8 +46,7 @@ impl Dependency {
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 `{}` and re-run the command.
If you have not modified this package, re-run the command with --force to skip this check.",
Please manually delete it from `{}` and re-run the command, or add `--overwrite` to overwrite any local changes.",
self.name,
if self.is_flavor { "flavor" } else { "plugin" },
self.target().display()

View file

@ -4,7 +4,7 @@ use super::{Dependency, Git};
use crate::shared::must_exists;
impl Dependency {
pub(super) async fn install(&mut self, force: bool) -> Result<()> {
pub(super) async fn install(&mut self, overwrite: bool) -> Result<()> {
self.header("Fetching package `{name}`")?;
let path = self.local();
@ -18,7 +18,7 @@ impl Dependency {
Git::checkout(&path, self.rev.trim_start_matches('=')).await?;
}
self.deploy(force).await?;
self.deploy(overwrite).await?;
if self.rev.is_empty() {
self.rev = Git::revision(&path).await?;
}

View file

@ -28,19 +28,19 @@ impl Package {
Ok(())
}
pub(crate) async fn delete_many(&mut self, uses: &[String], force: bool) -> Result<()> {
pub(crate) async fn delete_many(&mut self, uses: &[String], overwrite: bool) -> Result<()> {
for u in uses {
let r = self.delete(u, force).await;
let r = self.delete(u, overwrite).await;
self.save().await?;
r?;
}
Ok(())
}
pub(crate) async fn install(&mut self, force: bool) -> Result<()> {
pub(crate) async fn install(&mut self, overwrite: bool) -> Result<()> {
macro_rules! go {
($dep:expr) => {
let r = $dep.install(force).await;
let r = $dep.install(overwrite).await;
self.save().await?;
r?;
};
@ -55,11 +55,11 @@ impl Package {
Ok(())
}
pub(crate) async fn upgrade_many(&mut self, uses: &[String], force: bool) -> Result<()> {
pub(crate) async fn upgrade_many(&mut self, uses: &[String], overwrite: bool) -> Result<()> {
macro_rules! go {
($dep:expr) => {
if uses.is_empty() || uses.contains(&$dep.r#use) {
let r = $dep.upgrade(force).await;
let r = $dep.upgrade(overwrite).await;
self.save().await?;
r?;
}
@ -116,12 +116,12 @@ impl Package {
Ok(())
}
async fn delete(&mut self, r#use: &str, force: bool) -> Result<()> {
async fn delete(&mut self, r#use: &str, overwrite: bool) -> Result<()> {
let Some(dep) = self.identical(&Dependency::from_str(r#use)?).cloned() else {
bail!("`{}` was not found in package.toml", r#use)
};
dep.delete(force).await?;
dep.delete(overwrite).await?;
if dep.is_flavor {
self.flavors.retain(|d| !d.identical(&dep));
} else {

View file

@ -3,7 +3,7 @@ use anyhow::Result;
use super::Dependency;
impl Dependency {
pub(super) async fn upgrade(&mut self, force: bool) -> Result<()> {
if self.rev.starts_with('=') { Ok(()) } else { self.add(force).await }
pub(super) async fn upgrade(&mut self, overwrite: bool) -> Result<()> {
if self.rev.starts_with('=') { Ok(()) } else { self.add(overwrite).await }
}
}

View file

@ -219,7 +219,7 @@ impl Data {
pub fn as_any<T: 'static>(&self) -> Option<&T> {
match self {
Self::Any(b) => (&**b).as_any().downcast_ref::<T>(),
Self::Any(b) => (**b).as_any().downcast_ref::<T>(),
_ => None,
}
}