From 31ca5b408b06f623ad0111530eaf7d2d6a3b4dcb Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 5 Mar 2021 02:38:23 -0700 Subject: [PATCH] clear-all-htmlcache.pl: convert to show better progress Use the new Progress class to show a better running progress indicator since this operation can take a very long time when there are many projects and it's been run nice'd. Signed-off-by: Kyle J. McKay --- toolbox/clear-all-htmlcache.pl | 30 ++++++++++++++++++++++++++++++ toolbox/clear-all-htmlcache.sh | 42 ++++++++++-------------------------------- 2 files changed, 40 insertions(+), 32 deletions(-) create mode 100755 toolbox/clear-all-htmlcache.pl rewrite toolbox/clear-all-htmlcache.sh (76%) diff --git a/toolbox/clear-all-htmlcache.pl b/toolbox/clear-all-htmlcache.pl new file mode 100755 index 0000000..8447f03 --- /dev/null +++ b/toolbox/clear-all-htmlcache.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# Remove all files present in the htmlcache subdirectory of each project. +# A count of projects that had files to be removed is displayed. + +use strict; +use warnings; + +use lib "__BASEDIR__"; +use Girocco::Config; +use Girocco::CLIUtil; +use Girocco::Project; + +my $bd = $Girocco::Config::reporoot . '/'; +my @projects = Girocco::Project::get_full_list(); +my $progress = Girocco::CLIUtil::Progress->new( + scalar(@projects), "Clearing htmlcache files"); +my $count = 0; +my $cleared = 0; +foreach (@projects) { + my $hcd = $bd . $_ . ".git/htmlcache"; + opendir my $dh, $hcd or next; + my @files = map({/^(?![.][.]?$)(.*)$/ ? $1 : ()} readdir($dh)); + closedir $dh; + unlink($hcd . "/" . $_) foreach @files; + @files and ++$cleared; +} continue {$progress->update(++$count)} +$progress->clear; +print "Projects cleared: $cleared\n"; +exit 0 diff --git a/toolbox/clear-all-htmlcache.sh b/toolbox/clear-all-htmlcache.sh dissimilarity index 76% index 59b2d15..5f1a07c 100755 --- a/toolbox/clear-all-htmlcache.sh +++ b/toolbox/clear-all-htmlcache.sh @@ -1,32 +1,10 @@ -#!/bin/sh - -# Remove all files present in the htmlcache subdirectory of each project. -# A count of projects that had files to be removed is displayed. - -set -e - -. @basedir@/shlib.sh - -umask 002 - -base="$cfg_reporoot" -cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v "^_repo" | -( - count=0 - while read proj; do - projdir="$base/$proj.git" - if cd "$projdir/htmlcache" 2>/dev/null; then - if [ "$(echo *)" != '*' ]; then - rm -f * 2>/dev/null - count=$(( $count + 1 )) - if [ $(( $count % 10 )) = 0 ]; then - printf '%s ' $count - fi - fi - fi - done - if [ $(( $count % 10 )) != 0 ]; then - printf '%s ' $count - fi - printf '%s\n' 'done' -) +#!/bin/sh +# +# clear-all-htmlcache +# Remove all files present in the htmlcache subdirectory of each project. +# A count of projects that had files to be removed is displayed. + +# The old clear-all-htmlcache.sh has been replaced by clear-all-htmlcache.pl; +# it now simply runs that. + +exec @basedir@/toolbox/clear-all-htmlcache.pl "$@" -- 2.11.4.GIT