root/gs2-extensions/parallel-building/trunk/src/perllib/inexport.pm @ 25401

Revision 25401, 41.6 KB (checked in by jmt12, 7 years ago)

Extend the code that 'pre-started' the GDBMServer to pre-start any infodbtype ending with *server (to support the new TDBServer)

Line 
1###########################################################################
2#
3# inexport.pm -- useful class to support import.pl and export.pl
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
26package inexport;
27
28use strict;
29
30no strict 'refs'; # allow filehandles to be variables and vice versa
31no strict 'subs'; # allow barewords (eg STDERR) as function arguments
32
33use arcinfo;
34use colcfg;
35use dbutil;
36use doc;
37use plugin;
38use plugout;
39use manifest;
40use inexport;
41use util;
42use scriptutil;
43use FileHandle;
44use gsprintf 'gsprintf';
45use printusage;
46use parse2;
47
48use File::Basename;
49
50sub new
51{
52    my $class = shift (@_);
53    my ($mode,$argv,$options,$opt_listall_options) = @_;
54
55    my $self = { 'xml' => 0, 'mode' => $mode };
56
57    # general options available to all plugins
58    my $arguments = $options->{'args'};
59    my $intArgLeftinAfterParsing = parse2::parse($argv,$arguments,$self,"allow_extra_options");
60    # Parse returns -1 if something has gone wrong
61    if ($intArgLeftinAfterParsing == -1)
62    {
63    &PrintUsage::print_txt_usage($options, "{import.params}");
64    die "\n";
65    }
66   
67    my $language = $self->{'language'};
68    # If $language has been specified, load the appropriate resource bundle
69    # (Otherwise, the default resource bundle will be loaded automatically)
70    if ($language && $language =~ /\S/) {
71    &gsprintf::load_language_specific_resource_bundle($language);
72    }
73
74    if ($self->{'listall'}) {
75    if ($self->{'xml'}) {
76        &PrintUsage::print_xml_usage($opt_listall_options);
77    }
78    else
79    {
80        &PrintUsage::print_txt_usage($opt_listall_options,"{export.params}");
81    }
82    die "\n";
83    }
84
85
86    if ($self->{'xml'}) {
87        &PrintUsage::print_xml_usage($options);
88    print "\n";
89    return bless $self, $class;
90    }
91
92    if ($self->{'gli'}) { # the gli wants strings to be in UTF-8
93    &gsprintf::output_strings_in_UTF8;
94    }
95   
96    # now check that we had exactly one leftover arg, which should be
97    # the collection name. We don't want to do this earlier, cos
98    # -xml arg doesn't need a collection name
99    # Or if the user specified -h, then we output the usage also
100
101    if ($intArgLeftinAfterParsing != 1 || (@$argv && $argv->[0] =~ /^\-+h/))
102    {
103    &PrintUsage::print_txt_usage($options, "{import.params}");
104    die "\n";
105    }
106
107    $self->{'close_out'} = 0;
108    my $out = $self->{'out'};
109    if ($out !~ /^(STDERR|STDOUT)$/i) {
110    open (OUT, ">$out") ||
111        (&gsprintf(STDERR, "{common.cannot_open_output_file}: $!\n", $out) && die);
112    $out = 'inexport::OUT';
113    $self->{'close_out'} = 1;
114    }
115    $out->autoflush(1);
116    $self->{'out'} = $out;
117
118    # @ARGV should be only one item, the name of the collection
119    $self->{'collection'} = shift @$argv;
120
121    if ((defined $self->{'jobs'}) && ($self->{'jobs'}>1)) {
122    require ParallelInexport;
123    }
124
125    return bless $self, $class;
126}
127
128# Simplified version of the contstructor for use with CGI scripts
129sub newCGI
130{
131    my $class = shift (@_);
132    my ($mode,$collect,$gsdl_cgi,$opt_site) = @_;
133
134    my $self = { 'xml' => 0, 'mode' => $mode };
135
136    $self->{'out'} = STDERR;
137   
138    if (defined $gsdl_cgi) {
139        $self->{'site'} = $opt_site;
140        my $collect_dir = $gsdl_cgi->get_collection_dir($opt_site);
141        $self->{'collectdir'} = $collect_dir;
142    }
143    else { 
144        $self->{'site'} = "";
145        $self->{'collectdir'} = &util::filename_cat($ENV{'GSDLHOME'},"collect");
146    }
147    $self->{'faillog'} = "";
148   
149    $self->{'collection'} = $collect;
150
151    return bless $self, $class;
152}
153sub get_collection
154{
155    my $self = shift @_;
156   
157    return $self->{'collection'};
158}
159
160
161sub read_collection_cfg
162{
163    my $self = shift @_;
164    my ($collection,$options) = @_;
165
166    my $collectdir = $self->{'collectdir'};
167    my $site       = $self->{'site'};
168    my $out        = $self->{'out'};
169     
170    if (($collection = &colcfg::use_collection($site, $collection, $collectdir)) eq "") {
171    &PrintUsage::print_txt_usage($options, "{import.params}");
172    die "\n";
173    }
174
175    # add collection's perllib dir  into include path in
176    # case we have collection specific modules
177    my $collection_perllib_path = $ENV{'GSDLCOLLECTDIR'} . '/perllib';
178    my $inc_paths = join(':', @INC);
179    if ($inc_paths !~ /$collection_perllib_path/)
180    {
181      unshift (@INC, $collection_perllib_path); # [jmt12]
182    }
183
184    # check that we can open the faillog
185    my $faillog = $self->{'faillog'};
186    if ($faillog eq "") {
187    $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
188    }
189    open (FAILLOG, ">$faillog") ||
190    (&gsprintf(STDERR, "{import.cannot_open_fail_log}\n", $faillog) && die);
191
192   
193    my $faillogname = $faillog;
194    $faillog = 'inexport::FAILLOG';
195    $faillog->autoflush(1);
196    $self->{'faillog'} = $faillog;
197    $self->{'faillogname'} = $faillogname;
198
199    # Read in the collection configuration file.
200    my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
201    my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
202
203    return ($config_filename,$collectcfg);
204}
205
206sub set_collection_options
207{
208    my $self = shift @_;
209    my ($collectcfg) = @_;
210
211    my $inexport_mode = $self->{'mode'};
212
213    my $verbosity  = $self->{'verbosity'};
214    my $debug      = $self->{'debug'};
215    my $importdir  = $self->{'importdir'};
216    my $archivedir = $self->{'archivedir'} || $self->{'exportdir'} || "";
217    my $out        = $self->{'out'};
218
219    # If the infodbtype value wasn't defined in the collect.cfg file, use the default
220    if (!defined($collectcfg->{'infodbtype'}))
221    {
222      $collectcfg->{'infodbtype'} = &dbutil::get_default_infodb_type();
223    }
224    if ($collectcfg->{'infodbtype'} eq "gdbm-txtgz") {
225    # we can't use the text version for archives dbs.
226    $collectcfg->{'infodbtype'} = "gdbm";
227    }
228    if (defined $collectcfg->{'importdir'} && $importdir eq "") {
229    $importdir = $collectcfg->{'importdir'};
230    }
231    if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
232    $archivedir = $collectcfg->{'archivedir'};
233    }
234    # fill in the default import and archives directories if none
235    # were supplied, turn all \ into / and remove trailing /
236    $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
237    $importdir =~ s/[\\\/]+/\//g;
238    $importdir =~ s/\/$//;
239    if (!-e $importdir) {
240    &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
241    die "\n";
242    }
243    $self->{'importdir'} = $importdir;
244
245    if ($archivedir eq "") {
246    if ($inexport_mode eq "import") {
247        $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
248    }
249    elsif ($inexport_mode eq "export") {
250        $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export");
251    }
252    else {
253        print STDERR "Warning: Unrecognized import/export mode '$inexport_mode'\n";
254        print STDERR "         Defaulting to 'archives' for file output\n";
255        $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
256    }
257    }
258
259    $archivedir =~ s/[\\\/]+/\//g;
260    $archivedir =~ s/\/$//;
261    $self->{'archivedir'} = $archivedir;
262
263    if ($verbosity !~ /\d+/) {
264    if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
265        $verbosity = $collectcfg->{'verbosity'};
266    } else {
267        $verbosity = 2; # the default
268    }
269    }
270    $self->{'verbosity'} = $verbosity;
271
272    if (defined $collectcfg->{'manifest'} && $self->{'manifest'} eq "") {
273    $self->{'manifest'} = $collectcfg->{'manifest'};
274    }
275
276    if (defined $collectcfg->{'gzip'} && !$self->{'gzip'}) {
277    if ($collectcfg->{'gzip'} =~ /^true$/i) {
278        $self->{'gzip'} = 1;
279    }
280    }
281
282    if ($self->{'maxdocs'} !~ /\-?\d+/) {
283    if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
284        $self->{'maxdocs'} = $collectcfg->{'maxdocs'};
285    } else {
286        $self->{'maxdocs'} = -1; # the default
287    }
288    }
289
290    if ((defined $self->{'groupsize'}) && ($self->{'groupsize'} == 1)) {
291    if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
292        $self->{'groupsize'} = $collectcfg->{'groupsize'};
293    }
294    }
295
296    if (!defined $self->{'OIDtype'}
297    || ($self->{'OIDtype'} !~ /^(hash|incremental|assigned|dirname)$/ )) {
298    if (defined $collectcfg->{'OIDtype'}
299        && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
300        $self->{'OIDtype'} = $collectcfg->{'OIDtype'};
301    } else {
302        $self->{'OIDtype'} = "hash"; # the default
303    }
304    }
305
306    if ((!defined $self->{'OIDmetadata'}) || ($self->{'OIDmetadata'} eq "")) {
307    if (defined $collectcfg->{'OIDmetadata'}) {
308        $self->{'OIDmetadata'} = $collectcfg->{'OIDmetadata'};
309    } else {
310        $self->{'OIDmetadata'} = "dc.Identifier"; # the default
311    }
312    }
313
314    my $sortmeta = $self->{'sortmeta'};
315    if (defined $collectcfg->{'sortmeta'} && (!defined $sortmeta || $sortmeta eq "")) {
316    $sortmeta = $collectcfg->{'sortmeta'};
317    }
318    # sortmeta cannot be used with group size
319    $sortmeta = undef unless defined $sortmeta && $sortmeta =~ /\S/;
320    if (defined $sortmeta && $self->{'groupsize'} > 1) {
321    &gsprintf($out, "{import.cannot_sort}\n\n");
322    $sortmeta = undef;
323    }
324    $self->{'sortmeta'} = $sortmeta;
325
326    if (defined $collectcfg->{'removeprefix'} && $self->{'removeprefix'} eq "") {
327    $self->{'removeprefix'} = $collectcfg->{'removeprefix'};
328    }
329   
330    if (defined $collectcfg->{'removesuffix'} && $self->{'removesuffix'} eq "") {
331    $self->{'removesuffix'} = $collectcfg->{'removesuffix'};
332    }
333    if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
334    $self->{'debug'} = 1;
335    }
336    if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
337    $self->{'gli'} = 1;
338    }
339    $self->{'gli'} = 0 unless defined $self->{'gli'};
340       
341    # check keepold and removeold
342    my $checkdir = ($inexport_mode eq "import") ? "archives" : "export";
343
344    my ($removeold, $keepold, $incremental, $incremental_mode)
345    = &scriptutil::check_removeold_and_keepold($self->{'removeold'}, $self->{'keepold'},
346                           $self->{'incremental'}, $checkdir,
347                           $collectcfg);
348
349    $self->{'removeold'}        = $removeold;
350    $self->{'keepold'}          = $keepold;
351    $self->{'incremental'}      = $incremental;
352    $self->{'incremental_mode'} = $incremental_mode;
353
354    # Since this wasted my morning, let's at least warn a user that manifest
355    # files now *only* work if keepold is set. [jmt12]
356    if ($self->{'manifest'} && !$self->{'keepold'})
357    {
358      print STDERR "Warning: -manifest flag should not be specified without also setting -keepold or -incremental. Ignoring.\n";
359    }
360}
361
362sub process_files
363{
364    my $self = shift @_;
365    my ($config_filename,$collectcfg) = @_;
366
367    my $inexport_mode = $self->{'mode'};
368
369    my $verbosity   = $self->{'verbosity'};
370    my $debug       = $self->{'debug'};
371
372    my $importdir   = $self->{'importdir'};
373    my $archivedir = $self->{'archivedir'} || $self->{'exportdir'};
374
375    my $incremental = $self->{'incremental'};
376    my $incremental_mode = $self->{'incremental_mode'};
377
378    my $removeold   = $self->{'removeold'};
379    my $keepold     = $self->{'keepold'};
380
381    my $saveas      = $self->{'saveas'};
382    my $OIDtype     = $self->{'OIDtype'};
383    my $OIDmetadata = $self->{'OIDmetadata'};
384
385    my $out         = $self->{'out'};
386    my $faillog     = $self->{'faillog'};
387
388    my $maxdocs     = $self->{'maxdocs'};
389    my $gzip        = $self->{'gzip'};
390    my $groupsize   = $self->{'groupsize'};
391    my $sortmeta    = $self->{'sortmeta'};
392
393    my $removeprefix = $self->{'removeprefix'};
394    my $removesuffix = $self->{'removesuffix'};
395
396    my $gli          = $self->{'gli'};
397
398    my $jobs         = $self->{'jobs'};
399    my $epoch        = $self->{'epoch'};
400
401    # related to export
402    my $xsltfile         = $self->{'xsltfile'};
403    my $group_marc       = $self->{'group_marc'};
404    my $mapping_file     = $self->{'mapping_file'};
405    my $xslt_mets        = $self->{'xslt_mets'};
406    my $xslt_txt         = $self->{'xslt_txt'};
407    my $fedora_namespace = $self->{'fedora_namespace'};
408    my $metadata_prefix  = $self->{'metadata_prefix'};
409
410    if ($inexport_mode eq "import") {
411    print STDERR "<Import>\n" if $gli;
412    }
413    else {
414    print STDERR "<export>\n" if $gli;
415    }
416
417    my $manifest_lookup = new manifest($collectcfg->{'infodbtype'},$archivedir);
418    if ($self->{'manifest'} ne "") {
419    my $manifest_filename = $self->{'manifest'};
420
421    if (!&util::filename_is_absolute($manifest_filename)) {
422        $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
423    }
424
425    $self->{'manifest'} =~ s/[\\\/]+/\//g;
426    $self->{'manifest'} =~ s/\/$//;
427
428    $manifest_lookup->parse($manifest_filename);
429    }
430
431    my $manifest = $self->{'manifest'};
432
433    # load all the plugins
434    my $plugins = [];
435    if (defined $collectcfg->{'plugin'}) {
436    $plugins = $collectcfg->{'plugin'};
437    }
438
439    my $plugin_incr_mode = $incremental_mode;
440    if ($manifest ne "") {
441    # if we have a manifest file, then we pretend we are fully incremental for plugins
442    $plugin_incr_mode = "all";
443    }
444    #some global options for the plugins
445    my @global_opts = ();
446
447    my $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts, $plugin_incr_mode);
448    if (scalar(@$pluginfo) == 0) {
449    &gsprintf($out, "{import.no_plugins_loaded}\n");
450    die "\n";
451    }
452
453    # remove the old contents of the archives directory (and tmp
454    # directory) if needed
455
456    if ($removeold) {
457    if (-e $archivedir) {
458        &gsprintf($out, "{import.removing_archives}\n");
459        &util::rm_r ($archivedir);
460    }
461    my $tmpdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "tmp");
462    $tmpdir =~ s/[\\\/]+/\//g;
463    $tmpdir =~ s/\/$//;
464    if (-e $tmpdir) {
465        #&gsprintf($out, "{import.removing_tmpdir}\n");
466        #&util::rm_r ($tmpdir);
467    }
468    }
469
470    # create the archives dir if needed
471    &util::mk_all_dir($archivedir);
472
473    # read the archive information file
474
475    # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
476    &util::rename_ldb_or_bdb_file(&util::filename_cat($archivedir, "archiveinf-doc"));
477    &util::rename_ldb_or_bdb_file(&util::filename_cat($archivedir, "archiveinf-src"));
478
479    # Warning! Black magic follows. When the following functions are called on
480    # the GDBMServer class they will actually prompt the running of the Server
481    # and attach themselves as a listener (even though they don't do anything)
482    # This is done so that, in parallel importing, the server will persist
483    # until the top level import.pl (which will be the first this that calls
484    # this function) completes. [jmt12]
485    my $create_server = 0;
486    # - infodb's of type *server need to be started on the same machine that
487    #   runs parallel-import.sh, especially when distributed processing
488    #   gets involved.
489    if ($collectcfg->{'infodbtype'} =~ /server$/)
490    {
491      $create_server = 1;
492    }
493    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-doc", $archivedir, $create_server);
494    my $arcinfo_src_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-src", $archivedir, $create_server);
495
496    my $archive_info = new arcinfo ($collectcfg->{'infodbtype'});
497    $archive_info->load_info ($arcinfo_doc_filename);
498
499    if ($manifest eq "") {
500    # Load in list of files in import folder from last import (if present)
501    $archive_info->load_prev_import_filelist ($arcinfo_src_filename);
502    }
503
504    ####Use Plugout####
505    my $plugout;
506
507    if ($inexport_mode eq "import") {
508    if (defined $collectcfg->{'plugout'}) {
509        # If a plugout was specified in the collect.cfg file, assume it is sensible
510        # We can't check the name because it could be anything, if it is a custom plugout
511        $plugout = $collectcfg->{'plugout'};
512    }
513    else{
514        if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
515        push @$plugout,"GreenstoneXMLPlugout";
516        }
517        else{
518        push @$plugout,$saveas."Plugout";
519        }
520    }
521    }
522    else {
523    if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
524        $plugout = $collectcfg->{'plugout'};
525    }
526    else{
527        if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
528        push @$plugout,"GreenstoneMETSPlugout";
529        }
530        else{
531        push @$plugout,$saveas."Plugout";
532        }
533    }
534    }
535   
536    my $plugout_name = $plugout->[0];
537
538    push @$plugout,("-output_info",$archive_info)  if (defined $archive_info);
539    push @$plugout,("-verbosity",$verbosity)       if (defined $verbosity);
540    push @$plugout,("-debug")                      if ($debug);
541    push @$plugout,("-group_size",$groupsize)      if (defined $groupsize);
542    push @$plugout,("-gzip_output")                if ($gzip);
543    push @$plugout,("-output_handle",$out)         if (defined $out);
544
545    push @$plugout,("-xslt_file",$xsltfile)        if (defined $xsltfile && $xsltfile ne "");
546
547    if ($plugout_name =~ m/^MARCXMLPlugout$/) {
548    push @$plugout,("-group")                      if ($group_marc);
549    push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "");
550    }
551    if ($plugout_name =~ m/^.*METSPlugout$/) {
552    push @$plugout,("-xslt_mets",$xslt_mets)       if (defined $xslt_mets && $xslt_mets ne "");
553    push @$plugout,("-xslt_txt",$xslt_txt)         if (defined $xslt_txt && $xslt_txt ne "");
554    }
555
556    if ($plugout_name eq "FedoraMETSPlugout") {
557    push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "");
558    }
559   
560    if ($plugout_name eq "DSpacePlugout") {
561    push @$plugout,("-metadata_prefix",$metadata_prefix) if (defined $metadata_prefix && $metadata_prefix ne "");   
562    }
563
564    my $processor = &plugout::load_plugout($plugout);                       
565    $processor->setoutputdir ($archivedir);
566    $processor->set_sortmeta ($sortmeta, $removeprefix, $removesuffix) if defined $sortmeta;
567    $processor->set_OIDtype ($OIDtype, $OIDmetadata);
568   
569    &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
570   
571    if ($removeold) {
572        # occasionally, plugins may want to do something on remove
573        # old, eg pharos image indexing
574    &plugin::remove_all($pluginfo, $importdir, $processor, $maxdocs, $gli);
575    }
576
577    # process the import directory
578    my $block_hash = {};
579    $block_hash->{'new_files'} = {};
580    $block_hash->{'reindex_files'} = {};
581    # All of these are set somewhere else, so it's kinda nice to define them
582    # here. [jmt12]
583    $block_hash->{'all_files'} = {};
584    $block_hash->{'deleted_files'} = {};
585    $block_hash->{'file_blocks'} = {};
586    $block_hash->{'metadata_files'} = {};
587    $block_hash->{'shared_fileroot'} = '';
588    # My new flag so we can tell we had a manifest way down in the plugins
589    # [jmt12]
590    $block_hash->{'manifest'} = 'false';
591    my $metadata = {};
592   
593    # global blocking pass may set up some metadata
594    # - when we have a manifest file we don't do this -unless- the collection
595    #   configuration indicates this collection contains complex (inherited)
596    #   metadata. [jmt12]
597    if ($manifest eq '' || (defined $collectcfg->{'complexmeta'} && $collectcfg->{'complexmeta'} eq 'true'))
598    {
599      #print "Temporarily skipping global file scan as it is slow as molasses\n";
600      &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
601    }
602    else
603    {
604      print "Skipping global file scan due to manifest and complexmeta configuration\n";
605    }
606   
607    if ($manifest ne "") {
608
609      $block_hash->{'manifest'} = 'true';
610
611    #
612    # 1. Process delete files first
613    #
614    my @deleted_files = keys %{$manifest_lookup->{'delete'}};
615    my @full_deleted_files = ();
616
617    # ensure all filenames are absolute
618    foreach my $df (@deleted_files) {
619        my $full_df =
620        (&util::filename_is_absolute($df))
621        ? $df
622        : &util::filename_cat($importdir,$df);
623
624        if (-d $full_df) {
625        &add_dir_contents_to_list($full_df, \@full_deleted_files);
626        } else {
627        push(@full_deleted_files,$full_df);
628        }
629    }
630   
631    &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@full_deleted_files);
632    mark_docs_for_deletion($archive_info,{},
633                   \@full_deleted_files,
634                   $archivedir, $verbosity, "delete");
635
636
637    #
638    # 2. Now files for reindexing
639    #
640
641    my @reindex_files = keys %{$manifest_lookup->{'reindex'}};
642    my @full_reindex_files = ();
643    # ensure all filenames are absolute
644    foreach my $rf (@reindex_files) {       
645        my $full_rf =
646        (&util::filename_is_absolute($rf))
647        ? $rf
648        : &util::filename_cat($importdir,$rf);
649
650        if (-d $full_rf) {
651        &add_dir_contents_to_list($full_rf, \@full_reindex_files);
652        } else {
653        push(@full_reindex_files,$full_rf);
654        }
655    }
656   
657    &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@full_reindex_files);
658    mark_docs_for_deletion($archive_info,{},\@full_reindex_files, $archivedir,$verbosity, "reindex");
659
660    # And now to ensure the new version of the file processed by
661    # appropriate plugin, we need to add it to block_hash reindex list
662    foreach my $full_rf (@full_reindex_files) {
663        $block_hash->{'reindex_files'}->{$full_rf} = 1;
664    }
665
666
667    #
668    # 3. Now finally any new files - add to block_hash new_files list
669    #
670
671    my @new_files = keys %{$manifest_lookup->{'index'}};
672    my @full_new_files = ();
673
674    foreach my $nf (@new_files) {
675        # ensure filename is absolute
676        my $full_nf =
677        (&util::filename_is_absolute($nf))
678        ? $nf
679        : &util::filename_cat($importdir,$nf);
680
681        if (-d $full_nf) {
682        &add_dir_contents_to_list($full_nf, \@full_new_files);
683        } else {
684        push(@full_new_files,$full_nf);
685        }
686    }
687
688    my $arcinfo_src_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-src", $archivedir);
689      # need to check this file exists before trying to read it. [jmt12]
690      if (-e $arcinfo_src_filename)
691      {
692    my $arcinfodb_map = {};
693    &dbutil::read_infodb_file($collectcfg->{'infodbtype'}, $arcinfo_src_filename, $arcinfodb_map);
694    foreach my $f (@full_new_files) {
695        # check that we haven't seen it already
696        if (defined $arcinfodb_map->{$f}) {
697        # TODO make better warning
698        print STDERR "Warning: $f already in src archive, \n";
699        } else {
700        $block_hash->{'new_files'}->{$f} = 1;
701        }
702    }
703    undef $arcinfodb_map;
704      }
705      # no existing files - so we can just add all the ones that need adding.
706      # [jmt12]
707      else
708      {
709        foreach my $f (@full_new_files)
710        {
711          $block_hash->{'new_files'}->{$f} = 1;
712        }
713      }
714
715      # If we are not using complex inherited metadata (and thus have skipped
716      # the global file scan) we need to at least scan the directory of the
717      # files being indexed/reindexed. [jmt12]
718      if (!defined $collectcfg->{'complexmeta'} || $collectcfg->{'complexmeta'} ne 'true')
719      {
720        my @all_files_to_import = (keys %{$block_hash->{'reindex_files'}}, keys %{$block_hash->{'new_files'}});
721        foreach my $file_to_import (@all_files_to_import)
722        {
723          my $dir_to_import = $file_to_import;
724          $dir_to_import =~ s/[^\\\/]*$//;
725          # - one day we may need to manually scan this directory for child
726          #   directories and somehow explicitly block them from being
727          #   recursed.
728          if (-d $dir_to_import)
729          {
730            &plugin::file_block_read($pluginfo, $dir_to_import, '', $block_hash, $metadata, $gli);
731          }
732        }
733      }
734    }
735    else {
736    # if incremental, we read through the import folder to see whats changed.
737
738    if ($incremental || $incremental_mode eq "onlyadd") {
739        prime_doc_oid_count($archivedir);
740
741        # Can now work out which files were new, already existed, and have
742        # been deleted
743       
744        new_vs_old_import_diff($archive_info,$block_hash,$importdir,
745                   $archivedir,$verbosity,$incremental_mode);
746       
747        my @new_files = sort keys %{$block_hash->{'new_files'}};
748        if (scalar(@new_files>0)) {
749        print STDERR "New files and modified metadata files since last import:\n  ";
750        print STDERR join("\n  ",@new_files), "\n";
751        }
752
753        if ($incremental) {
754               # only look for deletions if we are truely incremental
755        my @deleted_files = sort keys %{$block_hash->{'deleted_files'}};
756        # Filter out any in gsdl/tmp area
757        my @filtered_deleted_files = ();
758        my $gsdl_tmp_area = &util::filename_cat($ENV{'GSDLHOME'}, "tmp");
759        my $collect_tmp_area = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
760        $gsdl_tmp_area = &util::filename_to_regex($gsdl_tmp_area);
761        $collect_tmp_area = &util::filename_to_regex($collect_tmp_area);
762                 
763        foreach my $df (@deleted_files) {
764            next if ($df =~ m/^$gsdl_tmp_area/);
765            next if ($df =~ m/^$collect_tmp_area/);
766           
767            push(@filtered_deleted_files,$df);
768        }       
769       
770
771        @deleted_files = @filtered_deleted_files;
772       
773        if (scalar(@deleted_files)>0) {
774            print STDERR "Files deleted since last import:\n  ";
775            print STDERR join("\n  ",@deleted_files), "\n";
776       
777       
778            &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@deleted_files);
779           
780            mark_docs_for_deletion($archive_info,$block_hash,\@deleted_files, $archivedir,$verbosity, "delete");
781        }
782       
783        my @reindex_files = sort keys %{$block_hash->{'reindex_files'}};
784       
785        if (scalar(@reindex_files)>0) {
786            print STDERR "Files to reindex since last import:\n  ";
787            print STDERR join("\n  ",@reindex_files), "\n";
788            &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@reindex_files);
789            mark_docs_for_deletion($archive_info,$block_hash,\@reindex_files, $archivedir,$verbosity, "reindex");
790        }
791               
792        }       
793    }
794    }
795
796    # Check for existence of the file that's to contain earliestDateStamp in archivesdir
797    # Do nothing if the file already exists (file exists on incremental build).
798    # If the file doesn't exist, as happens on full build, create it and write out the current datestamp into it
799    # In buildcol, read the file's contents and set the earliestdateStamp in GS2's build.cfg / GS3's buildconfig.xml
800    # In doc.pm have set_oaiLastModified similar to set_lastmodified, and create the doc fields
801    # oailastmodified and oailastmodifieddate
802    my $earliestDatestampFile = &util::filename_cat($archivedir, "earliestDatestamp");
803    if (!-f $earliestDatestampFile && -d $archivedir) {
804    my $current_time_in_seconds = time; # in seconds
805
806    if(open(FOUT, ">$earliestDatestampFile")) {
807        # || (&gsprintf(STDERR, "{common.cannot_open}: $!\n", $earliestDatestampFile) && die);
808        print FOUT $current_time_in_seconds;
809        close(FOUT);
810    }
811    else {
812        &gsprintf(STDERR, "{import.cannot_write_earliestdatestamp}\n", $earliestDatestampFile);
813    }
814
815    }
816
817    # now, whichever mode we are in, we can process the entire import folder
818    if ((defined $jobs) && ($jobs > 1))
819    {
820    # if jobs are set to >1, run in parallel using MPI helper
821    # [hs, 1 july 2010]
822    &ParallelInexport::farm_out_processes($jobs, $epoch, $importdir, $block_hash,
823                          $self->{'collection'}, $self->{'site'});
824    }
825    else
826    {
827    &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
828    }
829   
830   
831    if ($saveas eq "FedoraMETS") {
832    # create collection "doc obj" for Fedora that contains
833    # collection-level metadata
834   
835    my $doc_obj = new doc($config_filename,"nonindexed_doc","none");
836    $doc_obj->set_OID("collection");
837   
838    my $col_name = undef;
839    my $col_meta = $collectcfg->{'collectionmeta'};
840   
841    if (defined $col_meta) {       
842        store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
843        store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description     
844    }
845    $processor->process($doc_obj);
846    }
847
848    &plugin::end($pluginfo, $processor);
849
850    &plugin::deinit($pluginfo, $processor);
851
852    # Store the value of OIDCount (used in doc.pm) so it can be
853    # restored correctly to this value on an incremental build
854    store_doc_oid_count($archivedir);
855
856    # write out the archive information file
857    $processor->close_file_output() if (defined $groupsize) && ($groupsize > 1);
858    $processor->close_group_output() if $processor->is_group();
859
860    # for backwards compatability with archvies.inf file
861    if ($arcinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
862    $archive_info->save_info($arcinfo_doc_filename);
863    }
864    else {
865    $archive_info->save_revinfo_db($arcinfo_src_filename);
866    }
867
868    return $pluginfo;
869}
870
871
872sub generate_statistics
873{
874    my $self = shift @_;
875    my ($pluginfo) = @_;
876
877    my $inexport_mode = $self->{'mode'};
878
879    my $statsfile   = $self->{'statsfile'};
880    my $out         = $self->{'out'};
881    my $faillogname = $self->{'faillogname'};
882    my $gli         = $self->{'gli'};
883    my $jobs        = $self->{'jobs'};
884
885    # write out import stats
886
887    if ((!defined $jobs) || ($jobs == 1))
888    {
889    # only output statistics if there are multiple jobs
890    # [hs, 1 july 2010]
891
892    my $close_stats = 0;
893    if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
894        if (open (STATS, ">$statsfile")) {
895        $statsfile = 'inexport::STATS';
896        $close_stats = 1;
897        } else {
898        &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
899        &gsprintf($out, "{import.stats_backup}\n");
900        $statsfile = 'STDERR';
901        }
902    }
903   
904    &gsprintf($out, "\n");
905    &gsprintf($out, "*********************************************\n");
906    &gsprintf($out, "{$inexport_mode.complete}\n");
907    &gsprintf($out, "*********************************************\n");
908   
909    &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
910    if ($close_stats) {
911        close STATS;
912    }
913    }
914
915    close OUT if $self->{'close_out'};
916    close FAILLOG;
917}
918
919
920sub store_collectionmeta
921{
922    my ($collectionmeta,$field,$doc_obj) = @_;
923   
924    my $section = $doc_obj->get_top_section();
925   
926    my $field_hash = $collectionmeta->{$field};
927   
928    foreach my $k (keys %$field_hash)
929    {
930    my $val = $field_hash->{$k};
931   
932    ### print STDERR "*** $k = $field_hash->{$k}\n";
933   
934    my $md_label = "ex.$field";
935   
936   
937    if ($k =~ m/^\[l=(.*?)\]$/)
938    {
939       
940        my $md_suffix = $1;
941        $md_label .= "^$md_suffix";
942    }
943   
944   
945    $doc_obj->add_utf8_metadata($section,$md_label, $val);
946   
947    # see collConfigxml.pm: GS2's "collectionextra" is called "description" in GS3,
948    # while "collectionname" in GS2 is called "name" in GS3.
949    # Variable $nameMap variable in collConfigxml.pm maps between GS2 and GS3
950    if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
951    {
952        $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
953    }
954   
955    }
956}
957
958
959sub oid_count_file {
960    my ($archivedir) = @_;
961    return &util::filename_cat ($archivedir, "OIDcount");
962}
963
964
965sub prime_doc_oid_count
966{
967    my ($archivedir) = @_;
968    my $oid_count_filename = &oid_count_file($archivedir);
969
970    if (-e $oid_count_filename) {
971    if (open(OIDIN,"<$oid_count_filename")) {
972        my $OIDcount = <OIDIN>;
973        chomp $OIDcount;       
974        close(OIDIN);
975
976        $doc::OIDcount = $OIDcount;     
977    }
978    else {     
979        &gsprintf(STDERR, "{import.cannot_read_OIDcount}\n", $oid_count_filename);
980    }
981    }
982   
983}
984
985sub store_doc_oid_count
986{
987    # Use the file "OIDcount" in the archives directory to record
988    # what value doc.pm got up to
989
990    my ($archivedir) = @_;
991    my $oid_count_filename = &oid_count_file($archivedir);
992
993
994    if (open(OIDOUT,">$oid_count_filename")) {
995    print OIDOUT $doc::OIDcount, "\n";
996       
997    close(OIDOUT);
998    }
999    else {
1000    &gsprintf(STDERR, "{import.cannot_write_OIDcount}\n", $oid_count_filename);
1001    }
1002}
1003
1004
1005
1006sub new_vs_old_import_diff
1007{
1008    my ($archive_info,$block_hash,$importdir,$archivedir,$verbosity,$incremental_mode) = @_;
1009
1010    # Get the infodbtype value for this collection from the arcinfo object
1011    my $infodbtype = $archive_info->{'infodbtype'};
1012
1013    # in this method, we want to know if metadata files are modified or not.
1014    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archivedir);
1015
1016    my $archiveinf_timestamp = -M $arcinfo_doc_filename;
1017
1018    # First convert all files to absolute form
1019    # This is to support the situation where the import folder is not
1020    # the default
1021   
1022    my $prev_all_files = $archive_info->{'prev_import_filelist'};
1023    my $full_prev_all_files = {};
1024
1025    foreach my $prev_file (keys %$prev_all_files) {
1026
1027    if (!&util::filename_is_absolute($prev_file)) {
1028        my $full_prev_file = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},$prev_file);
1029        $full_prev_all_files->{$full_prev_file} = $prev_file;
1030    }
1031    else {
1032        $full_prev_all_files->{$prev_file} = $prev_file;
1033    }
1034    }
1035
1036
1037    # Figure out which are the new files, existing files and so
1038    # by implication the files from the previous import that are not
1039    # there any more => mark them for deletion
1040    foreach my $curr_file (keys %{$block_hash->{'all_files'}}) {
1041   
1042    my $full_curr_file = $curr_file;
1043
1044    # entry in 'all_files' is moved to either 'existing_files',
1045    # 'deleted_files', 'new_files', or 'new_or_modified_metadata_files'
1046
1047    if (!&util::filename_is_absolute($curr_file)) {
1048        # add in import dir to make absolute
1049        $full_curr_file = &util::filename_cat($importdir,$curr_file);
1050    }
1051
1052    # figure out if new file or not
1053    if (defined $full_prev_all_files->{$full_curr_file}) {
1054        # delete it so that only files that need deleting are left
1055        delete $full_prev_all_files->{$full_curr_file};
1056       
1057        # had it before. is it a metadata file?
1058        if ($block_hash->{'metadata_files'}->{$full_curr_file}) {
1059       
1060        # is it modified??
1061        if (-M $full_curr_file < $archiveinf_timestamp) {
1062            print STDERR "*** Detected a *modified metadata* file: $full_curr_file\n" if $verbosity >= 2;
1063            # its newer than last build
1064            $block_hash->{'new_or_modified_metadata_files'}->{$full_curr_file} = 1;
1065        }
1066        }
1067        else {
1068        if ($incremental_mode eq "all") {
1069           
1070            # had it before
1071            $block_hash->{'existing_files'}->{$full_curr_file} = 1;
1072           
1073        }
1074        else {
1075            # Warning in "onlyadd" mode, but had it before!
1076            print STDERR "Warning: File $full_curr_file previously imported.\n";
1077            print STDERR "         Treating as new file\n";
1078           
1079            $block_hash->{'new_files'}->{$full_curr_file} = 1;
1080           
1081        }
1082        }
1083    }
1084    else {
1085        if ($block_hash->{'metadata_files'}->{$full_curr_file}) {
1086        # the new file is the special sort of file greenstone uses
1087        # to attach metadata to src documents
1088        # i.e metadata.xml
1089        # (but note, the filename used is not constrained in
1090        # Greenstone to always be this)
1091
1092        print STDERR "*** Detected *new* metadata file: $full_curr_file\n" if $verbosity >= 2;
1093        $block_hash->{'new_or_modified_metadata_files'}->{$full_curr_file} = 1;
1094        }
1095        else {
1096        $block_hash->{'new_files'}->{$full_curr_file} = 1;
1097        }
1098    }
1099
1100   
1101    delete $block_hash->{'all_files'}->{$curr_file};
1102    }
1103
1104
1105
1106
1107    # Deal with complication of new or modified metadata files by forcing
1108    # everything from this point down in the file hierarchy to
1109    # be freshly imported. 
1110    #
1111    # This may mean files that have not changed are reindexed, but does
1112    # guarantee by the end of processing all new metadata is correctly
1113    # associated with the relevant document(s).
1114
1115    foreach my $new_mdf (keys %{$block_hash->{'new_or_modified_metadata_files'}}) {
1116    my ($fileroot,$situated_dir,$ext) = fileparse($new_mdf, "\\.[^\\.]+\$");
1117
1118    $situated_dir =~ s/[\\\/]+$//; # remove tailing slashes
1119    $situated_dir =~ s/\\/\\\\/g;  # need to protect windows slash \ in regular expression
1120   
1121    # Go through existing_files, and mark anything that is contained
1122    # within 'situated_dir' to be reindexed (in case some of the metadata
1123    # attaches to one of these files)
1124
1125    my $reindex_files = [];
1126
1127    foreach my $existing_f (keys %{$block_hash->{'existing_files'}}) {
1128   
1129        if ($existing_f =~ m/^$situated_dir/) {
1130
1131        print STDERR "**** Existing file $existing_f\nis located within\n$situated_dir\n";
1132
1133        push(@$reindex_files,$existing_f);
1134        $block_hash->{'reindex_files'}->{$existing_f} = 1;
1135        delete $block_hash->{'existing_files'}->{$existing_f};
1136
1137        }
1138    }
1139   
1140    # metadata file needs to be in new_files list so parsed by MetadataXMLPlug
1141    # (or equivalent)
1142    $block_hash->{'new_files'}->{$new_mdf} = 1;
1143
1144    }
1145
1146    # go through remaining existing files and work out what has changed and needs to be reindexed.
1147    my @existing_files = sort keys %{$block_hash->{'existing_files'}};
1148
1149    my $reindex_files = [];
1150
1151    foreach my $existing_filename (@existing_files) {
1152    if (-M $existing_filename < $archiveinf_timestamp) {
1153        # file is newer than last build
1154       
1155        my $existing_file = $existing_filename;
1156        #my $collectdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'});
1157
1158        #my $collectdir_resafe = &util::filename_to_regex($collectdir);
1159        #$existing_file =~ s/^$collectdir_resafe(\\|\/)?//;
1160       
1161        print STDERR "**** Reindexing existing file: $existing_file\n";
1162
1163        push(@$reindex_files,$existing_file);
1164        $block_hash->{'reindex_files'}->{$existing_filename} = 1;
1165    }
1166
1167    }
1168
1169   
1170    # By this point full_prev_all_files contains the files
1171    # mentioned in archiveinf-src.db but are not in the 'import'
1172    # folder (or whatever was specified through -importdir ...)
1173
1174    # This list can contain files that were created in the 'tmp' or
1175    # 'cache' areas (such as screen-size and thumbnail images).
1176    #
1177    # In building the final list of files to delete, we test to see if
1178    # it exists on the filesystem and if it does (unusual for a "normal"
1179    # file in import, but possible in the case of 'tmp' files),
1180    # supress it from going into the final list
1181
1182    my $collectdir = $ENV{'GSDLCOLLECTDIR'};
1183
1184    my @deleted_files = values %$full_prev_all_files;
1185    map { my $curr_file = $_;
1186      my $full_curr_file = $curr_file;
1187
1188      if (!&util::filename_is_absolute($curr_file)) {
1189          # add in import dir to make absolute
1190
1191          $full_curr_file = &util::filename_cat($collectdir,$curr_file);
1192      }
1193
1194
1195      if (!-e $full_curr_file) {
1196          $block_hash->{'deleted_files'}->{$curr_file} = 1;
1197      }
1198      } @deleted_files;
1199
1200
1201
1202}
1203
1204
1205# this is used to delete "deleted" docs, and to remove old versions of "changed" docs
1206# $mode is 'delete' or 'reindex'
1207sub mark_docs_for_deletion
1208{
1209    my ($archive_info,$block_hash,$deleted_files,$archivedir,$verbosity,$mode) = @_;
1210
1211    my $mode_text = "deleted from index";
1212    if ($mode eq "reindex") {
1213    $mode_text = "reindexed";
1214    }
1215
1216    # Get the infodbtype value for this collection from the arcinfo object
1217    my $infodbtype = $archive_info->{'infodbtype'};
1218
1219    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archivedir);
1220    my $arcinfo_src_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-src", $archivedir);
1221
1222
1223    # record files marked for deletion in arcinfo
1224    foreach my $file (@$deleted_files) {
1225    # use 'archiveinf-src' info database file to look up all the OIDs
1226    # that this file is used in (note in most cases, it's just one OID)
1227   
1228    my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file);
1229    my $oids = $src_rec->{'oid'};
1230    my $file_record_deleted = 0;
1231
1232    # delete the src record
1233    my $src_infodb_file_handle = &dbutil::open_infodb_write_handle($infodbtype, $arcinfo_src_filename, "append");
1234    &dbutil::delete_infodb_entry($infodbtype, $src_infodb_file_handle, $file);
1235    &dbutil::close_infodb_write_handle($infodbtype, $src_infodb_file_handle);
1236
1237
1238    foreach my $oid (@$oids) {
1239
1240        # find the source doc (the primary file that becomes this oid)
1241        my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $oid);
1242        my $doc_source_file = $doc_rec->{'src-file'}->[0];
1243        if (!&util::filename_is_absolute($doc_source_file)) {
1244        $doc_source_file = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},$doc_source_file);
1245        }
1246
1247        if ($doc_source_file ne $file) {
1248        # its an associated or metadata file
1249       
1250        # mark source doc for reimport as one of its assoc files has changed or deleted
1251        $block_hash->{'reindex_files'}->{$doc_source_file} = 1;
1252       
1253        }
1254        my $curr_status = $archive_info->get_status_info($oid);
1255        if (defined($curr_status) && (($curr_status ne "D"))) {
1256        if ($verbosity>1) {
1257            print STDERR "$oid ($doc_source_file) marked to be $mode_text on next buildcol.pl\n";
1258        }
1259        # mark oid for deletion (it will be deleted or reimported)
1260        $archive_info->set_status_info($oid,"D");
1261        my $val = &dbutil::read_infodb_rawentry($infodbtype, $arcinfo_doc_filename, $oid);
1262        $val =~ s/^<index-status>(.*)$/<index-status>D/m;
1263
1264        my $val_rec = &dbutil::convert_infodb_string_to_hash($val);
1265        my $doc_infodb_file_handle = &dbutil::open_infodb_write_handle($infodbtype, $arcinfo_doc_filename, "append");
1266
1267        &dbutil::write_infodb_entry($infodbtype, $doc_infodb_file_handle, $oid, $val_rec);
1268        &dbutil::close_infodb_write_handle($infodbtype, $doc_infodb_file_handle);
1269        }
1270    }
1271   
1272    }
1273
1274    # now go through and check that we haven't marked any primary
1275    # files for reindex (because their associated files have
1276    # changed/deleted) when they have been deleted themselves. only in
1277    # delete mode.
1278
1279    if ($mode eq "delete") {
1280    foreach my $file (@$deleted_files) {
1281        if (defined $block_hash->{'reindex_files'}->{$file}) {
1282        delete $block_hash->{'reindex_files'}->{$file};
1283        }
1284    }
1285    }
1286
1287
1288}
1289
1290sub add_dir_contents_to_list {
1291
1292    my ($dirname, $list) = @_;
1293 
1294    # Recur over directory contents.
1295    my (@dir, $subfile);
1296   
1297    # find all the files in the directory
1298    if (!opendir (DIR, $dirname)) {
1299    print STDERR "inexport: WARNING - couldn't read directory $dirname\n";
1300    return -1; # error in processing
1301    }
1302    @dir = readdir (DIR);
1303    closedir (DIR);
1304   
1305    for (my $i = 0; $i < scalar(@dir); $i++) {
1306    my $subfile = $dir[$i];
1307    next if ($subfile =~ m/^\.\.?$/);
1308    next if ($subfile =~ /^\.svn$/);
1309    my $full_file = &util::filename_cat($dirname, $subfile);
1310    if (-d $full_file) {
1311        &add_dir_contents_to_list($full_file, $list);
1312    } else {
1313        push (@$list, $full_file);
1314    }
1315    }
1316   
1317}
1318
1319
13201;
Note: See TracBrowser for help on using the browser.