-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean_package_dirs.pl
142 lines (124 loc) · 3.36 KB
/
clean_package_dirs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright (c) 2009 Symbian Foundation Ltd
# This component and the accompanying materials are made available
# under the terms of the License "Eclipse Public License v1.0"
# which accompanies this distribution, and is available
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
#
# Initial Contributors:
# Symbian Foundation Ltd - initial contribution.
#
# Contributors:
#
# Description:
# This is a helper script which cleans up some space on the machine by
# removing old package-build-related directories
use strict;
use Getopt::Long;
use File::Path;
my $sJOB_BASE_DIR = "D:\\fbf_job";
my $nJOB_MAX_DIR_AGE_SECS = 259200; # 259200=3 days
my $bJOB_SAVE_LAST_DIR = 1;
my $sPROJECT_BASE_DIR = "D:\\fbf_project";
my $nPROJECT_MAX_DIR_AGE_SECS = 259200; # 259200=3 days
my $bPROJECT_SAVE_LAST_DIR = 1;
my $nNow = time();
print "#### Cleaning old job dirs. ####\n";
opendir(DIR, "$sJOB_BASE_DIR");
my @asDirs = readdir(DIR);
close(DIR);
for my $sDir ( @asDirs )
{
next if ( $sDir eq "." or $sDir eq ".." );
next if ( ! -d "$sJOB_BASE_DIR\\$sDir" );
#print "--- $sDir\n";
if ( $sDir =~ /^([^.]+)\.T?(\d+)/ )
{
my $sBaseName = $1;
my $sBuildNumber = $2;
my $nTs = (stat("$sJOB_BASE_DIR\\$sDir"))[9]; # modified time
my $bLastDir = 0;
if ( $bJOB_SAVE_LAST_DIR )
{
my @asSimilarDirs = grep(/^$sBaseName(\.|$)/, @asDirs);
$bLastDir = 1;
for my $sSimilarDir ( @asSimilarDirs )
{
my $nSimDirTs = (stat("$sJOB_BASE_DIR\\$sSimilarDir"))[9];
$bLastDir = 0 if ( $nSimDirTs > $nTs );
}
$bLastDir = 1 if ( ! scalar @asSimilarDirs );
}
if ( $bJOB_SAVE_LAST_DIR && $bLastDir )
{
print "Skipping $sDir as last dir in the series\n";
}
elsif ( $nNow - $nTs > $nJOB_MAX_DIR_AGE_SECS )
{
print "Removing $sDir...\n";
print "rmdir /S $sJOB_BASE_DIR\\$sDir\n";
system("rmdir /S /Q $sJOB_BASE_DIR\\$sDir");
}
else
{
print "Keeping $sDir\n";
}
}
else
{
print "$sDir doesn't match\n";
}
}
print "#### Cleaning old project dirs. ####\n";
opendir(DIR, "$sPROJECT_BASE_DIR");
@asDirs = readdir(DIR);
close(DIR);
for my $sDir ( @asDirs )
{
next if ( $sDir eq "." or $sDir eq ".." );
next if ( ! -d "$sPROJECT_BASE_DIR\\$sDir" );
if ( $sDir =~ /^([^.]+)\.(\d+)/ or $sDir =~ /^([^.]+)$/ )
{
my $sBaseName = "";
my $sBuildNumber = 0;
if ( $sDir =~ /^([^.]+)\.(\d+)/ )
{
$sBaseName = $1;
$sBuildNumber = $2;
}
elsif ( $sDir =~ /^([^.]+)$/ )
{
$sBaseName = $1;
}
my $nTs = (stat("$sPROJECT_BASE_DIR\\$sDir"))[9]; # modified time
my $bLastDir = 0;
if ( $bPROJECT_SAVE_LAST_DIR )
{
my @asSimilarDirs = grep(/^$sBaseName(\.|$)/, @asDirs);
$bLastDir = 1;
for my $sSimilarDir ( @asSimilarDirs )
{
my $nSimDirTs = (stat("$sPROJECT_BASE_DIR\\$sSimilarDir"))[9];
$bLastDir = 0 if ( $nSimDirTs > $nTs );
}
$bLastDir = 1 if ( ! scalar @asSimilarDirs );
}
if ( $bPROJECT_SAVE_LAST_DIR && $bLastDir )
{
print "Skipping $sDir as last dir in the series\n";
}
elsif ( $nNow - $nTs > $nPROJECT_MAX_DIR_AGE_SECS )
{
print "Removing $sDir...\n";
print "rmdir /S $sPROJECT_BASE_DIR\\$sDir\n";
system("rmdir /S /Q $sPROJECT_BASE_DIR\\$sDir");
}
else
{
print "Keeping $sDir\n";
}
}
else
{
print "$sDir doesn't match\n";
}
}