aptosaurus.sh: don't run rm via xargs if file list is empty

This commit is contained in:
Starbeamrainbowlabs 2020-05-21 17:29:36 +01:00
parent 0430fc5109
commit e3afca72e0
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 1 additions and 1 deletions

View File

@ -202,7 +202,7 @@ task_delete-old() {
task_begin "Deleting packages more than ${keep_versions} versions ago";
# Find and delete old package versions
export -f __analyse_package_simple;
find sources/ -type f -name "*.deb" -print0 | xargs -0 -n1 -P "$(nproc)" -I{} bash -c '__analyse_package_simple "{}"' | sort -k1,2Vr | uniq | awk -v keep_ago=${keep_versions} '{ package=$1; gsub(/^.*\//, "", package); gsub(/_.*+$/, "", package); arch=$1; gsub(/^.*_/, "", arch); gsub(/\.deb$/, "", arch); counts[package arch]++; if(counts[package arch] > keep_ago) print($1); }' | xargs --verbose rm
find sources/ -type f -name "*.deb" -print0 | xargs -0 -n1 -P "$(nproc)" -I{} bash -c '__analyse_package_simple "{}"' | sort -k1,2Vr | uniq | awk -v keep_ago=${keep_versions} '{ package=$1; gsub(/^.*\//, "", package); gsub(/_.*+$/, "", package); arch=$1; gsub(/^.*_/, "", arch); gsub(/\.deb$/, "", arch); counts[package arch]++; if(counts[package arch] > keep_ago) print($1); }' | xargs --verbose --no-run-if-empty rm
# Result resultant broken symlinks
find "${dir_repo}" -xtype l -delete -print0 | xargs -0 -n1 echo Deleting;
task_end "$?";