source: main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm@ 29760

Last change on this file since 29760 was 29760, checked in by kjdon, 9 years ago

try decoding against locale rather than utf8. will this work on wondows/mac?? need to test there. locale is a special thing provided by Encoding::Locale

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 22.7 KB
Line 
1###########################################################################
2#
3# DirectoryPlugin.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# DirectoryPlugin is a plugin which recurses through directories processing
27# each file it finds - which basically means passing it down the plugin
28# pipeline
29
30package DirectoryPlugin;
31
32use extrametautil;
33use PrintInfo;
34use plugin;
35use util;
36use FileUtils;
37use metadatautil;
38
39use File::Basename;
40use strict;
41no strict 'refs';
42no strict 'subs';
43
44use Encode::Locale;
45use Encode;
46
47BEGIN {
48 @DirectoryPlugin::ISA = ('PrintInfo');
49}
50
51my $arguments =
52 [ { 'name' => "block_exp",
53 'desc' => "{BasePlugin.block_exp}",
54 'type' => "regexp",
55 'deft' => &get_default_block_exp(),
56 'reqd' => "no" },
57 # this option has been deprecated. leave it here for now so we can warn people not to use it
58 { 'name' => "use_metadata_files",
59 'desc' => "{DirectoryPlugin.use_metadata_files}",
60 'type' => "flag",
61 'reqd' => "no",
62 'hiddengli' => "yes" },
63 { 'name' => "recheck_directories",
64 'desc' => "{DirectoryPlugin.recheck_directories}",
65 'type' => "flag",
66 'reqd' => "no" } ];
67
68my $options = { 'name' => "DirectoryPlugin",
69 'desc' => "{DirectoryPlugin.desc}",
70 'abstract' => "no",
71 'inherits' => "yes",
72 'args' => $arguments };
73
74sub new {
75 my ($class) = shift (@_);
76 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
77 push(@$pluginlist, $class);
78
79 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
80 push(@{$hashArgOptLists->{"OptList"}},$options);
81
82 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
83
84 if ($self->{'info_only'}) {
85 # don't worry about any options or initialisations etc
86 return bless $self, $class;
87 }
88
89 # we have left this option in so we can warn people who are still using it
90 if ($self->{'use_metadata_files'}) {
91 die "ERROR: DirectoryPlugin -use_metadata_files option has been deprecated. Please remove the option and add MetadataXMLPlug to your plugin list instead!\n";
92 }
93
94 $self->{'num_processed'} = 0;
95 $self->{'num_not_processed'} = 0;
96 $self->{'num_blocked'} = 0;
97 $self->{'num_archives'} = 0;
98
99 $self->{'subdir_extrametakeys'} = {};
100
101 return bless $self, $class;
102}
103
104# called once, at the start of processing
105sub init {
106 my $self = shift (@_);
107 my ($verbosity, $outhandle, $failhandle) = @_;
108
109 # verbosity is passed through from the processor
110 $self->{'verbosity'} = $verbosity;
111
112 # as are the outhandle and failhandle
113 $self->{'outhandle'} = $outhandle if defined $outhandle;
114 $self->{'failhandle'} = $failhandle;
115
116}
117
118# called once, after all passes have finished
119sub deinit {
120 my ($self) = @_;
121
122}
123
124# called at the beginning of each plugin pass (import has one, building has many)
125sub begin {
126 my $self = shift (@_);
127 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
128
129 # Only lookup timestamp info for import.pl, and only if incremental is set
130 my $proc_package_name = ref $processor;
131 if ($proc_package_name !~ /buildproc$/ && $self->{'incremental'} == 1) {
132 # Get the infodbtype value for this collection from the arcinfo object
133 my $infodbtype = $processor->getoutputinfo()->{'infodbtype'};
134 $infodbtype = "gdbm" if $infodbtype eq "gdbm-txtgz"; # in archives, cannot use txtgz version
135 my $output_dir = $processor->getoutputdir();
136 my $archives_inf = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $output_dir);
137
138 if ( -e $archives_inf ) {
139 $self->{'inf_timestamp'} = -M $archives_inf;
140 }
141 }
142}
143
144sub remove_all {
145 my $self = shift (@_);
146 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
147}
148
149
150sub remove_one {
151 my $self = shift (@_);
152 my ($file, $oids, $archivedir) = @_;
153 return undef; # this will never be called for directories (will it??)
154
155}
156
157
158# called at the end of each plugin pass
159sub end {
160 my ($self) = shift (@_);
161
162}
163
164
165
166# return 1 if this class might recurse using $pluginfo
167sub is_recursive {
168 my $self = shift (@_);
169
170 return 1;
171}
172
173sub get_default_block_exp {
174 my $self = shift (@_);
175
176 return '(?i)(CVS|\.svn|Thumbs\.db|OIDcount|\.DS_Store|~)$';
177}
178
179sub check_directory_path {
180
181 my $self = shift(@_);
182 my ($dirname) = @_;
183
184 return undef unless (-d $dirname);
185
186 return 0 if ($self->{'block_exp'} ne "" && $dirname =~ /$self->{'block_exp'}/);
187
188 my $outhandle = $self->{'outhandle'};
189
190 # check to make sure we're not reading the archives or index directory
191 my $gsdlhome = quotemeta($ENV{'GSDLHOME'});
192 if ($dirname =~ m/^$gsdlhome\/.*?\/import.*?\/(archives|index)$/) {
193 print $outhandle "DirectoryPlugin: $dirname appears to be a reference to a Greenstone collection, skipping.\n";
194 return 0;
195 }
196
197 # check to see we haven't got a cyclic path...
198 if ($dirname =~ m%(/.*){,41}%) {
199 print $outhandle "DirectoryPlugin: $dirname is 40 directories deep, is this a recursive path? if not increase constant in DirectoryPlugin.pm.\n";
200 return 0;
201 }
202
203 # check to see we haven't got a cyclic path...
204 if ($dirname =~ m%.*?import/(.+?)/import/\1.*%) {
205 print $outhandle "DirectoryPlugin: $dirname appears to be in a recursive loop...\n";
206 return 0;
207 }
208
209 return 1;
210}
211
212# this may be called more than once
213sub sort_out_associated_files {
214
215 my $self = shift (@_);
216 my ($block_hash) = @_;
217 if (!scalar (keys %{$block_hash->{'shared_fileroot'}})) {
218 return;
219 }
220
221 $self->{'assocfile_info'} = {} unless defined $self->{'assocfile_info'};
222 my $metadata = $self->{'assocfile_info'};
223 foreach my $prefix (keys %{$block_hash->{'shared_fileroot'}}) {
224 my $record = $block_hash->{'shared_fileroot'}->{$prefix};
225
226 my $tie_to = $record->{'tie_to'};
227 my $exts = $record->{'exts'};
228
229 if ((defined $tie_to) && (scalar (keys %$exts) > 0)) {
230 # set up fileblocks and assocfile_tobe
231 my $base_file = "$prefix$tie_to";
232 $metadata->{$base_file} = {} unless defined $metadata->{$base_file};
233 my $base_file_metadata = $metadata->{$base_file};
234
235 $base_file_metadata->{'gsdlassocfile_tobe'} = [] unless defined $base_file_metadata->{'gsdlassocfile_tobe'};
236 my $assoc_tobe = $base_file_metadata->{'gsdlassocfile_tobe'};
237 foreach my $e (keys %$exts) {
238 # block the file
239 &util::block_filename($block_hash,"$prefix$e");
240 # set up as an associatd file
241 print STDERR " $self->{'plugin_type'}: Associating $prefix$e with $tie_to version\n";
242 my $mime_type = ""; # let system auto detect this
243 push(@$assoc_tobe,"$prefix$e:$mime_type:");
244
245 }
246 }
247 } # foreach record
248
249 $block_hash->{'shared_fileroot'} = undef;
250 $block_hash->{'shared_fileroot'} = {};
251
252}
253
254
255# do block exp OR special blocking ???
256
257sub file_is_blocked {
258 my $self = shift (@_);
259 my ($block_hash, $filename_full_path) = @_;
260
261 $filename_full_path = &util::upgrade_if_dos_filename($filename_full_path);
262
263 if (($ENV{'GSDLOS'} =~ m/^windows$/) && ($^O ne "cygwin")) {
264 # on windows, all block paths are lowercased.
265 my $lower_filename = lc ($filename_full_path);
266 if (defined $block_hash->{'file_blocks'}->{$lower_filename}) {
267 $self->{'num_blocked'} ++;
268 return 1;
269 }
270 }
271 else {
272 if (defined $block_hash->{'file_blocks'}->{$filename_full_path}) {
273 $self->{'num_blocked'} ++;
274 return 1;
275 }
276 }
277 # check Directory plugin's own block_exp
278 if ($self->{'block_exp'} ne "" && $filename_full_path =~ /$self->{'block_exp'}/) {
279 $self->{'num_blocked'} ++;
280 return 1; # blocked
281 }
282 return 0;
283}
284
285
286
287sub file_block_read {
288 my $self = shift (@_);
289 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
290
291 my $outhandle = $self->{'outhandle'};
292 my $verbosity = $self->{'verbosity'};
293
294 # Calculate the directory name and ensure it is a directory and
295 # that it is not explicitly blocked.
296 my $dirname = $file;
297 $dirname = &FileUtils::filenameConcatenate($base_dir, $file) if $base_dir =~ /\w/;
298
299 my $directory_ok = $self->check_directory_path($dirname);
300 return $directory_ok unless (defined $directory_ok && $directory_ok == 1);
301
302 print $outhandle "Global file scan checking directory: $dirname\n";
303
304 $block_hash->{'all_files'} = {} unless defined $block_hash->{'all_files'};
305 $block_hash->{'metadata_files'} = {} unless defined $block_hash->{'metadata_files'};
306
307 $block_hash->{'file_blocks'} = {} unless defined $block_hash->{'file_blocks'};
308 $block_hash->{'shared_fileroot'} = {} unless defined $block_hash->{'shared_fileroot'};
309
310 # Recur over directory contents.
311 my (@dir, $subfile);
312 #my $count = 0;
313
314 print $outhandle "DirectoryPlugin block: getting directory $dirname\n" if ($verbosity > 2);
315
316 # find all the files in the directory
317 if (!opendir (DIR, $dirname)) {
318 if ($gli) {
319 print STDERR "<ProcessingError n='$file' r='Could not read directory $dirname'>\n";
320 }
321 print $outhandle "DirectoryPlugin: WARNING - couldn't read directory $dirname\n";
322 return -1; # error in processing
323 }
324 @dir = sort readdir (DIR);
325 closedir (DIR);
326
327 for (my $i = 0; $i < scalar(@dir); $i++) {
328 my $raw_subfile = $dir[$i];
329 next if ($raw_subfile =~ m/^\.\.?$/);
330
331 my $this_file_base_dir = $base_dir;
332 my $raw_file_subfile = &FileUtils::filenameConcatenate($file, $raw_subfile);
333
334 # Recursively read each $raw_subfile
335 print $outhandle "DirectoryPlugin block recurring: ". Encode::decode("utf8", $raw_file_subfile) ."\n" if ($verbosity > 2);
336 print $outhandle "DirectoryPlugin block recurring: ". Encode::decode(locale =>$raw_file_subfile) ."\n" if ($verbosity > 2);
337
338 #$count += &plugin::file_block_read ($pluginfo, $this_file_base_dir,
339
340 &plugin::file_block_read ($pluginfo, $this_file_base_dir,
341 $raw_file_subfile,
342 $block_hash, $metadata, $gli);
343
344 }
345 $self->sort_out_associated_files($block_hash);
346 #return $count;
347 return 1;
348
349}
350
351# We don't do metadata_read
352sub metadata_read {
353 my $self = shift (@_);
354 my ($pluginfo, $base_dir, $file, $block_hash,
355 $extrametakeys, $extrametadata, $extrametafile,
356 $processor, $gli, $aux) = @_;
357
358 return undef;
359}
360
361
362# return number of files processed, undef if can't process
363# Note that $base_dir might be "" and that $file might
364# include directories
365
366# This function passes around metadata hash structures. Metadata hash
367# structures are hashes that map from a (scalar) key (the metadata element
368# name) to either a scalar metadata value or a reference to an array of
369# such values.
370
371sub read {
372 my $self = shift (@_);
373 my ($pluginfo, $base_dir, $file, $block_hash, $in_metadata, $processor, $maxdocs, $total_count, $gli) = @_;
374
375 my $outhandle = $self->{'outhandle'};
376 my $verbosity = $self->{'verbosity'};
377
378 # Calculate the directory name and ensure it is a directory and
379 # that it is not explicitly blocked.
380 my $dirname;
381 if ($file eq "") {
382 $dirname = $base_dir;
383 } else {
384 $dirname = $file;
385 $dirname = &FileUtils::filenameConcatenate($base_dir, $file) if $base_dir =~ /\w/;
386 }
387
388 my $directory_ok = $self->check_directory_path($dirname);
389 return $directory_ok unless (defined $directory_ok && $directory_ok == 1);
390
391 if (($verbosity > 2) && ((scalar keys %$in_metadata) > 0)) {
392 print $outhandle "DirectoryPlugin: metadata passed in: ",
393 join(", ", keys %$in_metadata), "\n";
394 }
395
396
397 # Recur over directory contents.
398 my (@dir, $subfile);
399
400 print $outhandle "DirectoryPlugin read: getting directory $dirname\n" if ($verbosity > 2);
401
402 # find all the files in the directory
403 if (!opendir (DIR, $dirname)) {
404 if ($gli) {
405 print STDERR "<ProcessingError n='$file' r='Could not read directory $dirname'>\n";
406 }
407 print $outhandle "DirectoryPlugin: WARNING - couldn't read directory $dirname\n";
408 return -1; # error in processing
409 }
410 @dir = sort readdir (DIR);
411 map { $_ = &unicode::raw_filename_to_url_encoded($_); print STDERR "****$_\n"; } @dir;
412 closedir (DIR);
413
414 # Re-order the files in the list so any directories ending with .all are moved to the end
415 for (my $i = scalar(@dir) - 1; $i >= 0; $i--) {
416 if (-d &FileUtils::filenameConcatenate($dirname, $dir[$i]) && $dir[$i] =~ /\.all$/) {
417 push(@dir, splice(@dir, $i, 1));
418 }
419 }
420
421 # setup the metadata structures. we do a metadata_read pass to see if there is any additional metadata, then pass it to read
422
423 my $additionalmetadata = 0; # is there extra metadata available?
424 my %extrametadata; # maps from filespec to extra metadata keys
425 my %extrametafile; # maps from filespec to the metadata.xml (or similar) file it came from
426 my @extrametakeys; # keys of %extrametadata in order read
427
428
429 my $os_dirsep = &util::get_os_dirsep();
430 my $dirsep = &util::get_dirsep();
431 my $base_dir_regexp = $base_dir;
432 $base_dir_regexp =~ s/\//$os_dirsep/g;
433
434 # Want to get relative path of local_dirname within the base_directory
435 # but with URL style slashes.
436 my $local_dirname = &util::filename_within_directory_url_format($dirname, $base_dir);
437
438 # if we are in import folder, then local_dirname will be empty
439 if ($local_dirname ne "") {
440 # look for extra metadata passed down from higher folders
441 $local_dirname .= "/"; # closing slash must be URL type slash also and not $dirsep;
442 if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) {
443 my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname};
444 foreach my $ek (@$extrakeys) {
445 my $extrakeys_re = $ek->{'re'};
446 my $extrakeys_md = $ek->{'md'};
447 my $extrakeys_mf = $ek->{'mf'};
448 &extrametautil::addmetakey(\@extrametakeys, $extrakeys_re);
449 &extrametautil::setmetadata(\%extrametadata, $extrakeys_re, $extrakeys_md);
450 &extrametautil::setmetafile(\%extrametafile, $extrakeys_re, $extrakeys_mf);
451 }
452 delete($self->{'subdir_extrametakeys'}->{$local_dirname});
453 }
454 }
455 # apply metadata pass for each of the files in the directory -- ignore
456 # maxdocs here
457 my $num_files = scalar(@dir);
458 for (my $i = 0; $i < scalar(@dir); $i++) {
459 my $subfile = $dir[$i];
460 next if ($subfile =~ m/^\.\.?$/);
461
462 my $this_file_base_dir = $base_dir;
463 my $raw_subfile = &unicode::url_encoded_to_raw_filename($subfile);
464
465 my $raw_file_subfile = &FileUtils::filenameConcatenate($file, $raw_subfile);
466 my $raw_full_filename = &FileUtils::filenameConcatenate($this_file_base_dir, $raw_file_subfile);
467
468 if ($self->file_is_blocked($block_hash,$raw_full_filename)) {
469 print STDERR "DirectoryPlugin: file $raw_full_filename was blocked for metadata_read\n" if ($verbosity > 2);
470 next;
471 }
472
473 # Recursively read each $raw_subfile
474 print $outhandle "DirectoryPlugin metadata recurring: $raw_subfile\n" if ($verbosity > 2);
475
476 &plugin::metadata_read ($pluginfo, $this_file_base_dir,
477 $raw_file_subfile,$block_hash,
478 \@extrametakeys, \%extrametadata,
479 \%extrametafile,
480 $processor, $gli);
481 $additionalmetadata = 1;
482 }
483
484 # filter out any extrametakeys that mention subdirectories and store
485 # for later use (i.e. when that sub-directory is being processed)
486 foreach my $ek (@extrametakeys) { # where each Extrametakey (which is a filename) is stored as a url-style regex
487
488 my ($subdir_re,$extrakey_dir) = &util::url_fileparse($ek);
489
490 if ($extrakey_dir ne "") {
491 # a subdir was specified
492 my $md = &extrametautil::getmetadata(\%extrametadata, $ek);
493 my $mf = &extrametautil::getmetafile(\%extrametafile, $ek);
494
495 my $subdir_extrametakeys = $self->{'subdir_extrametakeys'};
496 my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf };
497
498 # when it's looked up, it must be relative to the base dir
499 push(@{$subdir_extrametakeys->{"$local_dirname$extrakey_dir"}},$subdir_rec);
500 }
501 }
502
503 # import each of the files in the directory
504 my $count=0;
505 for (my $i = 0; $i <= scalar(@dir); $i++) {
506 # When every file in the directory has been done, pause for a moment (figuratively!)
507 # If the -recheck_directories argument hasn't been provided, stop now (default)
508 # Otherwise, re-read the contents of the directory to check for new files
509 # Any new files are added to the @dir list and are processed as normal
510 # This is necessary when documents to be indexed are specified in bibliographic DBs
511 # These files are copied/downloaded and stored in a new folder at import time
512 if ($i == $num_files) {
513 last unless $self->{'recheck_directories'};
514
515 # Re-read the files in the directory to see if there are any new files
516 last if (!opendir (DIR, $dirname));
517 my @dirnow = sort readdir (DIR);
518 map { $_ = &unicode::raw_filename_to_url_encoded($_) } @dirnow;
519 closedir (DIR);
520
521 # We're only interested if there are more files than there were before
522 last if (scalar(@dirnow) <= scalar(@dir));
523
524 # Any new files are added to the end of @dir to get processed by the loop
525 my $j;
526 foreach my $subfilenow (@dirnow) {
527 for ($j = 0; $j < $num_files; $j++) {
528 last if ($subfilenow eq $dir[$j]);
529 }
530 if ($j == $num_files) {
531 # New file
532 push(@dir, $subfilenow);
533 }
534 }
535 # When the new files have been processed, check again
536 $num_files = scalar(@dir);
537 }
538
539 my $subfile = $dir[$i];
540 last if ($maxdocs != -1 && ($count + $total_count) >= $maxdocs);
541 next if ($subfile =~ /^\.\.?$/);
542
543 my $this_file_base_dir = $base_dir;
544 my $raw_subfile = &unicode::url_encoded_to_raw_filename($subfile);
545 #my $unicode_subfile = &Encode::decode("utf8", $raw_subfile);
546 my $unicode_subfile = &Encode::decode(locale => $raw_subfile);
547
548 my $raw_file_subfile = &FileUtils::filenameConcatenate($file, $raw_subfile);
549 my $raw_full_filename
550 = &FileUtils::filenameConcatenate($this_file_base_dir,$raw_file_subfile);
551
552 if ($self->file_is_blocked($block_hash,$raw_full_filename)) {
553 print STDERR "DirectoryPlugin: file $raw_full_filename was blocked for read\n" if ($verbosity > 2);
554 next;
555 }
556 print STDERR "processing $raw_full_filename\n";
557 # Follow Windows shortcuts
558 if ($raw_subfile =~ m/(?i)\.lnk$/ && (($ENV{'GSDLOS'} =~ m/^windows$/i) && ($^O ne "cygwin"))) {
559 require Win32::Shortcut;
560 my $shortcut = new Win32::Shortcut(&FileUtils::filenameConcatenate($dirname, $raw_subfile));
561 if ($shortcut) {
562 # The file to be processed is now the target of the shortcut
563 $this_file_base_dir = "";
564 $file = "";
565 $raw_subfile = $shortcut->Path;
566 }
567 }
568
569 # check for a symlink pointing back to a leading directory
570 if (-d "$dirname/$raw_subfile" && -l "$dirname/$raw_subfile") {
571 # readlink gives a "fatal error" on systems that don't implement
572 # symlinks. This assumes the the -l test above would fail on those.
573 my $linkdest=readlink "$dirname/$raw_subfile";
574 if (!defined ($linkdest)) {
575 # system error - file not found?
576 warn "DirectoryPlugin: symlink problem - $!";
577 } else {
578 # see if link points to current or a parent directory
579 if ($linkdest =~ m@^[\./\\]+$@ ||
580 index($dirname, $linkdest) != -1) {
581 warn "DirectoryPlugin: Ignoring recursive symlink ($dirname/$raw_subfile -> $linkdest)\n";
582 next;
583 ;
584 }
585 }
586 }
587
588 print $outhandle "DirectoryPlugin: preparing metadata for $raw_subfile\n" if ($verbosity > 2);
589
590 # Make a copy of $in_metadata to pass to $raw_subfile
591 my $out_metadata = {};
592 &metadatautil::combine_metadata_structures($out_metadata, $in_metadata);
593
594 # check the assocfile_info
595 if (defined $self->{'assocfile_info'}->{$raw_full_filename}) {
596 &metadatautil::combine_metadata_structures($out_metadata, $self->{'assocfile_info'}->{$raw_full_filename});
597 }
598
599 ### $subfile by this point is url-encoded => all ASCII chars => no need to encode as UTF8
600 ###print STDERR "subfile = $subfile, raw_subfile = $raw_subfile\n";
601 ###print STDERR &unicode::debug_unicode_string("subfile = $subfile, raw_subfile = $raw_subfile\n");
602 # instead of using the subfile, we need unicode aware string
603 ###my $lookup_name = decode("utf8", $raw_subfile);
604 ####print STDERR "lookup nmae = $lookup_name\n";
605 # Next add metadata read in XML files (if it is supplied)
606 if ($additionalmetadata == 1) {
607 foreach my $filespec (@extrametakeys) {
608 ## use the url-encoded filename to do the filename comparison
609 print STDERR "comparing against filespec $filespec (";
610 print STDERR &unicode::debug_unicode_string("$filespec");
611 print STDERR ")\n";
612 if ($unicode_subfile =~ /^$filespec$/) {
613 ###if ($lookup_name =~ /^$filespec$/) {
614 print $outhandle "File \"$unicode_subfile\" matches filespec \"$filespec\"\n"
615 if ($verbosity > 2);
616 my $mdref = &extrametautil::getmetadata(\%extrametadata, $filespec);
617 my $mfref = &extrametautil::getmetafile(\%extrametafile, $filespec);
618
619 # Add the list files where the metadata came from
620 # into the metadata table so we can track this
621 # This mechanism is similar to how gsdlassocfile works
622
623 my @metafile_pair = ();
624 foreach my $l (keys %$mfref) {
625 my $f = $mfref->{$l};
626 push (@metafile_pair, "$f : $l");
627 }
628
629 $mdref->{'gsdlmetafile'} = \@metafile_pair;
630
631 &metadatautil::combine_metadata_structures($out_metadata, $mdref);
632 }
633 }
634 }
635
636 if (defined $self->{'inf_timestamp'}) {
637 # Look to see if it's a completely new file
638
639 if (!$block_hash->{'new_files'}->{$raw_full_filename}) {
640 # Not a new file, must be an existing file
641 # Let' see if it's newer than the last import.pl
642
643
644 if (! -d $raw_full_filename) {
645 if (!$block_hash->{'reindex_files'}->{$raw_full_filename}) {
646 # filename has been around for longer than inf_timestamp
647 print $outhandle "**** Skipping $unicode_subfile\n" if ($verbosity >3);
648 next;
649 }
650 else {
651 # Remove old folder in archives (might hash to something different)
652 # *** should be doing this on a Del one as well
653 # but leave folder name?? and ensure hashs to
654 # same again??
655
656 # Then let through as new doc??
657
658 # mark to doc-oids that rely on it for re-indexing
659 }
660 }
661 }
662 }
663
664 # Recursively read each $subfile
665 print $outhandle "DirectoryPlugin recurring: $unicode_subfile\n" if ($verbosity > 2);
666
667 $count += &plugin::read ($pluginfo, $this_file_base_dir,
668 $raw_file_subfile, $block_hash,
669 $out_metadata, $processor, $maxdocs, ($total_count + $count), $gli);
670 }
671
672 return $count;
673}
674
675sub compile_stats {
676 my $self = shift(@_);
677 my ($stats) = @_;
678}
679
6801;
Note: See TracBrowser for help on using the repository browser.