[537] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # RecPlug.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 |
|
---|
[2228] | 26 | # RecPlug is a plugin which recurses through directories processing
|
---|
| 27 | # each file it finds.
|
---|
[4] | 28 |
|
---|
[2228] | 29 | # RecPlug has one option: use_metadata_files. When this is set, it will
|
---|
[2813] | 30 | # check each directory for an XML file called "metadata.xml" that specifies
|
---|
| 31 | # metadata for the files (and subdirectories) in the directory.
|
---|
[2228] | 32 | #
|
---|
[2813] | 33 | # Here's an example of a metadata file that uses three FileSet structures
|
---|
[2228] | 34 | # (ignore the # characters):
|
---|
| 35 |
|
---|
[2813] | 36 | #<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
---|
[2925] | 37 | #<!DOCTYPE DirectoryMetadata SYSTEM "http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd">
|
---|
[2813] | 38 | #<DirectoryMetadata>
|
---|
| 39 | # <FileSet>
|
---|
| 40 | # <FileName>nugget.*</FileName>
|
---|
| 41 | # <Description>
|
---|
| 42 | # <Metadata name="Title">Nugget Point, The Catlins</Metadata>
|
---|
| 43 | # <Metadata name="Place" mode="accumulate">Nugget Point</Metadata>
|
---|
| 44 | # </Description>
|
---|
| 45 | # </FileSet>
|
---|
| 46 | # <FileSet>
|
---|
| 47 | # <FileName>nugget-point-1.jpg</FileName>
|
---|
| 48 | # <Description>
|
---|
| 49 | # <Metadata name="Title">Nugget Point Lighthouse, The Catlins</Metadata>
|
---|
| 50 | # <Metadata name="Subject">Lighthouse</Metadata>
|
---|
| 51 | # </Description>
|
---|
| 52 | # </FileSet>
|
---|
| 53 | # <FileSet>
|
---|
| 54 | # <FileName>kaka-point-dir</FileName>
|
---|
| 55 | # <Description>
|
---|
| 56 | # <Metadata name="Title">Kaka Point, The Catlins</Metadata>
|
---|
| 57 | # </Description>
|
---|
| 58 | # </FileSet>
|
---|
| 59 | #</DirectoryMetadata>
|
---|
[2228] | 60 |
|
---|
| 61 | # Metadata elements are read and applied to files in the order they appear
|
---|
[2813] | 62 | # in the file.
|
---|
[2228] | 63 | #
|
---|
[2813] | 64 | # The FileName element describes the subfiles in the directory that the
|
---|
| 65 | # metadata applies to as a perl regular expression (a FileSet group may
|
---|
| 66 | # contain multiple FileName elements). So, <FileName>nugget.*</FileName>
|
---|
| 67 | # indicates that the metadata records in the following Description block
|
---|
| 68 | # apply to every subfile that starts with "nugget". For these files, a
|
---|
[2228] | 69 | # Title metadata element is set, overriding any old value that the Title
|
---|
| 70 | # might have had.
|
---|
| 71 | #
|
---|
| 72 | # Occasionally, we want to have multiple metadata values applied to a
|
---|
| 73 | # document; in this case we use the "mode=accumulate" attribute of the
|
---|
[2813] | 74 | # particular Metadata element. In the second metadata element of the first
|
---|
| 75 | # FileSet above, the "Place" metadata is accumulating, and may therefore be
|
---|
| 76 | # given several values. If we wanted to override these values and use a
|
---|
| 77 | # single metadata element again, we could set the mode attribute to
|
---|
| 78 | # "override" instead. Remember: every element is assumed to be in override
|
---|
| 79 | # mode unless you specify otherwise, so if you want to accumulate metadata
|
---|
| 80 | # for some field, every occurance must have "mode=accumulate" specified.
|
---|
[2228] | 81 | #
|
---|
[2813] | 82 | # The second FileSet element above applies to a specific file, called
|
---|
| 83 | # nugget-point-1.jpg. This element overrides the Title metadata set in the
|
---|
| 84 | # first FileSet, and adds a "Subject" metadata field.
|
---|
[2228] | 85 | #
|
---|
[2813] | 86 | # The third and final FileSet sets metadata for a subdirectory rather than
|
---|
| 87 | # a file. The metadata specified (a Title) will be passed into the
|
---|
| 88 | # subdirectory and applied to every file that occurs in the subdirectory
|
---|
| 89 | # (and to every subsubdirectory and its contents, and so on) unless the
|
---|
| 90 | # metadata is explictly overridden later in the import.
|
---|
[2228] | 91 |
|
---|
| 92 |
|
---|
| 93 |
|
---|
[4] | 94 | package RecPlug;
|
---|
| 95 |
|
---|
| 96 | use BasPlug;
|
---|
| 97 | use plugin;
|
---|
[136] | 98 | use util;
|
---|
[13188] | 99 | use metadatautil;
|
---|
[4] | 100 |
|
---|
[8737] | 101 | use File::Basename;
|
---|
[10254] | 102 | use strict;
|
---|
| 103 | no strict 'refs';
|
---|
[13545] | 104 | use Encode;
|
---|
[4] | 105 |
|
---|
| 106 | BEGIN {
|
---|
[8716] | 107 | @RecPlug::ISA = ('BasPlug');
|
---|
[4] | 108 | }
|
---|
| 109 |
|
---|
[4744] | 110 | my $arguments =
|
---|
| 111 | [ { 'name' => "block_exp",
|
---|
[4873] | 112 | 'desc' => "{BasPlug.block_exp}",
|
---|
[6408] | 113 | 'type' => "regexp",
|
---|
[4744] | 114 | 'deft' => &get_default_block_exp(),
|
---|
| 115 | 'reqd' => "no" },
|
---|
[13417] | 116 | # this option has been deprecated. leave it here for now so we can warn people not to use it
|
---|
[4744] | 117 | { 'name' => "use_metadata_files",
|
---|
[4873] | 118 | 'desc' => "{RecPlug.use_metadata_files}",
|
---|
[4744] | 119 | 'type' => "flag",
|
---|
[13188] | 120 | 'reqd' => "no",
|
---|
| 121 | 'hiddengli' => "yes" },
|
---|
[7686] | 122 | { 'name' => "recheck_directories",
|
---|
| 123 | 'desc' => "{RecPlug.recheck_directories}",
|
---|
| 124 | 'type' => "flag",
|
---|
[4744] | 125 | 'reqd' => "no" } ];
|
---|
[13188] | 126 |
|
---|
[3540] | 127 | my $options = { 'name' => "RecPlug",
|
---|
[5680] | 128 | 'desc' => "{RecPlug.desc}",
|
---|
[6408] | 129 | 'abstract' => "no",
|
---|
[4744] | 130 | 'inherits' => "yes",
|
---|
| 131 | 'args' => $arguments };
|
---|
[3540] | 132 |
|
---|
[4] | 133 | sub new {
|
---|
[10218] | 134 | my ($class) = shift (@_);
|
---|
| 135 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 136 | push(@$pluginlist, $class);
|
---|
[3540] | 137 |
|
---|
[10218] | 138 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
| 139 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
| 140 |
|
---|
[13188] | 141 | my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
|
---|
| 142 |
|
---|
| 143 | if ($self->{'info_only'}) {
|
---|
| 144 | # don't worry about any options or initialisations etc
|
---|
| 145 | return bless $self, $class;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | # we have left this option in so we can warn people who are still using it
|
---|
[2813] | 149 | if ($self->{'use_metadata_files'}) {
|
---|
[13188] | 150 | die "ERROR: RecPlug -use_metadata_files option has been deprecated. Please remove the option and add MetadataXMLPlug to your plugin list instead!\n";
|
---|
[2813] | 151 | }
|
---|
[13188] | 152 |
|
---|
[8737] | 153 | $self->{'subdir_extrametakeys'} = {};
|
---|
| 154 |
|
---|
[4] | 155 | return bless $self, $class;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[10156] | 158 | sub begin {
|
---|
| 159 | my $self = shift (@_);
|
---|
| 160 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 161 |
|
---|
| 162 | my $proc_package_name = ref $processor;
|
---|
| 163 |
|
---|
[12969] | 164 | if ($proc_package_name !~ /buildproc$/ && $self->{'incremental'} == 1) {
|
---|
[10156] | 165 |
|
---|
[12969] | 166 | # Only lookup timestamp info for import.pl, and only if incremental is set
|
---|
[10156] | 167 |
|
---|
| 168 | my $output_dir = $processor->getoutputdir();
|
---|
| 169 | my $archives_inf = &util::filename_cat($output_dir,"archives.inf");
|
---|
| 170 |
|
---|
| 171 | if ( -e $archives_inf ) {
|
---|
| 172 | $self->{'inf_timestamp'} = -M $archives_inf;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | $self->SUPER::begin($pluginfo, $base_dir, $processor, $maxdocs);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
[4] | 180 | # return 1 if this class might recurse using $pluginfo
|
---|
| 181 | sub is_recursive {
|
---|
| 182 | my $self = shift (@_);
|
---|
[2813] | 183 |
|
---|
[4] | 184 | return 1;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[2228] | 187 | sub get_default_block_exp {
|
---|
| 188 | my $self = shift (@_);
|
---|
[2813] | 189 |
|
---|
[14180] | 190 | return '(CVS|\.svn)';
|
---|
[2228] | 191 | }
|
---|
| 192 |
|
---|
[317] | 193 | # return number of files processed, undef if can't process
|
---|
[4] | 194 | # Note that $base_dir might be "" and that $file might
|
---|
| 195 | # include directories
|
---|
[2228] | 196 |
|
---|
| 197 | # This function passes around metadata hash structures. Metadata hash
|
---|
| 198 | # structures are hashes that map from a (scalar) key (the metadata element
|
---|
| 199 | # name) to either a scalar metadata value or a reference to an array of
|
---|
| 200 | # such values.
|
---|
| 201 |
|
---|
[4] | 202 | sub read {
|
---|
| 203 | my $self = shift (@_);
|
---|
[9853] | 204 | my ($pluginfo, $base_dir, $file, $in_metadata, $processor, $maxdocs, $total_count, $gli) = @_;
|
---|
[2813] | 205 |
|
---|
[1424] | 206 | my $outhandle = $self->{'outhandle'};
|
---|
[2228] | 207 | my $verbosity = $self->{'verbosity'};
|
---|
| 208 | my $read_metadata_files = $self->{'use_metadata_files'};
|
---|
[7932] | 209 |
|
---|
[2228] | 210 | # Calculate the directory name and ensure it is a directory and
|
---|
| 211 | # that it is not explicitly blocked.
|
---|
[2795] | 212 | my $dirname = $file;
|
---|
| 213 | $dirname = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
|
---|
[2228] | 214 | return undef unless (-d $dirname);
|
---|
| 215 | return 0 if ($self->{'block_exp'} ne "" && $dirname =~ /$self->{'block_exp'}/);
|
---|
[7932] | 216 |
|
---|
[2228] | 217 | # check to make sure we're not reading the archives or index directory
|
---|
| 218 | my $gsdlhome = quotemeta($ENV{'GSDLHOME'});
|
---|
[2813] | 219 | if ($dirname =~ m/^$gsdlhome\/.*?\/import.*?\/(archives|index)$/) {
|
---|
| 220 | print $outhandle "RecPlug: $dirname appears to be a reference to a Greenstone collection, skipping.\n";
|
---|
[2228] | 221 | return 0;
|
---|
[1755] | 222 | }
|
---|
[2813] | 223 |
|
---|
[1755] | 224 | # check to see we haven't got a cyclic path...
|
---|
| 225 | if ($dirname =~ m%(/.*){,41}%) {
|
---|
| 226 | print $outhandle "RecPlug: $dirname is 40 directories deep, is this a recursive path? if not increase constant in RecPlug.pm.\n";
|
---|
[2228] | 227 | return 0;
|
---|
[1755] | 228 | }
|
---|
[2813] | 229 |
|
---|
[1755] | 230 | # check to see we haven't got a cyclic path...
|
---|
| 231 | if ($dirname =~ m%.*?import/(.+?)/import/\1.*%) {
|
---|
[2228] | 232 | print $outhandle "RecPlug: $dirname appears to be in a recursive loop...\n";
|
---|
| 233 | return 0;
|
---|
[1755] | 234 | }
|
---|
[2813] | 235 |
|
---|
[2228] | 236 | if (($verbosity > 2) && ((scalar keys %$in_metadata) > 0)) {
|
---|
| 237 | print $outhandle "RecPlug: metadata passed in: ",
|
---|
[2813] | 238 | join(", ", keys %$in_metadata), "\n";
|
---|
[2228] | 239 | }
|
---|
[2813] | 240 |
|
---|
[2228] | 241 | # Recur over directory contents.
|
---|
| 242 | my (@dir, $subfile);
|
---|
| 243 | my $count = 0;
|
---|
[6332] | 244 |
|
---|
[2228] | 245 | print $outhandle "RecPlug: getting directory $dirname\n" if ($verbosity);
|
---|
[2813] | 246 |
|
---|
[2228] | 247 | # find all the files in the directory
|
---|
| 248 | if (!opendir (DIR, $dirname)) {
|
---|
[9584] | 249 | if ($gli) {
|
---|
| 250 | print STDERR "<ProcessingError n='$file' r='Could not read directory $dirname'>\n";
|
---|
| 251 | }
|
---|
[9703] | 252 | print $outhandle "RecPlug: WARNING - couldn't read directory $dirname\n";
|
---|
[7362] | 253 | return -1; # error in processing
|
---|
[2228] | 254 | }
|
---|
| 255 | @dir = readdir (DIR);
|
---|
| 256 | closedir (DIR);
|
---|
[7686] | 257 |
|
---|
| 258 | # Re-order the files in the list so any directories ending with .all are moved to the end
|
---|
[8716] | 259 | for (my $i = scalar(@dir) - 1; $i >= 0; $i--) {
|
---|
[7688] | 260 | if (-d &util::filename_cat($dirname, $dir[$i]) && $dir[$i] =~ /\.all$/) {
|
---|
[7686] | 261 | push(@dir, splice(@dir, $i, 1));
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[13188] | 265 | # setup the metadata structures. we do a metadata_read pass to see if there is any additional metadata, then pass it to read
|
---|
| 266 |
|
---|
[2228] | 267 | my $additionalmetadata = 0; # is there extra metadata available?
|
---|
| 268 | my %extrametadata; # maps from filespec to extra metadata keys
|
---|
| 269 | my @extrametakeys; # keys of %extrametadata in order read
|
---|
[8512] | 270 |
|
---|
[11919] | 271 | my $os_dirsep = &util::get_os_dirsep();
|
---|
[8737] | 272 | my $dirsep = &util::get_dirsep();
|
---|
[11919] | 273 | my $base_dir_regexp = $base_dir;
|
---|
| 274 | $base_dir_regexp =~ s/\//$os_dirsep/g;
|
---|
[8737] | 275 | my $local_dirname = $dirname;
|
---|
[11919] | 276 | $local_dirname =~ s/^$base_dir_regexp($os_dirsep)//;
|
---|
[8737] | 277 | $local_dirname .= $dirsep;
|
---|
| 278 |
|
---|
| 279 | if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) {
|
---|
| 280 | my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname};
|
---|
| 281 | foreach my $ek (@$extrakeys) {
|
---|
| 282 | my $extrakeys_re = $ek->{'re'};
|
---|
| 283 | my $extrakeys_md = $ek->{'md'};
|
---|
| 284 | push(@extrametakeys,$extrakeys_re);
|
---|
| 285 | $extrametadata{$extrakeys_re} = $extrakeys_md;
|
---|
| 286 | }
|
---|
| 287 | delete($self->{'subdir_extrametakeys'}->{$local_dirname});
|
---|
| 288 | }
|
---|
[8512] | 289 |
|
---|
[9145] | 290 | # apply metadata pass for each of the files in the directory
|
---|
[2228] | 291 | my $out_metadata;
|
---|
[7686] | 292 | my $num_files = scalar(@dir);
|
---|
[8512] | 293 | for (my $i = 0; $i < scalar(@dir); $i++) {
|
---|
| 294 | my $subfile = $dir[$i];
|
---|
| 295 | my $this_file_base_dir = $base_dir;
|
---|
| 296 | last if ($maxdocs != -1 && $count >= $maxdocs);
|
---|
[9145] | 297 | next if ($subfile =~ m/^\.\.?$/);
|
---|
[8512] | 298 |
|
---|
| 299 | # Recursively read each $subfile
|
---|
| 300 | print $outhandle "RecPlug metadata recurring: $subfile\n" if ($verbosity > 2);
|
---|
| 301 |
|
---|
| 302 | $count += &plugin::metadata_read ($pluginfo, $this_file_base_dir,
|
---|
| 303 | &util::filename_cat($file, $subfile),
|
---|
| 304 | $out_metadata, \@extrametakeys, \%extrametadata,
|
---|
| 305 | $processor, $maxdocs, $gli);
|
---|
| 306 | $additionalmetadata = 1;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[8737] | 309 | # filter out any extrametakeys that mention subdirectories and store
|
---|
| 310 | # for later use (i.e. when that sub-directory is being processed)
|
---|
| 311 |
|
---|
| 312 | foreach my $ek (@extrametakeys) {
|
---|
| 313 | my ($subdir_re,$extrakey_dir) = &File::Basename::fileparse($ek);
|
---|
| 314 | $extrakey_dir =~ s/\\\./\./g; # remove RE syntax
|
---|
| 315 |
|
---|
[9122] | 316 | my $dirsep_re = &util::get_re_dirsep();
|
---|
[15005] | 317 |
|
---|
| 318 | my $ek_non_re = $ek;
|
---|
| 319 | $ek_non_re =~ s/\\\./\./g; # remove RE syntax
|
---|
| 320 |
|
---|
| 321 | if ($ek_non_re =~ m/$dirsep_re/) { # specifies at least one directory
|
---|
[8737] | 322 | my $md = $extrametadata{$ek};
|
---|
| 323 |
|
---|
| 324 | my $subdir_extrametakeys = $self->{'subdir_extrametakeys'};
|
---|
| 325 |
|
---|
| 326 | my $subdir_rec = { 're' => $subdir_re, 'md' => $md };
|
---|
[15005] | 327 |
|
---|
[8737] | 328 | push(@{$subdir_extrametakeys->{$extrakey_dir}},$subdir_rec);
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
[8512] | 331 |
|
---|
| 332 | # import each of the files in the directory
|
---|
| 333 | $count=0;
|
---|
[7686] | 334 | for (my $i = 0; $i <= scalar(@dir); $i++) {
|
---|
| 335 | # When every file in the directory has been done, pause for a moment (figuratively!)
|
---|
| 336 | # If the -recheck_directories argument hasn't been provided, stop now (default)
|
---|
| 337 | # Otherwise, re-read the contents of the directory to check for new files
|
---|
| 338 | # Any new files are added to the @dir list and are processed as normal
|
---|
| 339 | # This is necessary when documents to be indexed are specified in bibliographic DBs
|
---|
| 340 | # These files are copied/downloaded and stored in a new folder at import time
|
---|
| 341 | if ($i == $num_files) {
|
---|
| 342 | last unless $self->{'recheck_directories'};
|
---|
| 343 |
|
---|
| 344 | # Re-read the files in the directory to see if there are any new files
|
---|
| 345 | last if (!opendir (DIR, $dirname));
|
---|
| 346 | my @dirnow = readdir (DIR);
|
---|
| 347 | closedir (DIR);
|
---|
| 348 |
|
---|
| 349 | # We're only interested if there are more files than there were before
|
---|
| 350 | last if (scalar(@dirnow) <= scalar(@dir));
|
---|
| 351 |
|
---|
| 352 | # Any new files are added to the end of @dir to get processed by the loop
|
---|
[8716] | 353 | my $j;
|
---|
[7686] | 354 | foreach my $subfilenow (@dirnow) {
|
---|
| 355 | for ($j = 0; $j < $num_files; $j++) {
|
---|
| 356 | last if ($subfilenow eq $dir[$j]);
|
---|
| 357 | }
|
---|
| 358 | if ($j == $num_files) {
|
---|
| 359 | # New file
|
---|
| 360 | push(@dir, $subfilenow);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 | # When the new files have been processed, check again
|
---|
| 364 | $num_files = scalar(@dir);
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | my $subfile = $dir[$i];
|
---|
[7932] | 368 | my $this_file_base_dir = $base_dir;
|
---|
[9853] | 369 | last if ($maxdocs != -1 && ($count + $total_count) >= $maxdocs);
|
---|
[2228] | 370 | next if ($subfile =~ /^\.\.?$/);
|
---|
[3108] | 371 |
|
---|
[7932] | 372 | # Follow Windows shortcuts
|
---|
| 373 | if ($subfile =~ /(?i)\.lnk$/ && $ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
| 374 | require Win32::Shortcut;
|
---|
| 375 | my $shortcut = new Win32::Shortcut(&util::filename_cat($dirname, $subfile));
|
---|
| 376 | if ($shortcut) {
|
---|
| 377 | # The file to be processed is now the target of the shortcut
|
---|
| 378 | $this_file_base_dir = "";
|
---|
| 379 | $file = "";
|
---|
| 380 | $subfile = $shortcut->Path;
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[3108] | 384 | # check for a symlink pointing back to a leading directory
|
---|
| 385 | if (-d "$dirname/$subfile" && -l "$dirname/$subfile") {
|
---|
| 386 | # readlink gives a "fatal error" on systems that don't implement
|
---|
| 387 | # symlinks. This assumes the the -l test above would fail on those.
|
---|
| 388 | my $linkdest=readlink "$dirname/$subfile";
|
---|
| 389 | if (!defined ($linkdest)) {
|
---|
| 390 | # system error - file not found?
|
---|
| 391 | warn "RecPlug: symlink problem - $!";
|
---|
| 392 | } else {
|
---|
| 393 | # see if link points to current or a parent directory
|
---|
| 394 | if ($linkdest =~ m@^[\./\\]+$@ ||
|
---|
| 395 | index($dirname, $linkdest) != -1) {
|
---|
| 396 | warn "RecPlug: Ignoring recursive symlink ($dirname/$subfile -> $linkdest)\n";
|
---|
| 397 | next;
|
---|
| 398 | ;
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 |
|
---|
[2813] | 403 | print $outhandle "RecPlug: preparing metadata for $subfile\n" if ($verbosity > 2);
|
---|
[317] | 404 |
|
---|
[2228] | 405 | # Make a copy of $in_metadata to pass to $subfile
|
---|
| 406 | $out_metadata = {};
|
---|
[13188] | 407 | &metadatautil::combine_metadata_structures($out_metadata, $in_metadata);
|
---|
[317] | 408 |
|
---|
[13545] | 409 | ## encode the filename as perl5 doesn't handle unicode filenames
|
---|
| 410 | my $tmpfile = Encode::encode_utf8($subfile);
|
---|
| 411 |
|
---|
[2228] | 412 | # Next add metadata read in XML files (if it is supplied)
|
---|
| 413 | if ($additionalmetadata == 1) {
|
---|
[10218] | 414 |
|
---|
[2228] | 415 | my ($filespec, $mdref);
|
---|
| 416 | foreach $filespec (@extrametakeys) {
|
---|
[13545] | 417 | ## use the utf8 encoded filename to do the filename comparison
|
---|
| 418 | if ($tmpfile =~ /^$filespec$/) {
|
---|
[2228] | 419 | print $outhandle "File \"$subfile\" matches filespec \"$filespec\"\n"
|
---|
| 420 | if ($verbosity > 2);
|
---|
| 421 | $mdref = $extrametadata{$filespec};
|
---|
[13188] | 422 | &metadatautil::combine_metadata_structures($out_metadata, $mdref);
|
---|
[2228] | 423 | }
|
---|
[4] | 424 | }
|
---|
| 425 | }
|
---|
[10156] | 426 |
|
---|
| 427 |
|
---|
| 428 | my $file_subfile = &util::filename_cat($file, $subfile);
|
---|
| 429 | my $filename_subfile
|
---|
| 430 | = &util::filename_cat($this_file_base_dir,$file_subfile);
|
---|
| 431 | if (defined $self->{'inf_timestamp'}) {
|
---|
| 432 | my $inf_timestamp = $self->{'inf_timestamp'};
|
---|
| 433 |
|
---|
| 434 | if (! -d $filename_subfile) {
|
---|
| 435 | my $filename_timestamp = -M $filename_subfile;
|
---|
| 436 | if ($filename_timestamp > $inf_timestamp) {
|
---|
| 437 | # filename has been around for longer than inf
|
---|
| 438 | ##### print $outhandle "**** Skipping $subfile\n";
|
---|
| 439 | next;
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[2228] | 444 | # Recursively read each $subfile
|
---|
| 445 | print $outhandle "RecPlug recurring: $subfile\n" if ($verbosity > 2);
|
---|
[8512] | 446 |
|
---|
| 447 | $count += &plugin::read ($pluginfo, $this_file_base_dir,
|
---|
[10156] | 448 | $file_subfile,
|
---|
[9853] | 449 | $out_metadata, $processor, $maxdocs, ($total_count + $count), $gli);
|
---|
[4] | 450 | }
|
---|
[7686] | 451 |
|
---|
[8512] | 452 | return $count;
|
---|
[2228] | 453 | }
|
---|
[4] | 454 |
|
---|
| 455 | 1;
|
---|