-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_oe_dirs.pl
executable file
·154 lines (135 loc) · 2.86 KB
/
clean_oe_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
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl -w
# This script removes builds of old modules. It looks at the r part (revision) of packages.
# Run the script from the build directory
# Clean up work directory
# Make inventory of directories that can be deleted, store in tobedel list.
%package = ();
@tobedel = ();
opendir( WORK, "tmp/work" ) || die "Something wrong with the directory: $!";
while ($dir = readdir( WORK ))
{
if ($dir =~ /-r([r\d]+)$/)
{
$rev = $1;
$dir =~ s/-r[r\d]+$/-r/;
if (exists( $package{$dir} ))
{
if ( $rev ne $package{$dir} )
{
if ( $rev gt $package{$dir} )
{
push( @tobedel, $dir . $package{$dir} );
$package{$dir} = $rev;
}
else
{
push( @tobedel, $dir . $rev );
}
}
}
else
{
$package{$dir} = $rev;
}
}
}
closedir( WORK );
# Delete found directories
if ( @tobedel > 0 )
{
$fls = "";
foreach $dir ( @tobedel )
{
$fls .= " tmp/work/" . $dir;
}
$cmd = "rm -rf " . $fls . " &> /dev/null";
system( $cmd ) && die $!;
}
# Clean up stamps directory
# Make inventory of files that can be deleted, store in tobedel list.
%package = ();
@tobedel = ();
opendir( STAMPS, "tmp/stamps" ) || die "Something wrong with the directory: $!";
while ($fil = readdir( STAMPS ))
{
if ($fil =~ /-r([r\d]+)\.do_(fetch|patch|configure|compile|build|install|populate_staging|package)$/)
{
$rev = $1;
$fil =~ s/-r[r\d]+\.do_(fetch|patch|configure|compile|build|install|populate_staging|package)$/-r/;
if (exists( $package{$fil} ))
{
if ( $rev gt $package{$fil} )
{
if (grep($_ eq $fil . $package{$fil}, @tobedel) == 0)
{
push( @tobedel, $fil . $package{$fil} );
}
$package{$fil} = $rev;
}
elsif ( $rev lt $package{$fil} )
{
if (grep($_ eq $fil . $rev, @tobedel) == 0)
{
push( @tobedel, $fil . $rev );
}
}
}
else
{
$package{$fil} = $rev;
}
}
}
closedir( STAMPS );
# Delete found files
if ( @tobedel > 0 )
{
$fls = "";
foreach $fil ( @tobedel )
{
$fls .= " tmp/stamps/" . $fil . "*";
}
$cmd = "rm -f " . $fls . " &> /dev/null";
system( $cmd ) && die $!;
}
# Clean up sources directory
# Make inventory of files that can be deleted, store in tobedel list.
%package = ();
@tobedel = ();
opendir( SOURCES, "../sources" ) || die "Something wrong with the directory: $!";
while ($fil = readdir( SOURCES ))
{
if ($fil =~ /_(\d+)_now\.tar\.gz$/)
{
$rev = $1;
$fil =~ s/\d+_now\.tar\.gz$//;
if (exists( $package{$fil} ))
{
if ( $rev > $package{$fil} )
{
push( @tobedel, $fil . $package{$fil} );
$package{$fil} = $rev;
}
else
{
push( @tobedel, $fil . $rev );
}
}
else
{
$package{$fil} = $rev;
}
}
}
closedir( SOURCES );
# Delete found files
if ( @tobedel > 0 )
{
$fls = "";
foreach $fil ( @tobedel )
{
$fls .= " ../sources/" . $fil . "_now.tar.gz";
}
$cmd = "rm -f " . $fls . " &> /dev/null";
system( $cmd ) && die $!;
}