1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # DocHistoryFileUtils.pm
|
---|
4 | # -- supporting routines for file-level document-version history (fldv-history)
|
---|
5 | #
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 2023 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 | package DocHistoryFileUtils;
|
---|
29 |
|
---|
30 | # Pragma
|
---|
31 | use strict;
|
---|
32 | use warnings;
|
---|
33 |
|
---|
34 | # use FileHandle;
|
---|
35 |
|
---|
36 | # Greenstone modules
|
---|
37 | use dbutil;
|
---|
38 | use FileUtils;
|
---|
39 |
|
---|
40 | my $FLDV_HISTORY_DIR = "_fldv_history";
|
---|
41 |
|
---|
42 | sub prepend_document_version
|
---|
43 | {
|
---|
44 | my ($keepold_doc_dirname,$doc_dirname) = @_;
|
---|
45 |
|
---|
46 | # Step 5.1:
|
---|
47 | # * Deal with the keepold archives doc's in '_fldv_history' first (if it, and the sub-dirs exist)
|
---|
48 | # Step 5.2:
|
---|
49 | # * Deal with the keepold archives doc's top-level content (excluding _fldv_history)
|
---|
50 |
|
---|
51 | # For $keepold == 1 this means:
|
---|
52 | # * Recursive hardlink copy each of the keepold 'nminus-<n> folders -> archives as 'nminus-<n+1>'
|
---|
53 | # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir)
|
---|
54 |
|
---|
55 |
|
---|
56 | my $status_ok = 1;
|
---|
57 |
|
---|
58 | my $doc_fldv_history_dirname = &FileUtils::filenameConcatenate($doc_dirname,$FLDV_HISTORY_DIR);
|
---|
59 | my $keepold_doc_fldv_history_dirname = &FileUtils::filenameConcatenate($keepold_doc_dirname,$FLDV_HISTORY_DIR);
|
---|
60 |
|
---|
61 | if (&FileUtils::directoryExists($doc_fldv_history_dirname)) {
|
---|
62 | print SDTDERR "Error - The newly formed 'archives' version of document should not contain the existing '$FLDV_HISTORY_DIR' directory:\n";
|
---|
63 | print STDERR " $doc_fldv_history_dirname\n";
|
---|
64 | $status_ok = 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | if ($status_ok) {
|
---|
68 | # Step 5.1
|
---|
69 |
|
---|
70 | # Create _fldv_history in archive doc's dir, ready to take the n -> n+1 copies
|
---|
71 | my $mkdir_ok = &FileUtils::makeDirectory($doc_fldv_history_dirname);
|
---|
72 |
|
---|
73 | if ($mkdir_ok) {
|
---|
74 |
|
---|
75 | # If the keepold _fldv_history directory exists, then some prior content to deal with.
|
---|
76 | # Otherwise, this is our case of first file-level doc-version history for the doc
|
---|
77 | # and for Step 5.1 there is nothing to do
|
---|
78 |
|
---|
79 | if (&FileUtils::directoryExists($keepold_doc_fldv_history_dirname)) {
|
---|
80 |
|
---|
81 | # Start recursive hardlink copying the directories across as n -> n+1
|
---|
82 |
|
---|
83 | my $keepold_matching_dirs = &FileUtils::readDirectoryFiltered($keepold_doc_fldv_history_dirname,undef,"^nminus-\\d+\$");
|
---|
84 |
|
---|
85 | if (scalar(@$keepold_matching_dirs) == 0) {
|
---|
86 | print STDERR "Warning: no 'nminus-<n>' directories found in $FLDV_HISTORY_DIR:\n";
|
---|
87 | print STDERR " $keepold_doc_fldv_history_dirname\n";
|
---|
88 | print STDERR "=> No file-level document-version history content to increase by 1\n";
|
---|
89 | }
|
---|
90 |
|
---|
91 | my @sorted_keepold_matching_dirs = sort {
|
---|
92 | my ($a_num) = ($a =~ m/(\d+)$/);
|
---|
93 | my ($b_num) = ($b =~ m/(\d+)$/);
|
---|
94 |
|
---|
95 | # sort into descending order
|
---|
96 | return $b_num <=> $a_num;
|
---|
97 | } @$keepold_matching_dirs;
|
---|
98 |
|
---|
99 | # want sort order to be higest to lowest, for moving 'n' vals up by one
|
---|
100 |
|
---|
101 | foreach my $nminus_n (@sorted_keepold_matching_dirs) {
|
---|
102 |
|
---|
103 | my $keepold_full_dir = &FileUtils::filenameConcatenate($keepold_doc_fldv_history_dirname,$nminus_n);
|
---|
104 | if (-d $keepold_full_dir) {
|
---|
105 |
|
---|
106 | my ($n) = ($nminus_n =~ m/(\d+)$/);
|
---|
107 | my $new_n = $n + 1;
|
---|
108 |
|
---|
109 | my $full_new_dir_plus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-$new_n");
|
---|
110 |
|
---|
111 | my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_full_dir],$full_new_dir_plus1,
|
---|
112 | { 'strict' => 1 } );
|
---|
113 |
|
---|
114 | if (!$hard_link_ok) {
|
---|
115 | print STDERR "Error: Failed to recursive hardlink copy 'nminus-<n>' from 'archives_keepold' to 'archives'\n";
|
---|
116 | $status_ok = 0;
|
---|
117 | last;
|
---|
118 | }
|
---|
119 |
|
---|
120 | #my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_full_dir],$full_new_dir_plus1,
|
---|
121 | # { 'strict' => 1, 'exclude_filter_re' => "^$FLDV_HISTORY_DIR\$" } );
|
---|
122 |
|
---|
123 | #if (!&FileUtils::renameDirectory($full_dir,$full_new_dir)) {
|
---|
124 | # print STDERR "Error: Failed to shuffled down 'nminus' dirs\n";
|
---|
125 | # $status_ok = 0;
|
---|
126 | # last;
|
---|
127 | #}
|
---|
128 | }
|
---|
129 | else {
|
---|
130 | print STDERR "Warning: skipping $keepold_full_dir as it is not a directory\n";
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | print STDERR "First time file-level document-version history item stored for $doc_fldv_history_dirname\n";
|
---|
137 | }
|
---|
138 | }
|
---|
139 | else {
|
---|
140 | print STDERR "Error: failed to make directory:\n";
|
---|
141 | print STDERR " '$doc_fldv_history_dirname'\n";
|
---|
142 |
|
---|
143 | $status_ok = 0;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 | # # Action Step 5 (from inexport.pm)
|
---|
151 | # #
|
---|
152 | # # 5.1 When $keepold == 1
|
---|
153 | # #### * Move the keepold archives doc's '_fldv_history' to archives (if it exists)
|
---|
154 | # #### * Then, if nminus-1, nminus-2 etc sub-folders exist, shuffle them (in-situ) down by one
|
---|
155 |
|
---|
156 | # # * Recursive hardlink copy each of the keepold 'nminus-<n> folders -> archives as 'nminus-<n+1>'
|
---|
157 | # # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir)
|
---|
158 |
|
---|
159 | # # Move the keepold archives doc's '_fldv_history' to archives (if it exists)
|
---|
160 | # # * Then, if nminus-1, nminus-2 etc sub-folders exist, shuffle them (in-situ) down by one
|
---|
161 |
|
---|
162 |
|
---|
163 | # if (!&FileUtils::directoryExists($keepold_doc_fldv_history_dirname)) {
|
---|
164 | # # First time creating a file-level doc-version history folder for this doc
|
---|
165 | # # => make new empty _fldv_history folder in archives dir (nothing else to do at this point)
|
---|
166 | # my $mkdir_ok = &FileUtils::makeDirectory($doc_fldv_history_dirname);
|
---|
167 |
|
---|
168 | # if (!$mkdir_ok) {
|
---|
169 | # print STDERR "Error: failed to make directory:\n";
|
---|
170 | # print STDERR " '$doc_fldv_history_dirname'\n";
|
---|
171 |
|
---|
172 | # $status_ok = 0;
|
---|
173 | # }
|
---|
174 | # }
|
---|
175 | # else {
|
---|
176 | # # Have some existing nminus-n folders to deal this
|
---|
177 |
|
---|
178 | # if (&FileUtils::directoryMove($keepold_$doc_fldv_history_dirname,$doc_fldv_history_dirname)) {
|
---|
179 |
|
---|
180 | # # now shuffle nminus-1, nminus-2 down by one
|
---|
181 | # my $matching_dirs = &FileUtils::readDirectoryFiltered($doc_fldv_history_dirname,undef,"^nminus-\\d+\$");
|
---|
182 |
|
---|
183 | # if (scalar(@$matching_dirs) == 0) {
|
---|
184 | # print STDERR "Warning: no 'nminus-<n>' directories found in $FLDV_HISTORY_DIR:\n";
|
---|
185 | # print STDERR " $doc_fldv_history_dirname\n";
|
---|
186 | # print STDERR "=> No file-level document-version history to store\n";
|
---|
187 | # }
|
---|
188 |
|
---|
189 | # my @sorted_matching_dirs = sort {
|
---|
190 | # my ($a_num) = ($a =~ m/(\d+)$/);
|
---|
191 | # my ($b_num) = ($b =~ m/(\d+)$/);
|
---|
192 |
|
---|
193 | # # sort into descending order
|
---|
194 | # return $b_num <=> $a_num;
|
---|
195 | # } @$matching_dirs;
|
---|
196 |
|
---|
197 | # # want sort order to be higest to lowest, for moving 'n' vals up by one
|
---|
198 |
|
---|
199 | # foreach my $nminus_n (@sorted_matching_dirs) {
|
---|
200 |
|
---|
201 | # my $full_dir = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,$nminus_n);
|
---|
202 | # if (-d $full_dir) {
|
---|
203 | # # print STDERR " Increasing by one the file-level document-version history number for:\n";
|
---|
204 | # # print STDERR " $full_dir\n";
|
---|
205 |
|
---|
206 | # my ($n) = ($nminus_n =~ m/(\d+)$/);
|
---|
207 | # my $new_n = $n + 1;
|
---|
208 |
|
---|
209 | # my $full_new_dir = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-$new_n");
|
---|
210 |
|
---|
211 | # if (!&FileUtils::renameDirectory($full_dir,$full_new_dir)) {
|
---|
212 | # print STDERR "Error: Failed to shuffled down 'nminus' dirs\n";
|
---|
213 | # $status_ok = 0;
|
---|
214 | # last;
|
---|
215 | # }
|
---|
216 | # }
|
---|
217 | # else {
|
---|
218 | # print STDERR "Warning: skipping $full_dir as it is not a directory\n";
|
---|
219 | # }
|
---|
220 | # }
|
---|
221 | # }
|
---|
222 | # else {
|
---|
223 | # print STDERR "Error - Failed to move $FLDV_HISTORY_DIR from 'archives_keepold' to 'archives'\n";
|
---|
224 | # $status_ok = 0;
|
---|
225 | # }
|
---|
226 | # }
|
---|
227 | # }
|
---|
228 |
|
---|
229 | if ($status_ok) {
|
---|
230 |
|
---|
231 | # Step 5.2
|
---|
232 |
|
---|
233 | # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir)
|
---|
234 |
|
---|
235 | my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1");
|
---|
236 |
|
---|
237 | my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_doc_dirname],$doc_fldv_history_dirname_nminus1,
|
---|
238 | { 'strict' => 1, 'exclude_filter_re' => "^$FLDV_HISTORY_DIR\$" } );
|
---|
239 |
|
---|
240 | if (!$hard_link_ok) {
|
---|
241 | print STDERR "Error: Failed to recursively hardlink copy the top-level 'keepold_archives' doc as 'archives' $FLDV_HISTORY_DIR/nminus-1 version\n";
|
---|
242 | $status_ok = 0;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | if (!$status_ok) {
|
---|
247 | print STDERR "\n";
|
---|
248 | print STDERR "**** A critical error occurred in creating/updating file-level document-version history\n";
|
---|
249 | print STDERR "**** After determining and correcting the cause of the error, to reset, delete\n";
|
---|
250 | print STDERR "**** your 'archives' folder, and move 'archives_keepold' back to 'archives'\n";
|
---|
251 | print STDERR "\n";
|
---|
252 | exit 1;
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | sub replace_document_version
|
---|
257 | {
|
---|
258 | my ($keepold_doc_dirname,$doc_dirname) = @_;
|
---|
259 |
|
---|
260 | # Step 5.1:
|
---|
261 | # * Deal with the keepold archives doc's in '_fldv_history' first (if it, and the sub-dirs exist)
|
---|
262 | # Step 5.2:
|
---|
263 | # * Deal with the keepold archives doc's top-level content (excluding _fldv_history)
|
---|
264 |
|
---|
265 | # For $replaceold == 1 this means:
|
---|
266 | # * Starting at 'nminus-2', recursive hardlink copy each of the keepold 'nminus-<n>' folders (keeping 'n' the same value)
|
---|
267 | # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir) as 'nminus-1'
|
---|
268 |
|
---|
269 | my $status_ok = 1;
|
---|
270 |
|
---|
271 | my $doc_fldv_history_dirname = &FileUtils::filenameConcatenate($doc_dirname,$FLDV_HISTORY_DIR);
|
---|
272 | my $keepold_doc_fldv_history_dirname = &FileUtils::filenameConcatenate($keepold_doc_dirname,$FLDV_HISTORY_DIR);
|
---|
273 |
|
---|
274 | if (&FileUtils::directoryExists($doc_fldv_history_dirname)) {
|
---|
275 | print SDTDERR "Error - The newly formed 'archives' version of document should not contain the existing '$FLDV_HISTORY_DIR' directory:\n";
|
---|
276 | print STDERR " $doc_fldv_history_dirname\n";
|
---|
277 | $status_ok = 0;
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | if ($status_ok) {
|
---|
282 | # Step 5.1
|
---|
283 |
|
---|
284 | # Create _fldv_history in archive doc's dir, ready to take the n -> n copies, starting at n+2 onwards
|
---|
285 | my $mkdir_ok = &FileUtils::makeDirectory($doc_fldv_history_dirname);
|
---|
286 |
|
---|
287 | if ($mkdir_ok) {
|
---|
288 |
|
---|
289 | # If the keepold _fldv_history directory exists, then some prior content to deal with.
|
---|
290 | # As long as there is a nminus-2, then there are sub-folders to copy
|
---|
291 | # Otherwise there is nothing to do for Step 5.1
|
---|
292 |
|
---|
293 | if (&FileUtils::directoryExists($keepold_doc_fldv_history_dirname)) {
|
---|
294 |
|
---|
295 | # Start recursive hardlink copying the directories across n+2 -> n+3 and onwardds
|
---|
296 |
|
---|
297 | my $keepold_matching_dirs = &FileUtils::readDirectoryFiltered($keepold_doc_fldv_history_dirname,undef,"^nminus-\\d+\$");
|
---|
298 |
|
---|
299 | if (scalar(@$keepold_matching_dirs) == 0) {
|
---|
300 | print STDERR "Warning: no 'nminus-<n>' directories found in $FLDV_HISTORY_DIR:\n";
|
---|
301 | print STDERR " $keepold_doc_fldv_history_dirname\n";
|
---|
302 | print STDERR "=> No file-level document-version history content to increase by 1\n";
|
---|
303 | }
|
---|
304 |
|
---|
305 | my @sorted_keepold_matching_dirs = sort {
|
---|
306 | my ($a_num) = ($a =~ m/(\d+)$/);
|
---|
307 | my ($b_num) = ($b =~ m/(\d+)$/);
|
---|
308 |
|
---|
309 | # sort into descending order
|
---|
310 | return $b_num <=> $a_num;
|
---|
311 | } @$keepold_matching_dirs;
|
---|
312 |
|
---|
313 | # want sort order to be higest to lowest, for moving 'n' vals up by one
|
---|
314 |
|
---|
315 | foreach my $nminus_n (@sorted_keepold_matching_dirs) {
|
---|
316 |
|
---|
317 | last if $nminus_n eq "nminus-1";
|
---|
318 |
|
---|
319 | my $keepold_full_dir = &FileUtils::filenameConcatenate($keepold_doc_fldv_history_dirname,$nminus_n);
|
---|
320 | if (-d $keepold_full_dir) {
|
---|
321 |
|
---|
322 | # my ($n) = ($nminus_n =~ m/(\d+)$/);
|
---|
323 |
|
---|
324 | my $full_new_dir = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,$nminus_n);
|
---|
325 |
|
---|
326 | my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_full_dir],$full_new_dir,
|
---|
327 | { 'strict' => 1 } );
|
---|
328 |
|
---|
329 | if (!$hard_link_ok) {
|
---|
330 | print STDERR "Error: Failed to recursive hardlink copy 'nminus-<n>' from 'archives_keepold' to 'archives'\n";
|
---|
331 | $status_ok = 0;
|
---|
332 | last;
|
---|
333 | }
|
---|
334 | }
|
---|
335 | else {
|
---|
336 | print STDERR "Warning: skipping $keepold_full_dir as it is not a directory\n";
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | }
|
---|
341 | }
|
---|
342 | else {
|
---|
343 | print STDERR "Error: failed to make directory:\n";
|
---|
344 | print STDERR " '$doc_fldv_history_dirname'\n";
|
---|
345 |
|
---|
346 | $status_ok = 0;
|
---|
347 | }
|
---|
348 | }
|
---|
349 |
|
---|
350 | my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1");
|
---|
351 |
|
---|
352 |
|
---|
353 | if ($status_ok) {
|
---|
354 |
|
---|
355 | # Step 5.2
|
---|
356 |
|
---|
357 | # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir) to archives as nminus-1
|
---|
358 |
|
---|
359 | my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1");
|
---|
360 |
|
---|
361 | my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_doc_dirname],$doc_fldv_history_dirname_nminus1,
|
---|
362 | { 'strict' => 1, 'exclude_filter_re' => "^$FLDV_HISTORY_DIR\$" } );
|
---|
363 |
|
---|
364 | if (!$hard_link_ok) {
|
---|
365 | print STDERR "Error: Failed to recursively hardlink copy the top-level 'keepold_archives' doc as 'archives' $FLDV_HISTORY_DIR/nminus-1 version\n";
|
---|
366 | $status_ok = 0;
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | if (!$status_ok) {
|
---|
371 | print STDERR "\n";
|
---|
372 | print STDERR "**** A critical error occurred in creating/updating file-level document-version history\n";
|
---|
373 | print STDERR "**** After determining and correcting the cause of the error, to reset, delete\n";
|
---|
374 | print STDERR "**** your 'archives' folder, and move 'archives_keep' back to 'archives'\n";
|
---|
375 | print STDERR "\n";
|
---|
376 | exit 1;
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | sub doc_copy_archivedir_keepold_to_archivedir
|
---|
382 | {
|
---|
383 |
|
---|
384 | my ($keepold_doc_dirname,$doc_dirname) = @_;
|
---|
385 |
|
---|
386 | my $status_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_doc_dirname],$doc_dirname, { 'strict' => 1 } );
|
---|
387 |
|
---|
388 | if (!$status_ok) {
|
---|
389 | print STDERR "Error: Failed to recursively hardlink copy the top-level 'keepold_archives' doc to 'archives'\n";
|
---|
390 | }
|
---|
391 |
|
---|
392 | if (!$status_ok) {
|
---|
393 | print STDERR "\n";
|
---|
394 | print STDERR "**** A critical error occurred in creating/updating file-level document-version history\n";
|
---|
395 | print STDERR "**** After determining and correcting the cause of the error, to reset, delete\n";
|
---|
396 | print STDERR "**** your 'archives' folder, and move 'archives_keep' back to 'archives'\n";
|
---|
397 | print STDERR "\n";
|
---|
398 | exit 1;
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | sub archivedir_keepold_to_archivedir
|
---|
404 | {
|
---|
405 | my ($collectcfg, $keepold,$replaceold,$incremental_mode, $archive_info,$archivedir, $archivedir_keepold) = @_;
|
---|
406 |
|
---|
407 | # Action Step 5 (from inexport.pm)
|
---|
408 |
|
---|
409 | # If needing to turn content in 'archives_keep' into a doc's 'archive' fldv_history/ directory, then
|
---|
410 | # 5.1 a keepold doc's '_fldv_history' goes first
|
---|
411 | # 5.2 then the keepold doc's top-level content for new 'nminus 1'
|
---|
412 |
|
---|
413 | my $perform_firsttime_init = 1;
|
---|
414 | my $arcinfo_keepold_doc_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-doc", $archivedir_keepold, $perform_firsttime_init);
|
---|
415 | # my $arcinfo_keepold_src_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-src", $archivedir_keepold, $perform_firsttime_init);
|
---|
416 |
|
---|
417 | # print STDERR "Creating/Updating archives File-Level Document-Version History (fldv-history) directories:\n";
|
---|
418 | my $status_ok = 1;
|
---|
419 |
|
---|
420 | my $archive_keepold_info = new arcinfo($collectcfg->{'infodbtype'});
|
---|
421 | $archive_keepold_info->load_info($arcinfo_keepold_doc_filename);
|
---|
422 |
|
---|
423 | my $archive_keepold_oidinfo_list = $archive_keepold_info->get_OID_list();
|
---|
424 |
|
---|
425 | foreach my $keepold_info_array (@$archive_keepold_oidinfo_list) {
|
---|
426 |
|
---|
427 | my $keepold_OID = $keepold_info_array->[0];
|
---|
428 | my $keepold_doc_file = $keepold_info_array->[1];
|
---|
429 | my $keepold_index_status = $keepold_info_array->[2];
|
---|
430 |
|
---|
431 | # Work through all entries in arcinfo_keepold doc-id entries:
|
---|
432 | #
|
---|
433 | # (1) if archive_info entry is marked for deletion (D)
|
---|
434 | # => Do nothing
|
---|
435 | # This will result in archive_keep and archives versions being wiped
|
---|
436 | # (respectively after import.pl and buildcol.pl
|
---|
437 | #
|
---|
438 | # (2) if -keepold on
|
---|
439 | # => move 'archives_keepold' doc's _fldv_history folder to 'archives' version
|
---|
440 | # shuffle all the numbers down by one
|
---|
441 | # move the 'archives_keepold' doc's folder to be the archives _fldv-history/nminus-1
|
---|
442 | #
|
---|
443 | # (3) if -replaceold on
|
---|
444 | # => then a similar process to (2), except the 'archives_keepold'
|
---|
445 | # doc folder (without its fldv-history folder), directly replaces the
|
---|
446 | # the 'nminus-1' folder in the 'archives' doc's 'fldv-history' folder
|
---|
447 |
|
---|
448 |
|
---|
449 | # Indexing cases to consider:
|
---|
450 | # I = needs to be Indexed
|
---|
451 | # R = needs to be Reindexed
|
---|
452 | # D = needs to be Deleted
|
---|
453 | # B = has Been indexed
|
---|
454 | #
|
---|
455 | # Specifics of what to do for (2) and (3) dependant at times incremental_mode
|
---|
456 | print STDERR "Document Versioning: Processing $keepold_OID\n";
|
---|
457 |
|
---|
458 | my $oid_info_array = $archive_info->get_info($keepold_OID);
|
---|
459 |
|
---|
460 | if (defined $oid_info_array) {
|
---|
461 |
|
---|
462 | my $doc_file = $oid_info_array->[0];
|
---|
463 | my $index_status = $oid_info_array->[1];
|
---|
464 | # For completeness, the other position in oid_info_array are
|
---|
465 | # ->[2] is sort_meta
|
---|
466 | # ->[3] is group_position
|
---|
467 |
|
---|
468 | # **** Need additional work if -groupsize option > 1 is to be supported!
|
---|
469 | # **** otherwise need to have earlier test to prevent -groupsize > 1 from been used with fldv-history
|
---|
470 |
|
---|
471 | my $keepold_doc_filename = &FileUtils::filenameConcatenate($archivedir_keepold, $keepold_doc_file);
|
---|
472 | my $keepold_doc_dirname = &util::get_parent_folder($keepold_doc_filename);
|
---|
473 |
|
---|
474 | my $doc_filename = &FileUtils::filenameConcatenate($archivedir, $doc_file);
|
---|
475 | my $doc_dirname = &util::get_parent_folder($doc_filename);
|
---|
476 |
|
---|
477 | if ($index_status eq "D") {
|
---|
478 | #
|
---|
479 | # (1) if archive_info entry marked for deletion (D)
|
---|
480 | #
|
---|
481 |
|
---|
482 | # Even though delete is the ultimate outcome for this doc/dir, due to moving 'archives' to 'archives_keep' at the very start of import.pl
|
---|
483 | # we need to recursively hardlink copy it back, so the rest of the incremental import.pl process can work as expected
|
---|
484 | doc_copy_archivedir_keepold_to_archivedir($keepold_doc_dirname,$doc_dirname);
|
---|
485 |
|
---|
486 | print STDERR " The latest version of $keepold_OID is marked for deletion\n";
|
---|
487 | print STDERR " => nothing to do right now (will be deleted when buildcol.pl run)\n";
|
---|
488 | }
|
---|
489 | else {
|
---|
490 | if ($keepold) {
|
---|
491 | #
|
---|
492 | # (2) if -keepold on
|
---|
493 | #
|
---|
494 |
|
---|
495 | # Still need to consider: I, R, B
|
---|
496 | # R => always trigger store doc-history
|
---|
497 | # I => always trigger store doc-history
|
---|
498 | # B => trigger store doc-history if incremental_mode != "all"
|
---|
499 |
|
---|
500 | if ($index_status eq "R") {
|
---|
501 | print STDERR " Updated version of document from import directory (Index-Status=R)\n";
|
---|
502 | print STDERR " => keepold: storing snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
503 | prepend_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
504 | }
|
---|
505 | elsif ($index_status eq "I") {
|
---|
506 |
|
---|
507 | if (!&FileUtils::directoryExists($doc_dirname)) {
|
---|
508 | # This can happen if import.pl has been run twice in a row , without buildcol.pl
|
---|
509 | #
|
---|
510 | # Specifics: In the case that the second import.pl run is incremental, then previous "I" entries
|
---|
511 | # from the first import.pl have not been processed by buildcol.pl and turned into "B" entries.
|
---|
512 | # However, if existing "I" entries have not been modified between the first and second import.pl
|
---|
513 | # then there is is no 'doc_dirname' that has been created in the newly formed archives. Further,
|
---|
514 | # the archives_keepold version isn't an example of a document that needs a "fldv" bump.
|
---|
515 |
|
---|
516 | # long description to say, that basically we want to treat the situation like a "B", that
|
---|
517 | # it's been index
|
---|
518 |
|
---|
519 | print STDERR " Unchanged version of document in 'archives/' however (Index-Status=I not B)\n";
|
---|
520 | print STDERR " This can occur if two consecutive import.pl's have been run, without a buildcol.pl inbetween\n";
|
---|
521 | print STDERR " => Recusirvely copying the archives_keepold/ doc across verbatim to archives/\n";
|
---|
522 | print STDERR " (effectively treating as a 'B')\n";
|
---|
523 |
|
---|
524 | doc_copy_archivedir_keepold_to_archivedir($keepold_doc_dirname,$doc_dirname);
|
---|
525 | }
|
---|
526 | else {
|
---|
527 | print STDERR " Newly generated version of document from 'import/' of existing document from 'archives/' (Index-Status=I)\n";
|
---|
528 | print STDERR " => keepold: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
529 |
|
---|
530 | prepend_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
531 | }
|
---|
532 | }
|
---|
533 | elsif ($index_status eq "B") {
|
---|
534 | # This doc's archive doc folder hasn't change, but due to moving 'archives' to 'archives_keep' at the very start of import.pl
|
---|
535 | # we need to recursively hardlink copy it back
|
---|
536 |
|
---|
537 | doc_copy_archivedir_keepold_to_archivedir($keepold_doc_dirname,$doc_dirname);
|
---|
538 |
|
---|
539 | if ($incremental_mode ne "all") {
|
---|
540 | print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n";
|
---|
541 | print STDERR " => keepold without incremental: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
542 | prepend_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
543 | }
|
---|
544 | else {
|
---|
545 | print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n";
|
---|
546 | print STDERR " => no snapshot store needed when in incremental mode\n";
|
---|
547 | }
|
---|
548 | }
|
---|
549 | }
|
---|
550 | elsif ($replaceold) {
|
---|
551 | #
|
---|
552 | # (3) if -replaceold on
|
---|
553 | #
|
---|
554 |
|
---|
555 | # Still need to consider: I, R, B
|
---|
556 | # R => always trigger replace nminus-1 doc-history
|
---|
557 | # I => always trigger replace nminus-1 doc-history
|
---|
558 | # B => trigger replace nminus-1 doc-history if incremental_mode != "all"
|
---|
559 |
|
---|
560 | if ($index_status eq "R") {
|
---|
561 | print STDERR " Updated version of document from import directory (Index-Status=R)\n";
|
---|
562 | print STDERR " => replaceold: replacing snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
563 | replace_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
564 | }
|
---|
565 | elsif ($index_status eq "I") {
|
---|
566 |
|
---|
567 | if (!&FileUtils::directoryExists($doc_dirname)) {
|
---|
568 | # This can happen if import.pl has been run twice in a row , without buildcol.pl
|
---|
569 | #
|
---|
570 | # For explanation see above 'I' entry for -keepold
|
---|
571 | #
|
---|
572 | # Basically we want to treat the situation like a "B", that it's been index
|
---|
573 |
|
---|
574 | print STDERR " Unchanged version of document in 'archives/' however (Index-Status=I not B)\n";
|
---|
575 | print STDERR " This can occur if two consecutive import.pl's have been run, without a buildcol.pl inbetween\n";
|
---|
576 | print STDERR " => Recusirvely copying the archives_keepold/ doc across verbatim to archives/\n";
|
---|
577 | print STDERR " (effectively treating as a 'B')\n";
|
---|
578 |
|
---|
579 | doc_copy_archivedir_keepold_to_archivedir($keepold_doc_dirname,$doc_dirname);
|
---|
580 | }
|
---|
581 | else {
|
---|
582 | print STDERR " Newly generated version of document from 'import/' of existing document from 'archives/' (Index-Status=I)\n";
|
---|
583 | print STDERR " => keepold: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
584 | replace_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
585 | }
|
---|
586 | }
|
---|
587 | elsif ($index_status eq "B") {
|
---|
588 | if ($incremental_mode ne "all") {
|
---|
589 | print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n";
|
---|
590 | print STDERR " => keepold without incremental: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n";
|
---|
591 | replace_document_version($keepold_doc_dirname,$doc_dirname);
|
---|
592 | }
|
---|
593 | else {
|
---|
594 | print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n";
|
---|
595 | print STDERR " => no snapshot store needed when in incremental mode\n";
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|
599 |
|
---|
600 | }
|
---|
601 | else {
|
---|
602 | print STDERR "**** Error: Encountered a condition for $keepold_OID that was not expected\n";
|
---|
603 | }
|
---|
604 | }
|
---|
605 |
|
---|
606 | }
|
---|
607 | else {
|
---|
608 | print STDERR "**** Error: Did not find 'archives/' matching document for 'archives_keepold/' OID=$keepold_OID\n";
|
---|
609 | print STDERR "Skipping!\n";
|
---|
610 | }
|
---|
611 | }
|
---|
612 |
|
---|
613 | if ($status_ok) {
|
---|
614 | &FileUtils::removeFilesRecursive($archivedir_keepold);
|
---|
615 | }
|
---|
616 | }
|
---|
617 |
|
---|
618 | 1;
|
---|