From 51d67c656326a801d09f341f726c41e5f5016865 Mon Sep 17 00:00:00 2001 From: Colin Woodbury Date: Mon, 5 Aug 2024 20:25:34 +0900 Subject: [PATCH] feat(check): check for empty directories of package clones These can arise if a clone failed for some reason. --- CHANGELOG.md | 1 + rust/aura-pm/i18n/en-US/aura_pm.ftl | 2 ++ rust/aura-pm/src/command/check.rs | 35 +++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56bbc531..584c84ee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - `--asdeps` reinstated. - New `[aur]` configuration option `warn_unknowns`. If `false`, warning messages regarding "unknown packages" detected during an upgrade will be silenced. +- `check`: a check for any broken package clones (empty directories). #### Fixed diff --git a/rust/aura-pm/i18n/en-US/aura_pm.ftl b/rust/aura-pm/i18n/en-US/aura_pm.ftl index bb50d920b..a755a9c5f 100644 --- a/rust/aura-pm/i18n/en-US/aura_pm.ftl +++ b/rust/aura-pm/i18n/en-US/aura_pm.ftl @@ -162,6 +162,8 @@ check-cache-missing-for-fix = Fix: View the missing packages with { $cmd } and r check-pkgs = Package Status check-pkgs-old = All explicitly installed, non-dep packages are up to date? check-pkgs-old-warn = { $pkg } was last updated { $days } ago. +check-pkgs-empty = All package clones are populated? +check-pkgs-empty-fix = Fix: Delete the following directories. # Thanks thanks-you = Thank you for using Aura. diff --git a/rust/aura-pm/src/command/check.rs b/rust/aura-pm/src/command/check.rs index 9b388ac82..62c3a8c0b 100644 --- a/rust/aura-pm/src/command/check.rs +++ b/rust/aura-pm/src/command/check.rs @@ -66,7 +66,7 @@ pub(crate) fn check(fll: &FluentLanguageLoader, env: &Env) -> Result<(), Error> makepkg_config(fll, env); snapshots(fll, &env.backups.snapshots, &caches); cache(fll, &alpm, pool, &caches); - packages(fll, &alpm); + packages(fll, env, &alpm); green!(fll, "common-done"); Ok(()) @@ -509,9 +509,10 @@ fn pacnew_work() -> Option> { Some(bads) } -fn packages(fll: &FluentLanguageLoader, alpm: &Alpm) { +fn packages(fll: &FluentLanguageLoader, env: &Env, alpm: &Alpm) { aura!(fll, "check-pkgs"); old_packages(fll, alpm); + empty_directories(fll, env); } fn old_packages(fll: &FluentLanguageLoader, alpm: &Alpm) { @@ -562,3 +563,33 @@ fn old_packages(fll: &FluentLanguageLoader, alpm: &Alpm) { } } } + +fn empty_directories(fll: &FluentLanguageLoader, env: &Env) { + if let Ok(dir) = env.aur.clones.read_dir() { + let mut empties: Vec<_> = dir + .filter_map(|de| de.ok()) + .map(|de| de.path()) + .par_bridge() + .filter_map(|p| { + p.read_dir() + .ok() + .map(|mut dir| dir.next().is_none()) + .unwrap_or(true) + .then_some(p) + }) + .collect(); + empties.sort(); + + let symbol = if empties.is_empty() { GOOD.green() } else { BAD.red() }; + println!(" [{}] {}", symbol, fl!(fll, "check-pkgs-empty"),); + + if empties.is_empty().not() { + let msg = fl!(fll, "check-pkgs-empty-fix"); + println!(" └─ {}", msg); + + for empty in empties { + println!(" - {}", empty.display()); + } + } + } +}