diff --git a/releng.control/cleanupArtifacts.sh b/releng.control/cleanupArtifacts.sh index f6e117a4b6a2e03f2c2fede716b360c2b8e31a45..5529c4872b7cfd1e7c591bf96e31ef2c7d8fed2e 100644 --- a/releng.control/cleanupArtifacts.sh +++ b/releng.control/cleanupArtifacts.sh @@ -18,14 +18,91 @@ fi # direcotory will be "saved" elsewhere, if needed. # We never delete the last existing build (even if "old"). +# = = = = = = + +function removeIf () +{ + # echo "arg: $1"; + + if [ -z $1 ] + then + echo " This script requires an argument. " ; + return 1; + fi + foundDirectory=$1 + + # should already be in foundDirectory, if execDir used + cd $foundDirectory + + # adding a few "should never happen" errror checks + if [ -d $foundDirectory ] + then + rm -fr $foundDirectory + echo " removed: $foundDirectory"; + else + echo "ERROR: the foundDirectory, $foundDirectory, is not a directory" + fi +} + +function removeArtifactsIf {} +{ + # echo "arg: $1"; + + if [ -z $1 ] + then + echo " This script requires an argument. " ; + return 1; + fi + foundDirectory=$1 + nSave=$2 + + if [ -z $nSave ] + then + nSave=1; + fi + + # should already be in foundDirectory, if execDir used + cd $foundDirectory + # move up one so we can examine syblings + cd .. + currentDirectory=`pwd` + echo " current working directory: $currentDirectory"; + ndirs=`ls -lA | wc -l` + ndirs=$(($ndirs - 1)); # don't count the "totals" line + # echo "NDirs: $ndirs" + + # if only one left, do not remove it, no matter how old + # or, as improved ... if less than or equal to nSave is left, do not remove + if [ $ndirs -le $nSave ] + then + exit 0; + fi + # This is unexpected, since otherwise this method should not have been called. + # So, this check is just a safety check. + if [ $ndirs -lt 1 ] + then + exit 101; + fi + + # ok, it is old, and not the only one left + # adding a few "should never happen" errror checks + if [ -d $foundDirectory ] + then + rm -fr $foundDirectory + echo " removed: $foundDirectory"; + else + echo "ERROR: the foundDirectory, $foundDirectory, is not a directory" + fi +} # requires parent Directiory as first argument # if nDays not specified as second argument, then 0 is assumed # (which is one day) # if "saveAtLeast" is not set, as third argument, then assumed to be 1 # (that is, at least "saveAtLeast" directories will be saved, no matter how old) -function removeOldArtifactsDirectories () { +function removeOldArtifactsDirectories () +{ parentDir=$1; ndays=$2; @@ -62,7 +139,7 @@ echo " number of directories before cleaning: ${before}"; # empty directories often result from "bad builds". We remove those no matter how old find ${parentDir} -mindepth 2 -maxdepth 3 -type d -empty -exec rm -fr '{}' \; # now remove old ones -find ${parentDir} -mindepth 2 -maxdepth 2 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeArtifactDirIf.sh '{}' $saveAtLeast \; +find ${parentDir} -mindepth 2 -maxdepth 2 -type d -atime +$ndays -execdir removeArtifactDirIf '{}' $saveAtLeast \; after=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`; echo " number of directories after cleaning: ${after}"; @@ -104,7 +181,7 @@ echo " number of directories before cleaning: ${before}"; # empty directories often result from "bad builds". We remove those no matter how old find ${parentDir} -mindepth 1 -maxdepth 2 -type d -empty -exec rm -fr '{}' \; # now remove old ones -find ${parentDir} -mindepth 1 -maxdepth 1 -type d -ctime +$ndays -exec ${RELENG_CONTROL}/removeIf.sh '{}' \; +find ${parentDir} -mindepth 1 -maxdepth 1 -type d -atime +$ndays -exec removeIf '{}' \; after=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`; echo " number of directories after cleaning: ${after}"; @@ -117,7 +194,8 @@ echo; # if nDays not specified as second argument, then 0 is assumed # (which is one day) # This is a good function to remove old files and directories from tmp -function removeOldDirectoriesAndFiles () { +function removeOldDirectoriesAndFiles () +{ parentDir=$1; ndays=$2; @@ -145,7 +223,7 @@ before=`find ${parentDir} | wc -l`; echo " number of directories and files before cleaning: ${before}"; # remove all old directories and files -find ${parentDir} -ctime +$ndays -exec rm -fr '{}' \; +find ${parentDir} -atime +$ndays -exec rm -fr '{}' \; after=`find ${parentDir} | wc -l`; echo " number of directories and files after cleaning: ${after}"; @@ -153,6 +231,8 @@ echo; } +# = = = = = = = + echo "INFO: Checking to remove old artifacts." removeOldArtifactsDirectories ${PROJECT_ARTIFACTS} 3 1; diff --git a/releng.control/removeArtifactDirIf.sh b/releng.control/removeArtifactDirIf.sh deleted file mode 100644 index ceb8b1db034fb17220b3c45dfbd5225ecfc8bb1b..0000000000000000000000000000000000000000 --- a/releng.control/removeArtifactDirIf.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# echo "arg: $1"; - -if [ -z $1 ] - then - echo " This script requires an argument. " ; - exit 1; - fi -foundDirectory=$1 -nSave=$2 - -if [ -z $nSave ] -then - nSave=1; -fi - -# should already be in foundDirectory, if execDir used -cd $foundDirectory -# move up one so we can examine syblings -cd .. -currentDirectory=`pwd` -echo " current working directory: $currentDirectory"; -ndirs=`ls -lA | wc -l` -ndirs=$(($ndirs - 1)); # don't count the "totals" line -# echo "NDirs: $ndirs" - -# if only one left, do not remove it, no matter how old -# or, as improved ... if less than or equal to nSave is left, do not remove -if [ $ndirs -le $nSave ] -then - exit 0; -fi -# This is unexpected, since otherwise this method should not have been called. -# So, this check is just a safety check. -if [ $ndirs -lt 1 ] -then - exit 101; -fi - -# ok, it is old, and not the only one left -# adding a few "should never happen" errror checks -if [ -d $foundDirectory ] -then - rm -fr $foundDirectory - echo " removed: $foundDirectory"; -else - echo "ERROR: the foundDirectory, $foundDirectory, is not a directory" -fi diff --git a/releng.control/removeIf.sh b/releng.control/removeIf.sh deleted file mode 100644 index d6409504edc001e9336d258c6697c078c4f3d353..0000000000000000000000000000000000000000 --- a/releng.control/removeIf.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# echo "arg: $1"; - -if [ -z $1 ] - then - echo " This script requires an argument. " ; - exit 1; - fi -foundDirectory=$1 - -# should already be in foundDirectory, if execDir used -cd $foundDirectory - -# adding a few "should never happen" errror checks -if [ -d $foundDirectory ] -then - rm -fr $foundDirectory - echo " removed: $foundDirectory"; -else - echo "ERROR: the foundDirectory, $foundDirectory, is not a directory" -fi