Skip to content

Commit

Permalink
feat(check): check for empty directories of package clones
Browse files Browse the repository at this point in the history
These can arise if a clone failed for some reason.
  • Loading branch information
fosskers committed Aug 5, 2024
1 parent ca1e118 commit 51d67c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions rust/aura-pm/i18n/en-US/aura_pm.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 33 additions & 2 deletions rust/aura-pm/src/command/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -509,9 +509,10 @@ fn pacnew_work() -> Option<Vec<(PathBuf, u64)>> {
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) {
Expand Down Expand Up @@ -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());
}
}
}
}

0 comments on commit 51d67c6

Please sign in to comment.