[537] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[16013] | 3 | # ArchivesInfPlugin.pm --
|
---|
[537] | 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 |
|
---|
[21566] | 26 | # plugin which reads through an archives.inf (or archiveinf-doc info database equivalent)
|
---|
| 27 | # -- i.e. the file generated in the archives directory when an import is done),
|
---|
| 28 | # processing each file it finds
|
---|
[4] | 29 |
|
---|
[15870] | 30 | package ArchivesInfPlugin;
|
---|
[4] | 31 |
|
---|
| 32 | use util;
|
---|
[18528] | 33 | use doc;
|
---|
[17738] | 34 | use PrintInfo;
|
---|
[4] | 35 | use plugin;
|
---|
| 36 | use arcinfo;
|
---|
[5680] | 37 | use gsprintf;
|
---|
[4] | 38 |
|
---|
[10254] | 39 | use strict;
|
---|
| 40 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 41 |
|
---|
[21563] | 42 |
|
---|
[4] | 43 | BEGIN {
|
---|
[17738] | 44 | @ArchivesInfPlugin::ISA = ('PrintInfo');
|
---|
[4] | 45 | }
|
---|
| 46 |
|
---|
[10254] | 47 | my $arguments = [
|
---|
[20758] | 48 | { 'name' => "reversesort",
|
---|
| 49 | 'desc' => "{ArchivesInfPlugin.reversesort}",
|
---|
| 50 | 'type' => "flag",
|
---|
| 51 | 'reqd' => "no",
|
---|
| 52 | 'modegli' => "2" },
|
---|
| 53 |
|
---|
[10254] | 54 | ];
|
---|
| 55 |
|
---|
[15870] | 56 | my $options = { 'name' => "ArchivesInfPlugin",
|
---|
| 57 | 'desc' => "{ArchivesInfPlugin.desc}",
|
---|
[6408] | 58 | 'abstract' => "no",
|
---|
[20760] | 59 | 'inherits' => "yes",
|
---|
| 60 | 'args' => $arguments};
|
---|
[10254] | 61 |
|
---|
[5680] | 62 | sub gsprintf
|
---|
| 63 | {
|
---|
| 64 | return &gsprintf::gsprintf(@_);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[4] | 67 | sub new {
|
---|
[10218] | 68 | my ($class) = shift (@_);
|
---|
| 69 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 70 | push(@$pluginlist, $class);
|
---|
[4] | 71 |
|
---|
[15870] | 72 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 73 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10218] | 74 |
|
---|
[17738] | 75 | my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 76 |
|
---|
[4] | 77 | return bless $self, $class;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[17738] | 80 | # called once, at the start of processing
|
---|
| 81 | sub init {
|
---|
| 82 | my $self = shift (@_);
|
---|
| 83 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
| 84 |
|
---|
| 85 | # verbosity is passed through from the processor
|
---|
| 86 | $self->{'verbosity'} = $verbosity;
|
---|
| 87 |
|
---|
| 88 | # as are the outhandle and failhandle
|
---|
| 89 | $self->{'outhandle'} = $outhandle if defined $outhandle;
|
---|
| 90 | $self->{'failhandle'} = $failhandle;
|
---|
| 91 |
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[10156] | 94 | sub deinit {
|
---|
| 95 | my ($self) = @_;
|
---|
| 96 |
|
---|
| 97 | my $archive_info = $self->{'archive_info'};
|
---|
[18508] | 98 | my $verbosity = $self->{'verbosity'};
|
---|
| 99 | my $outhandle = $self->{'outhandle'};
|
---|
[10156] | 100 |
|
---|
| 101 | if (defined $archive_info) {
|
---|
| 102 | my $archive_info_filename = $self->{'archive_info_filename'};
|
---|
[21559] | 103 | my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $archive_info_filename, "append");
|
---|
[10156] | 104 |
|
---|
| 105 | my $file_list = $archive_info->get_file_list();
|
---|
| 106 |
|
---|
[18456] | 107 | foreach my $subfile (@$file_list) {
|
---|
[10156] | 108 | my $doc_oid = $subfile->[1];
|
---|
[18441] | 109 |
|
---|
[10254] | 110 | my $index_status = $archive_info->get_status_info($doc_oid);
|
---|
[18456] | 111 |
|
---|
[18441] | 112 | if ($index_status eq "D") {
|
---|
| 113 | # delete
|
---|
| 114 | $archive_info->delete_info($doc_oid);
|
---|
[21559] | 115 | &dbutil::delete_infodb_entry("gdbm", $infodb_file_handle, $doc_oid);
|
---|
[18508] | 116 |
|
---|
| 117 | my $doc_file = $subfile->[0];
|
---|
| 118 | my $base_dir =$self->{'base_dir'};
|
---|
| 119 |
|
---|
| 120 | my $doc_filename = &util::filename_cat($base_dir,$doc_file);
|
---|
| 121 |
|
---|
| 122 | my ($doc_tailname, $doc_dirname, $suffix)
|
---|
| 123 | = File::Basename::fileparse($doc_filename, "\\.[^\\.]+\$");
|
---|
| 124 |
|
---|
[18509] | 125 | print $outhandle "Removing $doc_dirname\n" if ($verbosity>2);
|
---|
[18508] | 126 |
|
---|
| 127 | &util::rm_r($doc_dirname);
|
---|
| 128 |
|
---|
| 129 |
|
---|
[18441] | 130 | }
|
---|
| 131 | elsif ($index_status =~ m/^(I|R)$/) {
|
---|
| 132 | # mark as "been indexed"
|
---|
| 133 | $archive_info->set_status_info($doc_oid,"B");
|
---|
| 134 | }
|
---|
[10156] | 135 | }
|
---|
| 136 |
|
---|
[21559] | 137 | &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle);
|
---|
[10156] | 138 | $archive_info->save_info($archive_info_filename);
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[17738] | 142 | # called at the beginning of each plugin pass (import has one, buildin has many)
|
---|
| 143 | sub begin {
|
---|
| 144 | my $self = shift (@_);
|
---|
| 145 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 146 |
|
---|
[18508] | 147 | $self->{'base_dir'} = $base_dir;
|
---|
[17738] | 148 | }
|
---|
| 149 |
|
---|
[21308] | 150 | sub remove_all {
|
---|
[21285] | 151 | my $self = shift (@_);
|
---|
| 152 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 153 |
|
---|
| 154 | }
|
---|
[21308] | 155 |
|
---|
| 156 | sub remove_one {
|
---|
| 157 | my $self = shift (@_);
|
---|
[21315] | 158 | my ($file, $oids, $archivedir) = @_;
|
---|
| 159 | return undef; # only called during import at this stage, this will never be processing a file
|
---|
| 160 |
|
---|
[21308] | 161 | }
|
---|
| 162 |
|
---|
| 163 |
|
---|
[17738] | 164 | # called at the end of each plugin pass
|
---|
| 165 | sub end {
|
---|
| 166 | my ($self) = shift (@_);
|
---|
| 167 |
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 |
|
---|
[4] | 171 | # return 1 if this class might recurse using $pluginfo
|
---|
| 172 | sub is_recursive {
|
---|
| 173 | my $self = shift (@_);
|
---|
| 174 |
|
---|
| 175 | return 1;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[10156] | 178 |
|
---|
[17738] | 179 | sub compile_stats {
|
---|
| 180 | my $self = shift(@_);
|
---|
| 181 | my ($stats) = @_;
|
---|
| 182 | }
|
---|
[10156] | 183 |
|
---|
[17738] | 184 | # We don't do metadata_read
|
---|
| 185 | sub metadata_read {
|
---|
| 186 | my $self = shift (@_);
|
---|
[19493] | 187 | my ($pluginfo, $base_dir, $file, $block_hash,
|
---|
| 188 | $extrametakeys, $extrametadata, $extrametafile,
|
---|
| 189 | $processor, $maxdocs, $gli) = @_;
|
---|
[10156] | 190 |
|
---|
[17738] | 191 | return undef;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | sub file_block_read {
|
---|
| 195 |
|
---|
| 196 | my $self = shift (@_);
|
---|
| 197 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
|
---|
| 198 |
|
---|
[18528] | 199 | if ($file eq "OIDcount") {
|
---|
| 200 | my ($filename_full_path, $filename_no_path)
|
---|
| 201 | = &util::get_full_filenames($base_dir, $file);
|
---|
| 202 | $block_hash->{'file_blocks'}->{$filename_full_path} = 1;
|
---|
| 203 | return 1;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | # otherwise, we don't do any file blocking
|
---|
| 207 |
|
---|
[17738] | 208 | return undef;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
[317] | 212 | # return number of files processed, undef if can't process
|
---|
[4] | 213 | # Note that $base_dir might be "" and that $file might
|
---|
| 214 | # include directories
|
---|
| 215 | sub read {
|
---|
| 216 | my $self = shift (@_);
|
---|
[16392] | 217 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
|
---|
[1424] | 218 | my $outhandle = $self->{'outhandle'};
|
---|
[4] | 219 |
|
---|
[317] | 220 | my $count = 0;
|
---|
| 221 |
|
---|
[4] | 222 | # see if this has a archives information file within it
|
---|
[18441] | 223 | ## my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
|
---|
[18659] | 224 |
|
---|
[21566] | 225 | my $archive_info_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", &util::filename_cat($base_dir, $file));
|
---|
[4] | 226 |
|
---|
| 227 | if (-e $archive_info_filename) {
|
---|
| 228 |
|
---|
[317] | 229 | # found an archives.inf file
|
---|
[15870] | 230 | &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
|
---|
[317] | 231 |
|
---|
[4] | 232 | # read in the archives information file
|
---|
| 233 | my $archive_info = new arcinfo ();
|
---|
[10156] | 234 | $self->{'archive_info'} = $archive_info;
|
---|
[12397] | 235 | $self->{'archive_info_filename'} = $archive_info_filename;
|
---|
[20758] | 236 | if ($self->{'reversesort'}) {
|
---|
| 237 | $archive_info->reverse_sort();
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[4] | 240 | $archive_info->load_info ($archive_info_filename);
|
---|
| 241 |
|
---|
[230] | 242 | my $file_list = $archive_info->get_file_list();
|
---|
[4] | 243 |
|
---|
| 244 | # process each file
|
---|
[1244] | 245 | foreach my $subfile (@$file_list) {
|
---|
[18441] | 246 |
|
---|
[9853] | 247 | last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
|
---|
[317] | 248 |
|
---|
[4] | 249 | my $tmp = &util::filename_cat ($file, $subfile->[0]);
|
---|
| 250 | next if $tmp eq $file;
|
---|
[18456] | 251 |
|
---|
| 252 | my $doc_oid = $subfile->[1];
|
---|
| 253 | my $index_status = $archive_info->get_status_info($doc_oid);
|
---|
| 254 |
|
---|
| 255 | my $curr_mode = $processor->get_mode();
|
---|
| 256 | my $new_mode = $curr_mode;
|
---|
| 257 |
|
---|
| 258 | # Start by assuming we want to process the file...
|
---|
[16257] | 259 | my $process_file = 1;
|
---|
[10156] | 260 |
|
---|
[18469] | 261 | # ...unless the build processor is incremental capable and -incremental was specified, in which case we need to check its index_status flag
|
---|
[16257] | 262 | if ($processor->is_incremental_capable() && $self->{'incremental'})
|
---|
| 263 | {
|
---|
[18441] | 264 | # Check to see if the file needs indexing
|
---|
[16257] | 265 | if ($index_status eq "B")
|
---|
| 266 | {
|
---|
[18441] | 267 | # Don't process this file as it has already been indexed
|
---|
[16257] | 268 | $process_file = 0;
|
---|
[10305] | 269 | }
|
---|
[18456] | 270 | elsif ($index_status eq "D") {
|
---|
| 271 | # Need to be delete it from the index.
|
---|
| 272 | $new_mode = $curr_mode."delete";
|
---|
| 273 | $process_file = 1;
|
---|
| 274 | }
|
---|
| 275 | elsif ($index_status eq "R") {
|
---|
[18469] | 276 | # Need to be reindexed/replaced
|
---|
[18456] | 277 | $new_mode = $curr_mode."reindex";
|
---|
[18469] | 278 |
|
---|
[18456] | 279 | $process_file = 1;
|
---|
| 280 | }
|
---|
[10305] | 281 | }
|
---|
[18456] | 282 | # ... or we're being asked to delete it (in which case skip it)
|
---|
| 283 | elsif ($index_status eq "D") {
|
---|
[18469] | 284 | # Non-incremental Delete
|
---|
| 285 | # It's already been deleted from the archives directory
|
---|
| 286 | # (done during import.pl)
|
---|
| 287 | # => All we need to do here is not process it
|
---|
[10305] | 288 |
|
---|
[18456] | 289 | $process_file = 0;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[18469] | 292 | if (!$processor->is_incremental_capable() && $self->{'incremental'}) {
|
---|
| 293 | # Nag feature
|
---|
| 294 | if (!defined $self->{'incremental-warning'}) {
|
---|
| 295 | print $outhandle "\n";
|
---|
| 296 | print $outhandle "Warning: command-line option '-incremental' used with *non-incremental*\n";
|
---|
| 297 | print $outhandle " processor '", ref $processor, "'. Some conflicts may arise.\n";
|
---|
| 298 | print $outhandle "\n";
|
---|
| 299 | sleep 10;
|
---|
| 300 | $self->{'incremental-warning'} = 1;
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[10305] | 304 | if ($process_file) {
|
---|
[10156] | 305 | # note: metadata is not carried on to the next level
|
---|
[18456] | 306 |
|
---|
| 307 | $processor->set_mode($new_mode) if ($new_mode ne $curr_mode);
|
---|
| 308 |
|
---|
[16392] | 309 | $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
|
---|
[18456] | 310 |
|
---|
| 311 | $processor->set_mode($curr_mode) if ($new_mode ne $curr_mode);
|
---|
[10156] | 312 | }
|
---|
[4] | 313 | }
|
---|
| 314 |
|
---|
[317] | 315 | return $count;
|
---|
[4] | 316 | }
|
---|
| 317 |
|
---|
[18528] | 318 |
|
---|
[4] | 319 | # wasn't an archives directory, someone else will have to process it
|
---|
[317] | 320 | return undef;
|
---|
[4] | 321 | }
|
---|
| 322 |
|
---|
| 323 | 1;
|
---|