From 517760ed21d0103a1a4c3d369dfb0610d98382cc Mon Sep 17 00:00:00 2001 From: Colin Woodbury Date: Tue, 11 Jun 2024 05:49:49 +0900 Subject: [PATCH] feat(check): warn about old Aura config files --- rust/aura-pm/i18n/en-US/aura_pm.ftl | 3 ++- rust/aura-pm/src/command/check.rs | 36 +++++++++++++++++++++++++---- rust/aura-pm/src/dirs.rs | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/rust/aura-pm/i18n/en-US/aura_pm.ftl b/rust/aura-pm/i18n/en-US/aura_pm.ftl index 48287e5b0..e6025472b 100644 --- a/rust/aura-pm/i18n/en-US/aura_pm.ftl +++ b/rust/aura-pm/i18n/en-US/aura_pm.ftl @@ -155,7 +155,7 @@ check-aconf-aura-exists = Aura config file exists? check-aconf-aura-exists-fix = Fix: Consider { $cmd } check-aconf-aura-parse = Aura config file can be parsed? check-aconf-old-dirs = No old Aura directories exist? -check-aconf-old-dirs-fix = You can delete { $old } in favour of { $new }. +check-aconf-old-conf = No old Aura config files exist? check-mconf = Makepkg Configuration (/etc/makepkg.conf) check-mconf-packager = PACKAGER set? check-mconf-packager-fix = Set { $cmd } within /etc/makepkg.conf @@ -247,6 +247,7 @@ common-no-packages = No packages specified. common-no-valid = No valid packages specified. common-no-work = Nothing to do. common-cancelled = Action cancelled. +common-replace = You can delete { $old } in favour of { $new }. # Misc. proceed = Proceed? diff --git a/rust/aura-pm/src/command/check.rs b/rust/aura-pm/src/command/check.rs index 3709abfc3..df4319fc7 100644 --- a/rust/aura-pm/src/command/check.rs +++ b/rust/aura-pm/src/command/check.rs @@ -169,6 +169,7 @@ fn aura_config(fll: &FluentLanguageLoader) { aura!(fll, "check-aconf"); parsable_aura_toml(fll); old_aura_dirs(fll); + old_aura_conf(fll); } fn old_aura_dirs(fll: &FluentLanguageLoader) { @@ -176,11 +177,36 @@ fn old_aura_dirs(fll: &FluentLanguageLoader) { let symbol = if good { GOOD.green() } else { WARN.yellow() }; println!(" [{}] {}", symbol, fl!(fll, "check-aconf-old-dirs")); - if let Ok(cache) = crate::dirs::aura_xdg_cache() { - let old = "/var/cache/aura".bold().yellow().to_string(); - let new = cache.display().to_string().bold().cyan().to_string(); - let msg = fl!(fll, "check-aconf-old-dirs-fix", old = old, new = new); - println!(" └─ {}", msg); + if !good { + if let Ok(cache) = crate::dirs::aura_xdg_cache() { + let old = "/var/cache/aura".bold().yellow().to_string(); + let new = cache.display().to_string().bold().cyan().to_string(); + let msg = fl!(fll, "common-replace", old = old, new = new); + println!(" └─ {}", msg); + } + } +} + +fn old_aura_conf(fll: &FluentLanguageLoader) { + if let Ok(xdg) = crate::dirs::xdg_config() { + let user = xdg.join("aura").join("aura.conf"); + let files = [Path::new("/etc/aura.conf"), &user]; + let exists: Vec<_> = files.into_iter().filter(|p| p.is_file()).collect(); + let good = exists.is_empty(); + let symbol = if good { GOOD.green() } else { WARN.yellow() }; + println!(" [{}] {}", symbol, fl!(fll, "check-aconf-old-conf")); + + if let Ok(aura) = crate::dirs::aura_config() { + let new = aura.display().to_string().bold().cyan().to_string(); + + let len = exists.len(); + for (i, file) in exists.into_iter().enumerate() { + let old = file.display().to_string().bold().yellow().to_string(); + let msg = fl!(fll, "common-replace", old = old, new = new.as_str()); + let arrow = if i + 1 == len { "└─" } else { "├─" }; + println!(" {} {}", arrow, msg); + } + } } } diff --git a/rust/aura-pm/src/dirs.rs b/rust/aura-pm/src/dirs.rs index 3e1e314ab..0694ab35d 100644 --- a/rust/aura-pm/src/dirs.rs +++ b/rust/aura-pm/src/dirs.rs @@ -36,7 +36,7 @@ impl Localised for Error { } /// Like [`xdg_cache`], but for `XDG_CONFIG_HOME`. -fn xdg_config() -> Result { +pub(crate) fn xdg_config() -> Result { std::env::var("XDG_CONFIG_HOME") .map(PathBuf::from) .or_else(|_| std::env::var("HOME").map(|h| [&h, ".config"].iter().collect()))