41 |
|
|
42 |
|
=item C<new()> |
43 |
|
|
44 |
< |
Create a new Cache::Cache object. The name of the cache is B<DirCache.db> by default. |
44 |
> |
Create a new Cache::Cache object. The name of the cache is B<DirCache.db.gz> by default. |
45 |
|
|
46 |
|
=cut |
47 |
|
|
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; |
82 |
|
{ |
83 |
|
my $self=shift; |
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 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/$_") && ($_!~/^(CVS|\..*)$/),readdir(DIR)); |
91 |
> |
my @items = map { "$path/$_" } grep ((-d "$path/$_") && ($_=~/^($match)$/) && ($_!~/^($ignore)$/),readdir(DIR)); |
92 |
|
closedir (DIR); |
93 |
|
return @items; |
94 |
|
} |
170 |
|
# Otherwise use the cache as the list of items we need to change. |
171 |
|
my $cached = $self->{DIRCACHE}{$path}; |
172 |
|
my @items = (); |
173 |
+ |
my $matchdir='[a-zA-Z0-9].+'; |
174 |
|
|
175 |
|
if (! -d _) |
176 |
|
{ |
181 |
|
{ |
182 |
|
# When a directory is added, this block is activated |
183 |
|
$self->{ADDEDDIR}{$path}=1; |
184 |
< |
$self->{DIRCACHE}{$path} = [ (stat(_))[9], @items = $self->getdir($path) ]; |
184 |
> |
$self->{DIRCACHE}{$path} = [ (stat(_))[9], @items = $self->getdir($path,'',$matchdir) ]; |
185 |
|
$required = 1; |
186 |
|
$self->cachestatus(1); |
187 |
|
} |
194 |
|
# update can be taken recursively from this dir: |
195 |
|
#$self->modified_parentdirs($path); |
196 |
|
# Current subdirs: |
197 |
< |
my %curdirs = map { $_ => 1 } $self->getdir($path); |
197 |
> |
my %curdirs = map { $_ => 1 } $self->getdir($path,'',$matchdir); |
198 |
|
my %olddirs = (); |
199 |
|
for (my $i = 1; $i <= $#$cached; $i++) |
200 |
|
{ |
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}"; |
237 |
– |
if (($self->{convertxml}) && (!-f "${bf}.xml") && (-f "$bf")) |
238 |
– |
{ |
239 |
– |
my $fref; |
240 |
– |
$self->{nonxml} = $self->{nonxml}+1; |
241 |
– |
if (open($fref,">${bf}.xml")) |
242 |
– |
{ |
243 |
– |
print ">> Converting $bf => ${bf}.xml\n"; |
244 |
– |
$self->{convertxml}->clean(); |
245 |
– |
my $xml=$self->{convertxml}->convert($bf); |
246 |
– |
foreach my $line (@$xml){print $fref "$line\n";} |
247 |
– |
close($fref); |
248 |
– |
$self->{convertxml}->clean(); |
249 |
– |
} |
250 |
– |
else |
251 |
– |
{ |
252 |
– |
print STDERR "**** WARNING: Can not open file for writing: ${bf}.xml\n"; |
253 |
– |
} |
254 |
– |
} |
241 |
|
foreach my $ext (".xml","") |
242 |
|
{ |
243 |
|
my $bfn="$bf$ext"; |
247 |
|
{ |
248 |
|
$self->{REMOVEDBF}{$bfn}=1; |
249 |
|
delete $self->{BFCACHE}{$bfn}; |
250 |
< |
AddDir::adddir($bfcachedir); |
251 |
< |
open(BF,">${bfcachedir}/$ENV{SCRAM_BUILDFILE}");close(BF); |
250 |
> |
Utilities::AddDir::adddir($bfcachedir); |
251 |
> |
open(BF,">${cbf}");close(BF); |
252 |
|
$self->cachestatus(1); |
253 |
|
} |
254 |
|
} |
258 |
|
if ((! exists $self->{BFCACHE}{$bfn}) || |
259 |
|
($bftime != $self->{BFCACHE}{$bfn})) |
260 |
|
{ |
261 |
< |
AddDir::adddir($bfcachedir); |
262 |
< |
open(BF,">${bfcachedir}/$ENV{SCRAM_BUILDFILE}");close(BF); |
263 |
< |
$self->{ADDEDBF}{$bfn}=1; |
264 |
< |
delete $self->{BFCACHE}{"${path}/$ENV{SCRAM_BUILDFILE}"}; |
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); |
273 |
|
{ |
274 |
|
$self->{ADDEDBF}{$bfn}=1; |
275 |
|
if ($ext eq ""){$self->{nonxml}+=1;} |
276 |
< |
if (!-f "${bfcachedir}/$ENV{SCRAM_BUILDFILE}") |
276 |
> |
if (!-f "${cbf}") |
277 |
|
{ |
278 |
< |
AddDir::adddir($bfcachedir); |
279 |
< |
open(BF,">${bfcachedir}/$ENV{SCRAM_BUILDFILE}");close(BF); |
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 |
|
{ |
345 |
|
{ |
346 |
|
my $self=shift; |
347 |
|
$self->{cachereset}=shift || 0; |
355 |
– |
$self->{convertxml}=shift || 0; |
348 |
|
# Scan config dir for top-level data, then start from src: |
349 |
|
my @scandirs=($ENV{SCRAM_CONFIGDIR}, $ENV{SCRAM_SOURCEDIR}); |
350 |
|
# Loop over all directories that need scanning (normally just src and config): |
359 |
– |
if ($self->{convertxml}) |
360 |
– |
{ |
361 |
– |
eval ("use SCRAM::Doc2XML"); |
362 |
– |
if (!$@) |
363 |
– |
{ |
364 |
– |
$self->{convertxml} = SCRAM::Doc2XML->new(); |
365 |
– |
} |
366 |
– |
else |
367 |
– |
{ |
368 |
– |
print STDERR "**** WARNING: Can not convert $ENV{SCRAM_BUILDFILE} in to XML format. Missing SCRAM::Doc2XML perl module.\n"; |
369 |
– |
} |
370 |
– |
} |
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"); |
368 |
|
} |
369 |
|
} |
370 |
|
} |
371 |
+ |
delete $self->{ExtraDirCache}; |
372 |
|
if ($self->{nonxml} > 0) |
373 |
|
{ |
374 |
< |
print STDERR "**** WARNING: ",$self->{nonxml}," non-xml based $ENV{SCRAM_BUILDFILE} were read.\n"; |
374 |
> |
#print STDERR "**** WARNING: ",$self->{nonxml}," non-xml based $ENV{SCRAM_BUILDFILE} were read.\n"; |
375 |
|
} |
376 |
|
return $self; |
377 |
|
} |
602 |
|
=item C<name()> |
603 |
|
|
604 |
|
Set or return the name of the cache. Normally set |
605 |
< |
to B<DirCache.db> (and not architecture dependent). |
605 |
> |
to B<DirCache.db.gz> (and not architecture dependent). |
606 |
|
|
607 |
|
=cut |
608 |
|
|