Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'production/sdk/cleaners/dailyCleanDownloads.sh')
-rwxr-xr-xproduction/sdk/cleaners/dailyCleanDownloads.sh93
1 files changed, 75 insertions, 18 deletions
diff --git a/production/sdk/cleaners/dailyCleanDownloads.sh b/production/sdk/cleaners/dailyCleanDownloads.sh
index 72c245253..c3868ba2a 100755
--- a/production/sdk/cleaners/dailyCleanDownloads.sh
+++ b/production/sdk/cleaners/dailyCleanDownloads.sh
@@ -21,9 +21,44 @@ fi
# Utility to clean build machine
echo -e "\n\tDaily clean of ${HOSTNAME} download server on $(date )\n"
+#
+# Checks whether a build can be retained or not.
+# returns 0 if the build can be retained
+#
+function canBeRetained ()
+{
+ retval=1
+ buildName=$1
+ grep BUILD_FAILED ${buildName}/buildproperties.shsource >/dev/null 2>&1
+ if [ $? -ne 0 ]; then #build didn't fail
+ if [ -f "${buildName}/buildUnstable" ]; then #build is marked unstable so should not be retained
+ retval=1
+ else
+ retval=0
+ fi
+ fi
+ return $retval
+}
+
+#
+# remove a build
+#
+
+function removeBuild ()
+{
+ buildName=$1
+ rm -fr $buildname
+ RC=$?
+ if [[ $RC = 0 ]];then
+ echo -e "Removed: $buildname"
+ else
+ echo -e "\n\tAn Error occurred removing $buildname. RC: $RC"
+ fi
+}
+
cDir="/home/data/httpd/download.eclipse.org/eclipse/downloads/drops4"
buildType="I*"
-allOldBuilds=$( find ${cDir} -maxdepth 1 -type d -ctime +5 -name "${buildType}" )
+allOldBuilds=$( find ${cDir} -maxdepth 1 -type d -ctime +5 -name "${buildType}"|sort )
nbuilds=$( find ${cDir} -maxdepth 1 -type d -name "${buildType}" | wc -l )
echo -e "\tNumber of I-builds before cleaning: $nbuilds"
#echo -e "\n\tDEBUG: allOldBuilds: \n${allOldBuilds}"
@@ -52,29 +87,51 @@ done
#DEBUG echo -e "\n\tnewest: \n${newest}";
areNotToDelete=$(printf '%s\n' "${newest[@]}" | paste -sd '|')
#echo "DEBUG: areNotToDelete: ${areNotToDelete}"
+
+currentWeekNum=0 #week number from start of the year user to identify the week in which the build is created
+found=0 #it will be 1 when we found a build that can be retained in that week
+
for buildname in ${allOldBuilds}; do
if [[ $buildname =~ $areNotToDelete ]]
then
echo -e "\tDEBUG: Not removed (since one of 4 newest, even though old): \n\t$buildname"
else
- buildId=$(basename $buildname)
- yy=$(echo $buildId|cut -b2-5)
- mm=$(echo $buildId|cut -b6-7)
- dd=$(echo $buildId|cut -b8-9)
- day=${mm}/${dd}/${yy}
- dayOfWeek=$(date -d $day +%u)
+ buildId=$(basename $buildname) #extract buildId
+ yy=$(echo $buildId|cut -b2-5) #extract year from buildId
+ mm=$(echo $buildId|cut -b6-7) #extract month
+ dd=$(echo $buildId|cut -b8-9) #extract day
+ day=${mm}/${dd}/${yy} #construct build date
+ dayOfWeek=$(date -d $day +%u) #get the day of the week like monday, tue, etc
+ weekNum=$(date -d $day +%U) #get the week number from start of the year
+
+ #special case for Sunday. unix considers sunday as the start of the week. but for us we need to consider
+ #monday as start of the week. For this purpose we subtract 1 to place the build in previous week
+ if [ $dayOfWeek -eq 7 ]; then
+ weekNum=$(expr $weekNum - 1)
+ if [ $weekNum -le 0 ]; then #check for the yearend
+ weekNum=53
+ fi
+ fi
- #Make sure donot remove I builds from Monday
- if [ $dayOfWeek != 1 ]
- then
- rm -fr $buildname
- RC=$?
- if [[ $RC = 0 ]]
- then
- echo -e "Removed: $buildname"
- else
- echo -e "\n\tAn Error occurred removing $buildname. RC: $RC"
- fi
+ canBeRetained ${buildname}
+ retain=$?
+
+ if [ $weekNum -eq $currentWeekNum ]; then
+ if [ $retain -eq 0 -a $found -ne 1 ]; then # we didn't found a build that can be retained in the current week
+ found=1
+ echo retaining $buildId
+ else
+ echo removing $buildId
+ fi
+ else #week changed
+ currentWeekNum=$weekNum
+ found=0
+ if [ $retain -eq 0 -a $dayOfWeek -eq 1 ]; then
+ found=1
+ echo retaining $buildId
+ else
+ echo removing $buildId
+ fi
fi
fi
done

Back to the top