1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 #!perl -w |
|
17 # |
|
18 # remove_old_builds.pl |
|
19 # |
|
20 # usage: |
|
21 # perl remove_old_builds.pl current_build_number build-directory required-free-space |
|
22 # |
|
23 use strict; |
|
24 |
|
25 sub usage |
|
26 { |
|
27 print <<USAGE_EOF; |
|
28 |
|
29 Usage: perl remove_old_builds.pl current_build build-directory required-bytes |
|
30 |
|
31 where: current_build = the number of the current build (e.g 00924_Symbian_OS_v9.1) |
|
32 build-directory = the top level directory containing the various builds |
|
33 required-bytes = the free disk space required. |
|
34 |
|
35 USAGE_EOF |
|
36 exit 1; |
|
37 } |
|
38 |
|
39 sub freespace |
|
40 { |
|
41 my $dir = shift; |
|
42 open FDIR, "dir /-c $dir |" or die "Cannot open FDIR $dir"; # /-c = suppress thousand separators (commas) |
|
43 my $s= -1; # Signifying "ERROR" |
|
44 while (<FDIR>) |
|
45 { |
|
46 if (/\s+(\d+) bytes free/) { $s=$1;} |
|
47 } |
|
48 return $s; |
|
49 } |
|
50 |
|
51 my $current_build=$ARGV[0]; |
|
52 my $bld_dir=$ARGV[1]; |
|
53 my $space=$ARGV[2]; |
|
54 |
|
55 unless ($space) { usage() }; # Must have all three args. So check for last one only. |
|
56 |
|
57 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 |
|
58 while (my $name = <DIRS>) |
|
59 { |
|
60 if (freespace($bld_dir) >= $space) |
|
61 { last; } |
|
62 chomp $name; |
|
63 chomp $current_build; |
|
64 |
|
65 if(($name =~ /^((D|T|M|MSF|TB|E|(\d{2,3}_))?(\d+))(([a-z]\.\d+)|([a-z])|(\.\d+))?/) && ($name ne $current_build)) |
|
66 { |
|
67 print "Removing $bld_dir\\$name\n"; |
|
68 if (system("rmdir /s /q $bld_dir\\$name")) |
|
69 { |
|
70 print "ERROR: Failed to remove: $bld_dir\\$name\n"; |
|
71 } |
|
72 } |
|
73 } |
|
74 close DIRS; |
|
75 |
|
76 if (freespace($bld_dir) < $space) |
|
77 { |
|
78 print "ERROR: Cannot create $space free bytes in $bld_dir\n"; |
|
79 exit 1; |
|
80 } |
|
81 |
|
82 exit 0; |
|
83 |
|
84 |
|
85 |
|
86 |
|