Skip to content

Commit

Permalink
feat(check): warn about old Aura config files
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Jun 10, 2024
1 parent d1d41f0 commit 517760e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
3 changes: 2 additions & 1 deletion rust/aura-pm/i18n/en-US/aura_pm.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
36 changes: 31 additions & 5 deletions rust/aura-pm/src/command/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,44 @@ 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) {
let good = Path::new("/var/cache/aura").is_dir().not();
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);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/aura-pm/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Localised for Error {
}

/// Like [`xdg_cache`], but for `XDG_CONFIG_HOME`.
fn xdg_config() -> Result<PathBuf, Error> {
pub(crate) fn xdg_config() -> Result<PathBuf, Error> {
std::env::var("XDG_CONFIG_HOME")
.map(PathBuf::from)
.or_else(|_| std::env::var("HOME").map(|h| [&h, ".config"].iter().collect()))
Expand Down

0 comments on commit 517760e

Please sign in to comment.