diff -r 000000000000 -r 83f4b4db085c bldsystemtools/commonbldutils/remove_old_builds.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bldsystemtools/commonbldutils/remove_old_builds.pl Tue Feb 02 01:39:43 2010 +0200 @@ -0,0 +1,71 @@ +#!perl -w +# +# remove_old_builds.pl +# +# usage: +# perl remove_old_builds.pl current_build_number build-directory required-free-space +# +use strict; + +sub usage + { + print <) + { + if (/\s+(\d+) bytes free/) { $s=$1;} + } + return $s; + } + +my $current_build=$ARGV[0]; +my $bld_dir=$ARGV[1]; +my $space=$ARGV[2]; + +unless ($space) { usage() }; # Must have all three args. So check for last one only. + +open DIRS, "dir /b /ad /od $bld_dir |" or die "Cannot open DIRS $bld_dir"; # /b = "bare output" /ad = directories only /od = sort by date +while (my $name = ) + { + if (freespace($bld_dir) >= $space) + { last; } + chomp $name; + chomp $current_build; + + if(($name =~ /^((D|T|M|MSF|TB|E|(\d{2,3}_))?(\d+))(([a-z]\.\d+)|([a-z])|(\.\d+))?/) && ($name ne $current_build)) + { + print "Removing $bld_dir\\$name\n"; + if (system("rmdir /s /q $bld_dir\\$name")) + { + print "ERROR: Failed to remove: $bld_dir\\$name\n"; + } + } + } +close DIRS; + +if (freespace($bld_dir) < $space) + { + print "ERROR: Cannot create $space free bytes in $bld_dir\n"; + exit 1; + } + +exit 0; + + + +