10 |
|
# Copyright: 2003 (C) Shaun Ashby |
11 |
|
# |
12 |
|
#-------------------------------------------------------------------- |
13 |
+ |
|
14 |
+ |
=head1 NAME |
15 |
+ |
|
16 |
+ |
Cache::Cache - A generic directory cache object. |
17 |
+ |
|
18 |
+ |
=head1 SYNOPSIS |
19 |
+ |
|
20 |
+ |
my $cacheobject=Cache::Cache->new(); |
21 |
+ |
|
22 |
+ |
=head1 DESCRIPTION |
23 |
+ |
|
24 |
+ |
A package to provide caching of directory information. Directory timestamps |
25 |
+ |
are tracked on further reading of an existing cache and lists of modified |
26 |
+ |
directories and BuildFiles can be obtained. |
27 |
+ |
|
28 |
+ |
=head1 METHODS |
29 |
+ |
|
30 |
+ |
=over |
31 |
+ |
|
32 |
+ |
=cut |
33 |
+ |
|
34 |
|
package Cache::Cache; |
35 |
|
require 5.004; |
36 |
|
|
37 |
|
use Exporter; |
38 |
+ |
use Utilities::AddDir; |
39 |
|
@ISA=qw(Exporter); |
40 |
|
# |
41 |
+ |
|
42 |
+ |
=item C<new()> |
43 |
+ |
|
44 |
+ |
Create a new Cache::Cache object. The name of the cache is B<DirCache.db.gz> by default. |
45 |
+ |
|
46 |
+ |
=cut |
47 |
+ |
|
48 |
|
sub new() |
49 |
|
############################################################### |
50 |
|
# new # |
60 |
|
my $class=ref($proto) || $proto; |
61 |
|
my $self= |
62 |
|
{ |
63 |
< |
CACHENAME => "DirCache.db", # Name of global file/dir cache; |
63 |
> |
CACHENAME => "DirCache.db.gz", # Name of global file/dir cache; |
64 |
|
BFCACHE => {}, # BuildFile cache; |
65 |
|
DIRCACHE => {}, # Source code cache; |
66 |
+ |
EXTRASUFFIX => {}, # path with extra suffix; |
67 |
|
STATUS => 0, # Status of cache: 1 => something changed. If so, force save; |
68 |
|
VERBOSE => 0 # Verbose mode (0/1); |
69 |
|
}; |
72 |
|
return $self; |
73 |
|
} |
74 |
|
|
75 |
+ |
=item C<getdir($path)> |
76 |
+ |
|
77 |
+ |
Return a list of directories starting from $path. |
78 |
+ |
|
79 |
+ |
=cut |
80 |
+ |
|
81 |
|
sub getdir() |
82 |
|
{ |
83 |
|
my $self=shift; |
84 |
< |
my ($path) = @_; |
84 |
> |
my $path=shift; |
85 |
> |
my $ignore=shift || 'CVS|\\..*'; |
86 |
> |
my $match=shift || ".+"; |
87 |
> |
|
88 |
|
opendir (DIR, $path) || die "$path: cannot read: $!\n"; |
89 |
< |
# Skip .admin subdirectories too: |
90 |
< |
my @items = map { "$path/$_" } grep ($_ ne "." && $_ ne ".." && $_ ne ".admin", readdir(DIR)); |
89 |
> |
# Skip .admin and CVS subdirectories too. |
90 |
> |
# Also skip files that look like backup files or files being modified with emacs: |
91 |
> |
my @items = map { "$path/$_" } grep ((-d "$path/$_") && ($_=~/^($match)$/) && ($_!~/^($ignore)$/),readdir(DIR)); |
92 |
|
closedir (DIR); |
93 |
|
return @items; |
94 |
|
} |
95 |
|
|
96 |
+ |
=item C<prune($path)> |
97 |
+ |
|
98 |
+ |
Recursively remove directories from the cache starting at $path. |
99 |
+ |
|
100 |
+ |
=cut |
101 |
+ |
|
102 |
|
sub prune() |
103 |
|
{ |
104 |
|
my $self=shift; |
105 |
< |
my ($path) = @_; |
105 |
> |
my $path = shift; |
106 |
> |
my $skipparent = shift || 0; |
107 |
> |
my $suffix = shift || ""; |
108 |
> |
$self->extra_suffix($path,$suffix) if ($suffix); |
109 |
> |
if (!$skipparent) |
110 |
> |
{ |
111 |
> |
my $parent = $path; |
112 |
> |
$parent =~ s|(.*)/[^/]+$|$1|; |
113 |
> |
if ($parent ne $path && exists $self->{DIRCACHE}{$parent}) |
114 |
> |
{ |
115 |
> |
my ($time, @subs) = @{$self->{DIRCACHE}{$parent}}; |
116 |
> |
$self->{DIRCACHE}{$parent} = [ $time, grep ($_ ne $path, @subs) ]; |
117 |
> |
$self->{ADDEDDIR}{$parent}=1; |
118 |
> |
$self->cachestatus(1); |
119 |
> |
} |
120 |
> |
} |
121 |
> |
if (exists $self->{ADDEDDIR}{$path}){delete $self->{ADDEDDIR}{$path};} |
122 |
> |
return if ! exists $self->{DIRCACHE}{$path}; |
123 |
|
$self->cachestatus(1); |
124 |
< |
return if ! exists $self->{DIRCACHE}->{$path}; |
125 |
< |
my (undef, undef, @subs) = @{$self->{DIRCACHE}->{$path}}; |
126 |
< |
delete $self->{DIRCACHE}->{$path}; |
124 |
> |
foreach my $bf ("$ENV{SCRAM_BUILDFILE}.xml","$ENV{SCRAM_BUILDFILE}") |
125 |
> |
{ |
126 |
> |
if (exists $self->{BFCACHE}{"${path}/${bf}"}) |
127 |
> |
{ |
128 |
> |
if (!-f "${path}/${bf}") {$self->{REMOVEDBF}{"${path}/${bf}"}=1;} |
129 |
> |
delete $self->{BFCACHE}{"${path}/${bf}"}; |
130 |
> |
if (exists $self->{ADDEDBF}{"${path}/${bf}"}){delete $self->{ADDEDBF}{"${path}/${bf}"};} |
131 |
> |
last; |
132 |
> |
} |
133 |
> |
} |
134 |
> |
if (!-d $path) {$self->{REMOVEDDIR}{$path}=1;} |
135 |
> |
my (undef, @subs) = @{$self->{DIRCACHE}{$path}}; |
136 |
> |
delete $self->{DIRCACHE}{$path}; |
137 |
|
foreach my $sub (@subs) |
138 |
|
{ |
139 |
< |
$self->prune($sub); |
139 |
> |
$self->prune($sub,1); |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
+ |
=item C<checktree($path, $required, $dofiles)> |
144 |
+ |
|
145 |
+ |
A timestamp checking routine. Starting from $path, check all timestamps of |
146 |
+ |
directories and their files. Skip all files unless $dofiles is 1. |
147 |
+ |
|
148 |
+ |
=cut |
149 |
+ |
|
150 |
|
sub checktree() |
151 |
|
{ |
152 |
< |
my ($self, $path, $required, $dofiles) = @_; |
152 |
> |
my ($self, $path, $required) = @_; |
153 |
|
# Check if this path needs to be checked. If it exists, has the same mode |
154 |
|
# and the same time stamp, it's up to date and doesn't need to be checked. |
155 |
|
# Otherwise if it is a directory whose time-stamp has changed, rescan it. |
156 |
|
# If the path has be removed, prune it from the cache. Note that we skip |
157 |
|
# non-directories unless $dofiles is set. Considering only directories is |
158 |
|
# dramatically faster. |
79 |
– |
next if ($path =~ /\.admin/); # skip .admin dirs |
159 |
|
|
160 |
|
# NB: We stat each path only once ever. The special "_" file handle uses |
161 |
|
# the results from the last stat we've made. See man perlfunc/stat. |
162 |
|
if (! stat($path)) |
163 |
|
{ |
164 |
|
die "$path: $!\n" if $required; |
86 |
– |
$self->logmsg("SCRAM: $path: missing: removing from cache\n"); |
165 |
|
$self->prune($path); |
88 |
– |
# Something changed so force write of cache: |
89 |
– |
$self->cachestatus(1); |
166 |
|
return; |
167 |
|
} |
168 |
|
|
169 |
|
# If the entry in the cache is not the same mode or time, force an update. |
170 |
|
# Otherwise use the cache as the list of items we need to change. |
171 |
< |
my $cached = $self->{DIRCACHE}->{$path}; |
171 |
> |
my $cached = $self->{DIRCACHE}{$path}; |
172 |
|
my @items = (); |
173 |
+ |
my $matchdir='[a-zA-Z0-9].+'; |
174 |
|
|
175 |
|
if (! -d _) |
176 |
|
{ |
177 |
< |
if ($dofiles) |
178 |
< |
{ |
102 |
< |
$self->logmsg("SCRAM: $path: updating cache\n"); |
103 |
< |
$self->{DIRCACHE}->{$path} = [ (stat(_))[2, 9] ]; |
104 |
< |
} |
105 |
< |
else |
106 |
< |
{ |
107 |
< |
$self->logmsg("SCRAM: $path: not a directory: removing from parent's list\n"); |
108 |
< |
my $parent = $path; |
109 |
< |
$parent =~ s|(.*)/[^/]+$|$1|; |
110 |
< |
if ($parent ne $path && exists $self->{DIRCACHE}->{$parent}) |
111 |
< |
{ |
112 |
< |
my ($mode, $time, @subs) = @{$self->{DIRCACHE}->{$parent}}; |
113 |
< |
$self->{DIRCACHE}->{$parent} = [ $mode, $time, grep ($_ ne $path, @subs) ]; |
114 |
< |
} |
115 |
< |
$self->cachestatus(1); |
116 |
< |
} |
177 |
> |
$self->prune($path); |
178 |
> |
return; |
179 |
|
} |
180 |
< |
elsif (! $cached || $cached->[0] != (stat(_))[2]) |
180 |
> |
elsif (! $cached) |
181 |
|
{ |
182 |
|
# When a directory is added, this block is activated |
183 |
< |
$self->added_dirs($path); # Store the newly-added dir |
184 |
< |
$self->logmsg("SCRAM: $path: new or changed: pruning and recreating cache\n"); |
123 |
< |
$self->prune($path); |
124 |
< |
$self->{DIRCACHE}->{$path} = [ (stat(_))[2, 9], @items = $self->getdir($path) ]; |
183 |
> |
$self->{ADDEDDIR}{$path}=1; |
184 |
> |
$self->{DIRCACHE}{$path} = [ (stat(_))[9], @items = $self->getdir($path,'',$matchdir) ]; |
185 |
|
$required = 1; |
186 |
|
$self->cachestatus(1); |
187 |
|
} |
188 |
< |
elsif ($cached->[1] != (stat(_))[9]) |
188 |
> |
elsif ($cached->[0] != (stat(_))[9]) |
189 |
|
{ |
190 |
+ |
my $ntime = (stat(_))[9]; |
191 |
|
# When a subdirectory is removed, this block is activated |
192 |
|
# |
193 |
|
# This is a parent directory. We store this as any |
194 |
|
# update can be taken recursively from this dir: |
195 |
< |
$self->modified_parentdirs($path); |
135 |
< |
|
136 |
< |
$self->logmsg("SCRAM: $path: modified: updating cache\n"); |
195 |
> |
#$self->modified_parentdirs($path); |
196 |
|
# Current subdirs: |
197 |
< |
@items = $self->getdir($path); |
198 |
< |
|
199 |
< |
# Start checking from element number 2: |
200 |
< |
for (my $i = 2; $i <= $#$cached; $i++) |
201 |
< |
{ |
202 |
< |
if (! grep($cached->[$i] eq $_, @items)) |
197 |
> |
my %curdirs = map { $_ => 1 } $self->getdir($path,'',$matchdir); |
198 |
> |
my %olddirs = (); |
199 |
> |
for (my $i = 1; $i <= $#$cached; $i++) |
200 |
> |
{ |
201 |
> |
my $d = $cached->[$i]; |
202 |
> |
$olddirs{$d}=1; |
203 |
> |
if (!exists $curdirs{$d}) |
204 |
|
{ |
205 |
< |
# Add the removed path to a store for later access |
146 |
< |
# from the project cache. This info is needed to update |
147 |
< |
# the cached data: |
148 |
< |
$self->schedremoval($cached->[$i]); |
149 |
< |
# Remove all child data: |
150 |
< |
$self->clean_cache_recursive($cached->[$i]); |
205 |
> |
$self->prune($d,1); |
206 |
|
} |
207 |
< |
} |
207 |
> |
} |
208 |
|
|
209 |
< |
$self->{DIRCACHE}->{$path} = [ (stat(_))[2, 9], @items ]; |
210 |
< |
$required = 1; |
209 |
> |
foreach my $d (keys %curdirs) |
210 |
> |
{ |
211 |
> |
if (!exists $olddirs{$d}) |
212 |
> |
{ |
213 |
> |
if ($self->extra_suffix($d)) |
214 |
> |
{ |
215 |
> |
delete $curdirs{$d}; |
216 |
> |
} |
217 |
> |
} |
218 |
> |
} |
219 |
> |
|
220 |
> |
$self->{ADDEDDIR}{$path}=1; |
221 |
|
$self->cachestatus(1); |
222 |
+ |
@items = keys %curdirs; |
223 |
+ |
$required = 0; |
224 |
+ |
$self->{DIRCACHE}{$path} = [ $ntime, @items ]; |
225 |
|
} |
226 |
|
else |
227 |
|
{ |
228 |
< |
$self->logmsg("SCRAM: $path: valid: using cached directory list\n"); |
161 |
< |
(undef, undef, @items) = @{$self->{DIRCACHE}->{$path}}; |
228 |
> |
(undef, @items) = @{$self->{DIRCACHE}{$path}}; |
229 |
|
$required = 0; |
230 |
|
} |
231 |
+ |
if (($self->{cachereset}) && (!exists $self->{ADDEDDIR}{$path})) |
232 |
+ |
{ |
233 |
+ |
$self->{ADDEDDIR}{$path}=1; |
234 |
+ |
$self->cachestatus(1); |
235 |
+ |
} |
236 |
|
|
237 |
+ |
my $bfcachedir=$ENV{LOCALTOP}."/".$ENV{SCRAM_TMP}."/".$ENV{SCRAM_ARCH}."/cache/bf/${path}"; |
238 |
+ |
my $cbf="${bfcachedir}/$ENV{SCRAM_BUILDFILE}"; |
239 |
+ |
my $bftime=0; |
240 |
+ |
my $bf="${path}/$ENV{SCRAM_BUILDFILE}"; |
241 |
+ |
foreach my $ext (".xml","") |
242 |
+ |
{ |
243 |
+ |
my $bfn="$bf$ext"; |
244 |
+ |
if (! stat ($bfn)) |
245 |
+ |
{ |
246 |
+ |
if (exists $self->{BFCACHE}{$bfn}) |
247 |
+ |
{ |
248 |
+ |
$self->{REMOVEDBF}{$bfn}=1; |
249 |
+ |
delete $self->{BFCACHE}{$bfn}; |
250 |
+ |
Utilities::AddDir::adddir($bfcachedir); |
251 |
+ |
open(BF,">${cbf}");close(BF); |
252 |
+ |
$self->cachestatus(1); |
253 |
+ |
} |
254 |
+ |
} |
255 |
+ |
else |
256 |
+ |
{ |
257 |
+ |
$bftime = (stat(_))[9]; |
258 |
+ |
if ((! exists $self->{BFCACHE}{$bfn}) || |
259 |
+ |
($bftime != $self->{BFCACHE}{$bfn})) |
260 |
+ |
{ |
261 |
+ |
if ((!-f "${cbf}") || (exists $self->{BFCACHE}{$bfn})) |
262 |
+ |
{ |
263 |
+ |
Utilities::AddDir::adddir($bfcachedir); |
264 |
+ |
open(BF,">${cbf}");close(BF); |
265 |
+ |
} |
266 |
+ |
$self->{ADDEDBF}{$bfn}=1; |
267 |
+ |
delete $self->{BFCACHE}{$bf}; |
268 |
+ |
$self->{BFCACHE}{$bfn}=$bftime; |
269 |
+ |
if ($ext eq ""){$self->{nonxml}+=1;} |
270 |
+ |
$self->cachestatus(1); |
271 |
+ |
} |
272 |
+ |
elsif($self->{cachereset}) |
273 |
+ |
{ |
274 |
+ |
$self->{ADDEDBF}{$bfn}=1; |
275 |
+ |
if ($ext eq ""){$self->{nonxml}+=1;} |
276 |
+ |
if (!-f "${cbf}") |
277 |
+ |
{ |
278 |
+ |
Utilities::AddDir::adddir($bfcachedir); |
279 |
+ |
open(BF,">${cbf}");close(BF); |
280 |
+ |
} |
281 |
+ |
$self->cachestatus(1); |
282 |
+ |
} |
283 |
+ |
last; |
284 |
+ |
} |
285 |
+ |
} |
286 |
+ |
if (exists $self->{ExtraDirCache}) |
287 |
+ |
{ |
288 |
+ |
eval {$self->{ExtraDirCache}->DirCache($self,$path);}; |
289 |
+ |
} |
290 |
|
# Process sub-directories |
291 |
|
foreach my $item (@items) |
292 |
|
{ |
293 |
< |
$self->checktree($item, $required, $dofiles); |
293 |
> |
$self->checktree($item, $required); |
294 |
|
} |
295 |
|
} |
296 |
|
|
297 |
+ |
=item C<clean_cache_recursive($startdir)> |
298 |
+ |
|
299 |
+ |
Recursive remove cached data for directories under $startdir. |
300 |
+ |
|
301 |
+ |
=cut |
302 |
+ |
|
303 |
|
sub clean_cache_recursive() |
304 |
|
{ |
305 |
|
my $self=shift; |
317 |
|
return $self; |
318 |
|
} |
319 |
|
|
320 |
+ |
=item C<dirtree($dir,$dofiles)> |
321 |
+ |
|
322 |
+ |
Starting from $dir, scan the directory tree. Ignore files unless $dofiles is set. This |
323 |
+ |
function just calls checktree(). |
324 |
+ |
|
325 |
+ |
=cut |
326 |
+ |
|
327 |
|
sub dirtree() |
328 |
|
{ |
329 |
|
my $self=shift; |
330 |
< |
my ($dir,$dofiles) = @_; |
330 |
> |
my ($dir) = @_; |
331 |
|
|
332 |
|
# Get the directory tree: |
333 |
< |
$self->checktree($dir, 1, $dofiles); |
333 |
> |
$self->checktree($dir, 1); |
334 |
|
return $self; |
335 |
|
} |
336 |
|
|
337 |
+ |
=item C<checkfiles()> |
338 |
+ |
|
339 |
+ |
Function to actually run the timestamp checks. This is only run from |
340 |
+ |
SCRAM::CMD::build(). |
341 |
+ |
|
342 |
+ |
=cut |
343 |
+ |
|
344 |
|
sub checkfiles() |
345 |
|
{ |
346 |
|
my $self=shift; |
347 |
+ |
$self->{cachereset}=shift || 0; |
348 |
|
# Scan config dir for top-level data, then start from src: |
349 |
< |
my @scandirs=($ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR}, $ENV{SCRAM_SOURCEDIR}); |
204 |
< |
my $dofiles=1; |
349 |
> |
my @scandirs=($ENV{SCRAM_CONFIGDIR}, $ENV{SCRAM_SOURCEDIR}); |
350 |
|
# Loop over all directories that need scanning (normally just src and config): |
351 |
+ |
$self->{nonxml}=0; |
352 |
+ |
eval ("use SCRAM::Plugins::DirCache;"); |
353 |
+ |
if(!$@) {$self->{ExtraDirCache} = SCRAM::Plugins::DirCache->new();} |
354 |
|
foreach my $scand (@scandirs) |
355 |
|
{ |
356 |
|
$self->logmsg("SCRAM: Scanning $scand [dofiles set to ".$dofiles."]\n"); |
357 |
|
# Check the directory tree: |
358 |
< |
$self->dirtree($scand, $dofiles); |
211 |
< |
$dofiles=0; |
358 |
> |
$self->dirtree($scand); |
359 |
|
} |
360 |
< |
|
214 |
< |
# Mark everything in the cache old: |
215 |
< |
map { $_->[0] = 0 } values %{$self->{BFCACHE}}; |
216 |
< |
map { $_->[0] = 0 } values %{$self->{CONFIGCACHE}}; |
217 |
< |
|
218 |
< |
# Remember which directories have buildfiles in them: |
219 |
< |
my %files = map { -f $_ ? ($_ => [ (stat(_))[9] ]) : () } |
220 |
< |
map { "$_/BuildFile" } |
221 |
< |
keys %{$self->{DIRCACHE}}; |
222 |
< |
|
223 |
< |
# Get list of files in config dir: |
224 |
< |
my $configcache = {}; |
225 |
< |
my %configfiles = map { -f $_ && |
226 |
< |
$_ =~ m|$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}.*?$| |
227 |
< |
? ($_ => [ (stat(_))[9] ]) : () } keys %{$self->{DIRCACHE}}; |
228 |
< |
|
229 |
< |
# Also add ToolCache.db to the cache: FIXME: should probably use aglob here so |
230 |
< |
# that all SCRAM_ARCHs are taken into account. |
231 |
< |
$configfiles{$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH}."/ToolCache.db"} = |
232 |
< |
[ (stat($ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH}."/ToolCache.db"))[9] ]; |
233 |
< |
|
234 |
< |
# Compare or add to config file cache. We need this to be separate so we can tell if a |
235 |
< |
# file affecting our build has been changed: |
236 |
< |
while (my ($path, $vals) = each %configfiles) |
360 |
> |
if ($self->cachestatus()) |
361 |
|
{ |
362 |
< |
if ($self->{CONFIGCACHE}->{$path} && $self->{CONFIGCACHE}->{$path}[1] == $vals->[0]) |
363 |
< |
{ |
364 |
< |
$configcache->{$path} = $self->{CONFIGCACHE}->{$path}; |
365 |
< |
delete $self->{CONFIGCACHE}->{$path}; |
366 |
< |
} |
367 |
< |
else |
368 |
< |
{ |
245 |
< |
$self->{STATUSCONFIG}=1; |
246 |
< |
$self->logmsg("SCRAM: $path: changed\n"); |
247 |
< |
$configcache->{$path} = [ 1, @$vals ]; |
248 |
< |
delete $self->{CONFIGCACHE}->{$path}; |
362 |
> |
foreach my $bf ("$ENV{SCRAM_BUILDFILE}.xml","$ENV{SCRAM_BUILDFILE}") |
363 |
> |
{ |
364 |
> |
if (exists $self->{BFCACHE}{"$ENV{SCRAM_CONFIGDIR}/${bf}"}) |
365 |
> |
{ |
366 |
> |
$self->{ADDEDBF}{"$ENV{SCRAM_CONFIGDIR}/${bf}"}=1; |
367 |
> |
last; |
368 |
> |
} |
369 |
|
} |
370 |
|
} |
371 |
< |
|
372 |
< |
# Compare with existing cache: remove from cache what no longer |
253 |
< |
# exists, then check which build files are newer than the cache. |
254 |
< |
my $newcache = {}; |
255 |
< |
|
256 |
< |
while (my ($path, $vals) = each %files) |
371 |
> |
delete $self->{ExtraDirCache}; |
372 |
> |
if ($self->{nonxml} > 0) |
373 |
|
{ |
374 |
< |
if ($self->{BFCACHE}->{$path} && $self->{BFCACHE}->{$path}[1] == $vals->[0]) |
259 |
< |
{ |
260 |
< |
$newcache->{$path} = $self->{BFCACHE}->{$path}; |
261 |
< |
delete $self->{BFCACHE}->{$path}; |
262 |
< |
} |
263 |
< |
else |
264 |
< |
{ |
265 |
< |
$self->{STATUSSRC}=1; |
266 |
< |
$self->logmsg("SCRAM: $path: changed\n"); |
267 |
< |
$newcache->{$path} = [ 1, @$vals ]; |
268 |
< |
delete $self->{BFCACHE}->{$path}; |
269 |
< |
} |
374 |
> |
#print STDERR "**** WARNING: ",$self->{nonxml}," non-xml based $ENV{SCRAM_BUILDFILE} were read.\n"; |
375 |
|
} |
271 |
– |
|
272 |
– |
# If there were BuildFiles that were removed, force update of cache |
273 |
– |
# and remove the BUILDFILEDATA entries: |
274 |
– |
foreach my $path (keys %{$self->{BFCACHE}}) |
275 |
– |
{ |
276 |
– |
$self->logmsg("SCRAM: $path: removed. Build data will be removed from build cache.\n"); |
277 |
– |
$self->cachestatus(1); |
278 |
– |
# Store this so that later, we can tell the BuildDataStore to remove it: |
279 |
– |
$self->schedremoval($path); |
280 |
– |
} |
281 |
– |
|
282 |
– |
# Save the BuildFile cache: |
283 |
– |
delete $self->{BFCACHE}; |
284 |
– |
$self->{BFCACHE} = $newcache; |
285 |
– |
|
286 |
– |
# Save the config cache: |
287 |
– |
delete $self->{CONFIGCACHE}; |
288 |
– |
$self->{CONFIGCACHE} = $configcache; |
376 |
|
return $self; |
377 |
|
} |
378 |
|
|
379 |
+ |
=item C<dircache()> |
380 |
+ |
|
381 |
+ |
Return a reference to the directory cache hash. |
382 |
+ |
|
383 |
+ |
=cut |
384 |
+ |
|
385 |
|
sub dircache() |
386 |
|
{ |
387 |
|
my $self=shift; |
389 |
|
return $self->{DIRCACHE}; |
390 |
|
} |
391 |
|
|
392 |
+ |
=item C<added_dirs($path)> |
393 |
+ |
|
394 |
+ |
Add $path to the list of directories added since last scan, or return |
395 |
+ |
the list of added directories if no argument given. |
396 |
+ |
|
397 |
+ |
=cut |
398 |
+ |
|
399 |
|
sub added_dirs() |
400 |
|
{ |
401 |
|
my $self=shift; |
422 |
|
} |
423 |
|
} |
424 |
|
|
425 |
+ |
=item C<modified_parentdirs($path)> |
426 |
+ |
|
427 |
+ |
Add a directory $path to the list of parent directories (directories |
428 |
+ |
having subdirectories), or return a reference to the list. |
429 |
+ |
Storing this parent allows any update to be taken recursively from this |
430 |
+ |
location. |
431 |
+ |
|
432 |
+ |
=cut |
433 |
+ |
|
434 |
|
sub modified_parentdirs() |
435 |
|
{ |
436 |
|
my $self=shift; |
459 |
|
} |
460 |
|
} |
461 |
|
|
462 |
+ |
=item C<schedremoval($d)> |
463 |
+ |
|
464 |
+ |
Add directory $d to list of directories that should be removed |
465 |
+ |
recursively from the cache. |
466 |
+ |
If no arguments given, return a reference to a list of |
467 |
+ |
directories to be removed. |
468 |
+ |
|
469 |
+ |
=cut |
470 |
+ |
|
471 |
|
sub schedremoval() |
472 |
|
{ |
473 |
|
my $self=shift; |
492 |
|
} |
493 |
|
} |
494 |
|
|
495 |
+ |
=item C<filestatus()> |
496 |
+ |
|
497 |
+ |
Return a true or false value depending on whether |
498 |
+ |
a BuildFile was changed or not. |
499 |
+ |
|
500 |
+ |
=cut |
501 |
+ |
|
502 |
|
sub filestatus() |
503 |
|
{ |
504 |
|
my $self=shift; |
507 |
|
return $self->{STATUSSRC}; |
508 |
|
} |
509 |
|
|
510 |
+ |
=item C<configstatus()> |
511 |
+ |
|
512 |
+ |
Return a true or false value depending on whether |
513 |
+ |
a file in the config directory was changed or not. |
514 |
+ |
|
515 |
+ |
=cut |
516 |
+ |
|
517 |
|
sub configstatus() |
518 |
|
{ |
519 |
|
my $self=shift; |
522 |
|
return $self->{STATUSCONFIG}; |
523 |
|
} |
524 |
|
|
525 |
+ |
=item C<bf_for_scanning()> |
526 |
+ |
|
527 |
+ |
Return a list of BuildFiles to re-read. Note that this is only done |
528 |
+ |
if the status was changed (i.e. not necessary to read through the list |
529 |
+ |
of BuildFiles to know whether something changed as the flag B<STATUSSRC> |
530 |
+ |
is set as the source tree is checked). |
531 |
+ |
If B<STATUSCONFIG> is true, all BuildFiles are marked to be read. |
532 |
+ |
|
533 |
+ |
=cut |
534 |
+ |
|
535 |
|
sub bf_for_scanning() |
536 |
|
{ |
537 |
|
my $self=shift; |
538 |
|
my $MODIFIED = []; |
539 |
< |
|
398 |
< |
$self->{STATUSSRC} = 0; |
399 |
< |
|
400 |
< |
# Return a list of buildfiles to be reread. Note that we only do this |
401 |
< |
# if the status was changed (i.e. don't have to read through the list of BFs to know |
402 |
< |
# whether something changed as the flags STATUSSRC is set as the src tree is checked). |
403 |
< |
# Also we check to see if STATUSCONFIG is true. If so all BuildFiles are marked to be read: |
404 |
< |
if ($self->{STATUSCONFIG}) |
405 |
< |
{ |
406 |
< |
$self->{STATUSCONFIG} = 0; |
407 |
< |
# Return all the buildfiles since they'll all to be read: |
408 |
< |
return [ keys %{$self->{BFCACHE}} ]; |
409 |
< |
} |
410 |
< |
else |
411 |
< |
{ |
412 |
< |
# Only return the files that changed: |
413 |
< |
map { ( $self->{BFCACHE}{$_}->[0] == 1 ) && push(@$MODIFIED, $_) } keys %{$self->{BFCACHE}}; |
414 |
< |
# Reset the flag: |
415 |
< |
$self->{STATUSCONFIG} = 0; |
416 |
< |
} |
539 |
> |
map { push(@$MODIFIED, $_) } @{$self->{ADDEDBF}}; |
540 |
|
return $MODIFIED; |
541 |
|
} |
542 |
|
|
543 |
+ |
=item C<paths()> |
544 |
+ |
|
545 |
+ |
Return a reference to an array of directories for the current source tree. |
546 |
+ |
|
547 |
+ |
=cut |
548 |
+ |
|
549 |
|
sub paths() |
550 |
|
{ |
551 |
|
my $self=shift; |
552 |
|
my $paths = {}; |
553 |
|
|
554 |
< |
$self->{ALLDIRS} = []; |
555 |
< |
|
556 |
< |
# Pass over each dir, skipping those that are not wanted and |
428 |
< |
# storing those that are relevant to an array: |
429 |
< |
foreach my $path (keys %{$self->{DIRCACHE}}) |
430 |
< |
{ |
431 |
< |
if ( ! -d $path && $path != m|$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}.*?$|) |
432 |
< |
{ |
433 |
< |
$self->logmsg("SCRAM: $path no longer exists. Clearing from cache.\n"); |
434 |
< |
$self->cachestatus(1); |
435 |
< |
delete $self->{DIRCACHE}->{$path}; |
436 |
< |
} |
437 |
< |
else |
438 |
< |
{ |
439 |
< |
next if $path =~ m|/CVS$|; # Ignore CVS directories. |
440 |
< |
next if $path =~ m|/\.admin$|; # Ignore .admin directories. |
441 |
< |
next if $path =~ m|\Q$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}\L|; |
442 |
< |
push(@{$self->{ALLDIRS}},$path); |
443 |
< |
} |
444 |
< |
} |
445 |
< |
|
446 |
< |
# Return the array: |
447 |
< |
return $self->{ALLDIRS}; |
554 |
> |
my $ALLDIRS = []; |
555 |
> |
map { push(@$ALLDIRS, $_) } keys %{$self->{DIRCACHE}}; |
556 |
> |
return $ALLDIRS; |
557 |
|
} |
558 |
|
|
559 |
+ |
=item C<verbose()> |
560 |
+ |
|
561 |
+ |
Turn verbosity for the cache on or off. |
562 |
+ |
|
563 |
+ |
=cut |
564 |
+ |
|
565 |
|
sub verbose() |
566 |
|
{ |
567 |
|
my $self=shift; |
570 |
|
: $self->{VERBOSE} |
571 |
|
} |
572 |
|
|
573 |
+ |
=item C<cachestatus()> |
574 |
+ |
|
575 |
+ |
Set or return the cache status to indicate whether or not a file |
576 |
+ |
timestamp has changed since the last pass. |
577 |
+ |
|
578 |
+ |
=cut |
579 |
+ |
|
580 |
|
sub cachestatus() |
581 |
|
{ |
582 |
|
my $self=shift; |
585 |
|
: $self->{STATUS} |
586 |
|
} |
587 |
|
|
588 |
+ |
=item C<logmsg(@message)> |
589 |
+ |
|
590 |
+ |
Print a message to B<STDERR>. This is only used in |
591 |
+ |
checktree(), checkfiles() and paths(). |
592 |
+ |
|
593 |
+ |
=cut |
594 |
+ |
|
595 |
|
sub logmsg() |
596 |
|
{ |
597 |
|
my $self=shift; |
599 |
|
print STDERR @_ if $self->verbose(); |
600 |
|
} |
601 |
|
|
602 |
+ |
=item C<name()> |
603 |
+ |
|
604 |
+ |
Set or return the name of the cache. Normally set |
605 |
+ |
to B<DirCache.db.gz> (and not architecture dependent). |
606 |
+ |
|
607 |
+ |
=cut |
608 |
+ |
|
609 |
|
sub name() |
610 |
|
{ |
611 |
|
my $self=shift; |
614 |
|
: $self->{CACHENAME} |
615 |
|
} |
616 |
|
|
617 |
+ |
sub get_data() |
618 |
+ |
{ |
619 |
+ |
my $self=shift; |
620 |
+ |
my $type=shift; |
621 |
+ |
@_ ? $self->{$type} = shift |
622 |
+ |
: $self->{$type}; |
623 |
+ |
} |
624 |
+ |
|
625 |
+ |
sub extra_suffix() |
626 |
+ |
{ |
627 |
+ |
my $self=shift; |
628 |
+ |
my $path=shift; |
629 |
+ |
@_ ? $self->{EXTRASUFFIX}{$path}=shift |
630 |
+ |
: exists $self->{EXTRASUFFIX}{$path}; |
631 |
+ |
} |
632 |
+ |
|
633 |
+ |
sub get_nonxml() |
634 |
+ |
{ |
635 |
+ |
my $self=shift; |
636 |
+ |
return $self->{nonxml}; |
637 |
+ |
} |
638 |
+ |
|
639 |
|
1; |
640 |
+ |
|
641 |
+ |
=back |
642 |
+ |
|
643 |
+ |
=head1 AUTHOR |
644 |
+ |
|
645 |
+ |
Shaun Ashby (with contribution from Lassi Tuura) |
646 |
+ |
|
647 |
+ |
=head1 MAINTAINER |
648 |
+ |
|
649 |
+ |
Shaun Ashby |
650 |
+ |
|
651 |
+ |
=cut |
652 |
+ |
|