refactor: remove migration code as it's no longer needed and causes errors (#1795)

This commit is contained in:
三咲雅 · Misaki Masa 2024-10-16 20:26:39 +08:00 committed by GitHub
parent e58cf555da
commit a6c9c93d58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 37 deletions

View File

@ -47,7 +47,6 @@ async fn main() -> anyhow::Result<()> {
Command::Pack(cmd) => {
package::init()?;
package::Package::migrate().await?;
if cmd.install {
package::Package::install_from_config("plugin", false).await?;
package::Package::install_from_config("flavor", false).await?;
@ -57,15 +56,7 @@ async fn main() -> anyhow::Result<()> {
} else if cmd.upgrade {
package::Package::install_from_config("plugin", true).await?;
package::Package::install_from_config("flavor", true).await?;
} else if let Some(mut repo) = cmd.add {
// TODO: remove this in the future
if repo.contains("#") {
repo = repo.replace("#", ":");
println!(
"WARNING: `#` has been deprecated in Yazi 0.3.1, please use `:` instead. See https://github.com/sxyazi/yazi/issues/1471 for more information."
);
}
} else if let Some(repo) = cmd.add {
package::Package::add_to_config(&repo).await?;
}
}

View File

@ -6,33 +6,6 @@ use yazi_shared::Xdg;
use super::Package;
impl Package {
// TODO: remove this in the future
pub(crate) async fn migrate() -> Result<()> {
let path = Xdg::config_dir().join("package.toml");
let mut doc = Self::ensure_config(&fs::read_to_string(&path).await.unwrap_or_default())?;
fn impl_(deps: &mut Array) -> Result<()> {
for dep in deps.iter_mut() {
let dep = dep.as_inline_table_mut().context("Dependency must be an inline table")?;
let use_ = dep.get("use").and_then(|d| d.as_str()).context("Missing `use` field")?;
if use_.contains("#") {
dep["use"] = use_.replace("#", ":").into();
}
if let Some(commit) = dep.get("commit").map(ToOwned::to_owned) {
dep.remove("commit");
dep.insert("rev", commit);
}
}
Ok(())
}
impl_(doc["plugin"]["deps"].as_array_mut().unwrap())?;
impl_(doc["flavor"]["deps"].as_array_mut().unwrap())?;
fs::write(path, doc.to_string()).await?;
Ok(())
}
pub(crate) async fn add_to_config(use_: &str) -> Result<()> {
let mut package = Self::new(use_, None);
let Some(name) = package.name() else { bail!("Invalid package `use`") };