Changeset 37187
- Timestamp:
- 2023-01-27T23:52:38+13:00 (15 months ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/DocHistoryFileUtils.pm
r37149 r37187 38 38 use FileUtils; 39 39 40 my $ fldv_history_dir= "_fldv_history";40 my $FLDV_HISTORY_DIR = "_fldv_history"; 41 41 42 42 sub prepend_document_version 43 43 { 44 44 my ($keepold_doc_dirname,$doc_dirname) = @_; 45 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 46 56 my $status_ok = 1; 47 57 48 my $doc_fldv_history_dirname = &FileUtils::filenameConcatenate($doc_dirname,$fldv_history_dir); 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); 49 60 50 61 if (&FileUtils::directoryExists($doc_fldv_history_dirname)) { 51 # need to shuffle nminus-1, nminus-2 down by one 52 my $matching_dirs = &FileUtils::readDirectoryFiltered($doc_fldv_history_dirname,undef,"^nminus-\\d+\$"); 53 54 my @sorted_matching_dirs = sort { 55 my ($a_num) = ($a =~ m/(\d+)$/); 56 my ($b_num) = ($b =~ m/(\d+)$/); 57 58 # sort into descending order 59 return $b_num <=> $a_num; 60 } @$matching_dirs; 61 62 # want sort order to be higest to lowest, for moving 'n' vals up by one 63 64 foreach my $nminus_n (@sorted_matching_dirs) { 65 66 my $full_dir = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,$nminus_n); 67 if (-d $full_dir) { 68 # print STDERR " Increasing by one the file-level document-version history number for:\n"; 69 # print STDERR " $full_dir\n"; 70 71 my ($n) = ($nminus_n =~ m/(\d+)$/); 72 my $new_n = $n + 1; 73 74 my $full_new_dir = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-$new_n"); 75 76 &FileUtils::moveFiles($full_dir,$full_new_dir); 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 77 134 } 78 135 else { 79 print STDERR " Warning: skipping $full_dir as it is not a directory\n";136 print STDERR "First time file-level document-version history item stored for $doc_fldv_history_dirname\n"; 80 137 } 81 138 } 82 83 } 84 else { 85 my $mkdir_ok = &FileUtils::makeDirectory($doc_fldv_history_dirname); 86 87 if (!$mkdir_ok) { 88 print STDERR "Error: DocHistoryFileUtils::prepend_document_version() failed to make directory:\n"; 89 print STDERR " '$doc_fldv_history_dirname'\n"; 90 139 else { 140 print STDERR "Error: failed to make directory:\n"; 141 print STDERR " '$doc_fldv_history_dirname'\n"; 142 91 143 $status_ok = 0; 92 144 } 93 145 } 94 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 95 229 if ($status_ok) { 96 230 231 # Step 5.2 232 233 # * Recursive hardlink copy the top-level keepold archive's doc (excluding _fldv_history dir) 234 97 235 my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1"); 98 236 99 237 my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_doc_dirname],$doc_fldv_history_dirname_nminus1, 100 { 'strict' => 1, 'exclude_filter_re' => "^$ fldv_history_dir\$" } );101 238 { 'strict' => 1, 'exclude_filter_re' => "^$FLDV_HISTORY_DIR\$" } ); 239 102 240 if (!$hard_link_ok) { 103 print STDERR "Error: DocHistoryFileUtils::prepend_document_version() failed to hardLink\n"; 104 print STDERR " '$keepold_doc_dirname' -> '$doc_fldv_history_dirname_nminus1'\n"; 105 241 print STDERR "Error: Failed to recursively hardlink copy the top-level 'keepold_archives' doc as 'archives' $FLDV_HISTORY_DIR/nminus-1 version\n"; 106 242 $status_ok = 0; 107 } 108 } 109 243 } 244 } 110 245 111 246 if (!$status_ok) { 112 print STDERR "**** Critical error occurred in creating/updating file-level document-version history\n"; 247 print STDERR "\n"; 248 print STDERR "**** A critical error occurred in creating/updating file-level document-version history\n"; 113 249 print STDERR "**** After determining and correcting the cause of the error, to reset, delete\n"; 114 print STDERR "**** your 'archives' folder, and replace it with 'archives_keep'\n"; 250 print STDERR "**** your 'archives' folder, and move 'archives_keep' back to 'archives'\n"; 251 print STDERR "\n"; 115 252 exit 1; 116 253 } … … 120 257 { 121 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' 122 268 123 269 my $status_ok = 1; 124 270 125 my $doc_fldv_history_dirname = &FileUtils::filenameConcatenate($doc_dirname,$fldv_history_dir); 126 my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1"); 127 128 if (!&FileUtils::directoryExists($doc_fldv_history_dirname)) { 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 129 285 my $mkdir_ok = &FileUtils::makeDirectory($doc_fldv_history_dirname); 130 286 131 if (!$mkdir_ok) { 132 print STDERR "Error: DocHistoryFileUtils::replace_document_version() failed to make directory:\n"; 133 print STDERR " '$doc_fldv_history_dirname'\n"; 134 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 135 346 $status_ok = 0; 136 347 } 137 348 } 138 else { 139 # Better to upgrade this method to return a ok_status value 140 &FileUtils::removeFilesRecursive($doc_fldv_history_dirname_nminus1); 141 } 142 349 350 my $doc_fldv_history_dirname_nminus1 = &FileUtils::filenameConcatenate($doc_fldv_history_dirname,"nminus-1"); 351 352 143 353 if ($status_ok) { 144 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 145 361 my $hard_link_ok = &FileUtils::hardlinkFilesRefRecursive([$keepold_doc_dirname],$doc_fldv_history_dirname_nminus1, 146 { 'strict' => 1, 'exclude_filter_re' => "^$fldv_history_dir\$" } ); 362 { 'strict' => 1, 'exclude_filter_re' => "^$FLDV_HISTORY_DIR\$" } ); 363 147 364 if (!$hard_link_ok) { 148 print STDERR "Error: DocHistoryFileUtils::replace_document_version() failed to hardLink\n"; 149 print STDERR " '$keepold_doc_dirname' -> '$doc_fldv_history_dirname_nminus1'\n"; 150 365 print STDERR "Error: Failed to recursively hardlink copy the top-level 'keepold_archives' doc as 'archives' $FLDV_HISTORY_DIR/nminus-1 version\n"; 151 366 $status_ok = 0; 152 } 367 } 153 368 } 154 369 155 370 if (!$status_ok) { 156 print STDERR "**** Critical error occurred in creating/updating file-level document-version history\n"; 371 print STDERR "\n"; 372 print STDERR "**** A critical error occurred in creating/updating file-level document-version history\n"; 157 373 print STDERR "**** After determining and correcting the cause of the error, to reset, delete\n"; 158 print STDERR "**** your 'archives' folder, and replace it with 'archives_keep'\n"; 374 print STDERR "**** your 'archives' folder, and move 'archives_keep' back to 'archives'\n"; 375 print STDERR "\n"; 159 376 exit 1; 160 } 377 } 161 378 } 162 379 … … 167 384 my ($collectcfg, $keepold,$replaceold,$incremental_mode, $archive_info,$archivedir, $archivedir_keepold) = @_; 168 385 386 # Action Step 5 (from inexport.pm) 387 388 # 5.1 a keepold doc's '_fldv_history' goes first 389 # 5.2 then the keepold doc's top-level content for new 'nminus 1' 390 169 391 my $perform_firsttime_init = 1; 170 392 my $arcinfo_keepold_doc_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-doc", $archivedir_keepold, $perform_firsttime_init); … … 184 406 my $keepold_doc_file = $keepold_info_array->[1]; 185 407 my $keepold_index_status = $keepold_info_array->[2]; 186 187 408 188 409 # Work through all entries in arcinfo_keepold doc-id entries: 189 #190 # If keepold entry does *not* exist in (the more up to date) archive_info191 # => print out an error. This should not happen!192 193 # If keepold entry *does* exist in (the more up to date) archive_info194 410 # 195 411 # (1) if archive_info entry is marked for deletion (D) … … 199 415 # 200 416 # (2) if -keepold on 201 # => Use hard-linking to turn 'archives_keepold' doc folder 202 # (without its fldv-history folder) into fldv-history/nminus-1 in the 203 # the 'archives' doc folder, having first shuffled any existing 204 # nminus-1, nminus-2 folders down by one value 417 # => move 'archives_keepold' doc's _fldv_history folder to 'archives' version 418 # shuffle all the numbers down by one 419 # move the 'archives_keepold' doc's folder to be the archives _fldv-history/nminus-1 205 420 # 206 421 # (3) if -replaceold on … … 258 473 if ($index_status eq "R") { 259 474 print STDERR " Updated version of document from import directory (Index-Status=R)\n"; 260 print STDERR " => keepold: storing snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";475 print STDERR " => keepold: storing snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 261 476 prepend_document_version($keepold_doc_dirname,$doc_dirname); 262 477 } 263 478 elsif ($index_status eq "I") { 264 479 print STDERR " Newly generated version of document from 'import/' of existing document from 'archives/' (Index-Status=I)\n"; 265 print STDERR " => keepold: store snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";480 print STDERR " => keepold: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 266 481 prepend_document_version($keepold_doc_dirname,$doc_dirname); 267 482 } … … 269 484 if ($incremental_mode ne "all") { 270 485 print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n"; 271 print STDERR " => keepold without incremental: store snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";486 print STDERR " => keepold without incremental: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 272 487 prepend_document_version($keepold_doc_dirname,$doc_dirname); 273 488 } … … 290 505 if ($index_status eq "R") { 291 506 print STDERR " Updated version of document from import directory (Index-Status=R)\n"; 292 print STDERR " => replaceold: replacing snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";507 print STDERR " => replaceold: replacing snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 293 508 replace_document_version($keepold_doc_dirname,$doc_dirname); 294 509 } 295 510 elsif ($index_status eq "I") { 296 511 print STDERR " Newly generated version of document from 'import/' of existing document from 'archives/' (Index-Status=I)\n"; 297 print STDERR " => keepold: store snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";512 print STDERR " => keepold: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 298 513 replace_document_version($keepold_doc_dirname,$doc_dirname); 299 514 } … … 301 516 if ($incremental_mode ne "all") { 302 517 print STDERR " Unchanged version of document in 'archives/' (Index-Status=B)\n"; 303 print STDERR " => keepold without incremental: store snapshot of previous version in $ fldv_history_diras 'nminus-1'\n";518 print STDERR " => keepold without incremental: store snapshot of previous version in $FLDV_HISTORY_DIR as 'nminus-1'\n"; 304 519 replace_document_version($keepold_doc_dirname,$doc_dirname); 305 520 } -
main/trunk/greenstone2/perllib/FileUtils.pm
r37151 r37187 120 120 # internal version that copies a file or a group of files 121 121 # 122 sub _copyFilesGeneral122 sub copyFilesGeneral 123 123 { 124 124 my ($srcfiles_ref,$dest,$options) = @_; … … 137 137 if (scalar(@$srcfiles_ref) == 0) 138 138 { 139 print STDERR "FileUtils:: _copyFilesGeneral() no destination directory given\n";139 print STDERR "FileUtils::copyFilesGeneral() no destination directory given\n"; 140 140 return 0; 141 141 } 142 142 elsif ((scalar(@$srcfiles_ref) > 1) && (!-d $dest)) 143 143 { 144 print STDERR "FileUtils:: _copyFilesGeneral() if multiple source files are given the destination must be a directory\n";144 print STDERR "FileUtils::copyFilesGeneral() if multiple source files are given the destination must be a directory\n"; 145 145 return 0; 146 146 } … … 159 159 if (!-e $file) 160 160 { 161 print STDERR "FileUtils:: _copyFilesGeneral() $file does not exist\n";161 print STDERR "FileUtils::copyFilesGeneral() $file does not exist\n"; 162 162 $had_an_error = 1; 163 163 if ($strict) { … … 167 167 elsif (!-f $file) 168 168 { 169 print STDERR "FileUtils:: _copyFilesGeneral() $file is not a regular file\n";169 print STDERR "FileUtils::copyFilesGeneral() $file is not a regular file\n"; 170 170 $had_an_error = 1; 171 171 if ($strict) { … … 181 181 if (!link($file, $tempdest)) 182 182 { 183 print STDERR "Warning: FileUtils:: _copyFilesGeneral(): unable to create hard link. ";183 print STDERR "Warning: FileUtils::copyFilesGeneral(): unable to create hard link. "; 184 184 print STDERR " Attempting file copy: $file -> $tempdest\n"; 185 185 $success = &File::Copy::copy($file, $tempdest); … … 195 195 196 196 if (!$success) { 197 print STDERR "FileUtils:: _copyFilesGeneral() failed to copy $file -> $tempdest\n";197 print STDERR "FileUtils::copyFilesGeneral() failed to copy $file -> $tempdest\n"; 198 198 $had_an_error = 1; 199 199 … … 226 226 my (@srcfiles) = @_; 227 227 228 return & _copyFilesGeneral(\@srcfiles,$dest,undef);228 return ©FilesGeneral(\@srcfiles,$dest,undef); 229 229 } 230 230 … … 306 306 my $strict = 0; 307 307 my $make_fullpath = 0; 308 my $exclude_dirs = 0; 309 my $exclude_files = 0; 308 310 my $exclude_filter_re = undef; 309 311 my $include_filter_re = undef; … … 312 314 $strict = $options->{'strict'} if defined $options->{'strict'}; 313 315 $make_fullpath = $options->{'make_fullpath'} if defined $options->{'make_fullpath'}; 316 $exclude_dirs = $options->{'exclude_dirs'} if defined $options->{'exclude_dirs'}; 317 $exclude_files = $options->{'exclude_files'} if defined $options->{'exclude_files'}; 314 318 $exclude_filter_re = $options->{'exclude_filter_re'} if defined $options->{'exclude_filter_re'}; 315 319 $include_filter_re = $options->{'include_filter_re'} if defined $options->{'include_filter_re'}; … … 330 334 { 331 335 next if $f_or_d =~ /^\.\.?$/; 336 next if $exclude_dirs && -d &filenameConcatenate($src_dir_fullpath, $f_or_d); 337 next if $exclude_files && -f &filenameConcatenate($src_dir_fullpath, $f_or_d); 332 338 next if (defined $exclude_filter_re && ($f_or_d =~ m/$exclude_filter_re/)); 333 339 … … 556 562 { 557 563 my $fullpath_subf = $fullpath_subf_or_subd; 558 my $ret_val_success = & _copyFilesGeneral([$fullpath_subf],$dest,$options);564 my $ret_val_success = ©FilesGeneral([$fullpath_subf],$dest,$options); 559 565 560 566 if ($ret_val_success == 0) { … … 585 591 else 586 592 { 587 my $ret_val_success = & _copyFilesGeneral([$file], $dest, $options);593 my $ret_val_success = ©FilesGeneral([$file], $dest, $options); 588 594 if ($ret_val_success == 0) { 589 595 … … 1487 1493 ## moveFiles() 1488 1494 1495 1496 ## @function renameDirectory() 1497 # 1498 # rename a directory 1499 # (effectively a move, where the destination name cannot already exist) 1500 # 1501 sub renameDirectory 1502 { 1503 my ($srcdir,$dstdir) = @_; 1504 1505 my $had_an_error = 0; 1506 1507 if (!-d $srcdir) { 1508 print STDERR "FileUtils::renameDirectory() Error - Source name must be an existing directory\n"; 1509 print STDERR "Source name was: $srcdir\n"; 1510 $had_an_error = 1; 1511 } 1512 elsif (-e $dstdir) { 1513 print STDERR "FileUtils::renameDirectory() Error - Destination name must not already exist\n"; 1514 print STDERR "Destination name was: $dstdir\n"; 1515 $had_an_error = 1; 1516 1517 } 1518 else { 1519 if (!rename($srcdir,$dstdir)) { 1520 print STDERR "FileUtils::renameDirectory() -- Error occured moving source name to destination name\n"; 1521 print STDERR "Source name was: $srcdir\n"; 1522 print STDERR "Destination name was: $dstdir\n"; 1523 $had_an_error = 1; 1524 } 1525 } 1526 1527 if ($had_an_error) { 1528 return 0; # i.e., not OK! 1529 } 1530 else { 1531 return 1; 1532 } 1533 } 1534 ## renameDirectory() 1535 1489 1536 ## @function openFileHandle() 1490 1537 # -
main/trunk/greenstone2/perllib/arcinfo.pm
r37150 r37187 65 65 66 66 my $self = {'infodbtype' => $infodbtype, 67 'info'=>{}, 68 'reverse-info'=>{}, 69 'order'=>[], 70 'reverse_sort'=>0, 71 'sort'=>0}; 67 'timestamp_file' => "archiveinf-timestamp.out", 68 'info' => {}, 69 'reverse-info'=> {}, 70 'order' => [], 71 'reverse_sort'=> 0, 72 'sort' => 0}; 72 73 73 74 return bless $self, $class; … … 93 94 close (INFILE); 94 95 } 95 96 97 96 } 98 97 … … 123 122 my ($filename) = @_; 124 123 124 my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1); 125 print STDERR "\n\n!!!!!!!!!!!! load_info() -- Calling method: $cfilename:$cline $cpackage->$csubr\n\n"; 126 125 127 $self->{'info'} = {}; 126 128 127 if ((defined $filename) && &FileUtils::fileExists($filename)) { 128 if ($filename =~ m/\.inf$/) { 129 $self->_load_info_txt($filename); 130 } 131 else { 132 $self->_load_info_db($filename); 133 } 134 } 129 if (defined $filename) { 130 131 my $timestamp_filename = $self->get_timestamp_filename($filename); 132 if (&FileUtils::fileExists($timestamp_filename)) { 133 my ($prev_infodbtype,$unused_timestamp) = $self->load_timestamp($filename); 134 $self->{'prev-infodbtype'} = $prev_infodbtype; 135 } 136 137 if (!&FileUtils::fileExists($filename)) { 138 # Typically a sign of a first-time, or -removeold build 139 140 # ... but could be because the value of infodbtype has changed since the last build 141 # => Check 142 143 my $prev_infodbtype = $self->{'prev-infodbtype'}; 144 my $infodbtype = $self->{'infodbtype'}; 145 146 if (defined $prev_infodbtype && ($prev_infodbtype ne $infodbtype)) { 147 print STDERR "arcinfo::load_info() detected change in infodbtype from previous build: $prev_infodbtype -> $infodbtype\n"; 148 print STDERR "=> adjusting archiveinf filename accordingly.\n"; 149 150 $filename =~ s/\.$infodbtype$/.$prev_infodbtype/; 151 } 152 } 153 154 # $filename might have changed if infodbtypes don't match 155 if (&FileUtils::fileExists($filename)) { 156 if ($filename =~ m/\.inf$/) { 157 $self->_load_info_txt($filename); 158 } 159 else { 160 $self->_load_info_db($filename); 161 } 162 } 163 } 135 164 } 136 165 … … 274 303 sub save_info { 275 304 my $self = shift (@_); 276 my ($filename) = @_; 277 278 if ($filename =~ m/(contents)|(\.inf)$/) { 279 $self->_save_info_txt($filename); 305 my ($arcinfo_filename) = @_; 306 307 308 if ($arcinfo_filename =~ m/(contents)|(\.inf)$/) { 309 $self->_save_info_txt($arcinfo_filename); 280 310 } 281 311 else { 282 $self->_save_info_db($filename); 283 } 284 } 312 $self->_save_info_db($arcinfo_filename); 313 } 314 } 315 316 317 318 sub get_timestamp_filename 319 { 320 my $self = shift (@_); 321 my ($arcinfo_doc_filename) = @_; 322 323 my $arcinfo_dirname = &File::Basename::dirname($arcinfo_doc_filename); 324 325 my $timestamp_filename = &FileUtils::filenameConcatenate($arcinfo_dirname, $self->{'timestamp_file'}); 326 327 return $timestamp_filename; 328 } 329 330 331 sub load_timestamp 332 { 333 my $self = shift (@_); 334 my ($arcinfo_doc_filename) = @_; 335 336 my $arcinfo_timestamp_filename = $self->get_timestamp_filename($arcinfo_doc_filename); 337 338 my $timestamp_infodbtype = undef; 339 my $arcinfo_timestamp = undef; 340 341 if (-f $arcinfo_timestamp_filename) { 342 if (open(ARCINFTS_IN,"<$arcinfo_timestamp_filename")) { 343 my $line = <ARCINFTS_IN>; 344 chomp $line; 345 close(ARCINFTS_IN); 346 347 ($timestamp_infodbtype,$arcinfo_timestamp) = ($line =~ m/^\s*(\w+)\s*:\s*(\d+)\s*$/) 348 } 349 else { 350 print STDERR "Error - failed to read:\n"; 351 print STDERR " $arcinfo_timestamp_filename\n"; 352 } 353 } 354 355 return ($timestamp_infodbtype,$arcinfo_timestamp); 356 } 357 358 359 sub save_arcinfo_doc_timestamp 360 { 361 my $self = shift (@_); 362 my ($arcinfo_doc_filename) = @_; 363 print STDERR "\n\n!!!!!!!!!! SAVE save_arcinfo_doc_timestamp()\n\n"; 364 365 my $arcinfo_timestamp_filename = $self->get_timestamp_filename($arcinfo_doc_filename); 366 367 my $infodbtype = $self->{'infodbtype'}; 368 369 # Before recording the current infodbtype type and timestamp 370 # handle the case of prev_infodbtype being different to infodbyte 371 # => mothball the prev_infodbtype as a backup file 372 373 my $prev_infodbtype = $self->{'prev-infodbtype'}; 374 if ((defined $prev_infodbtype) && ($prev_infodbtype ne $infodbtype)) { 375 my ($arcinfo_tailname, $arcinfo_dirname, $arcinfo_suffix) 376 = &File::Basename::fileparse($arcinfo_doc_filename, "\\.[^\\.]+\$"); 377 378 my $prev_arcinfo_filename = &dbutil::get_infodb_file_path($prev_infodbtype,$arcinfo_tailname,$arcinfo_dirname); 379 my $backup_arcinfo_filename = $prev_arcinfo_filename; 380 $backup_arcinfo_filename =~ s/\.$prev_infodbtype$/.bak.$prev_infodbtype/; 381 382 print STDERR "As a result of infodbtype changing from $prev_infodbtype -> $infodbtype\n"; 383 print STDERR "=> Making a backup copy of $prev_arcinfo_filename\n"; 384 &dbutil::rename_db_file_to($prev_infodbtype,$prev_arcinfo_filename,$backup_arcinfo_filename); 385 386 } 387 388 # Could consider taking the the timestamp of the file itself ??? 389 # e.g. $arcinfo_timestamp = -M $arcinfo_filename; 390 # But for now base this on a 'live' reading 391 my $arcinfo_timestamp = time(); 392 393 if (open(ARCINFTS_OUT,">$arcinfo_timestamp_filename")) { 394 print ARCINFTS_OUT "$infodbtype:$arcinfo_timestamp\n"; 395 396 close(ARCINFTS_OUT); 397 } 398 else { 399 print STDERR "Error - failed to write:\n"; 400 print STDERR " $arcinfo_timestamp_filename\n"; 401 } 402 } 403 285 404 286 405 sub delete_info { -
main/trunk/greenstone2/perllib/inexport.pm
r37178 r37187 521 521 my $archivedir = $self->{'archivedir'} || $self->{'exportdir'}; 522 522 # 'archivedir' is a tad abused, and is sometimes set to the 'exportdir' value, 523 # meaining 'archivedir_keepold' is actually the export dir name with '_keepold' appended523 # however at this stage in the code development'archivedir_keepold' is only associated with archivedir (used to provide fldv-history) 524 524 my $archivedir_keepold = $self->{'archivedir_keepold'}; 525 525 … … 655 655 else { 656 656 # If not $removeold, then must be $keepold or $replaceold 657 # => for either case want to "hard-link"/copy 'archives' to 'archives_keepold' 658 659 # Want to be super careful about doing this, so as not to accidentally 660 # wipe out any previous file-level document-version history 661 657 # => for either case the sequence to go through is: 658 # 659 # 1. Move 'archives' to 'archives_keepold' 660 # 2. Create new empty 'archives' 661 # 3. Copy top-level files in 'archives_keepold' to 'archives'; 662 # 4. Allow 'import' to populate 'archives' as usual 663 # 664 # 5. Resolve file-level document-verison history through 665 # "hard-link"/copy content from 'archives_keep' back to 'archives' 666 # 5.1 a keepold doc's '_fldv_history' goes first 667 # 5.2 then the keepold doc's top-level content for new 'nminus 1' 668 669 # Only if all these stages run without a single error then is 670 # it then safe to remove archivedir_keepold 671 672 # If an error occurs, the process is stopped, and deleting 673 # 'archives' and moving 'archives_keepold' restores things 674 # back to how they were before import.pl was run. 675 676 662 677 # If got to here, then there is no pre-existing $archivedir_keepold 663 # => Hard-link copy the contents of 'archives' to 'archives_keepold'664 # => Stop if there is any issue with creating the hard-link copy 665 666 if (! &FileUtils::hardlinkFilesRefRecursive([$archivedir],$archivedir_keepold, { 'strict' => 1 })) {667 678 # Action Step 1. 679 680 681 if (!rename($archivedir,$archivedir_keepold)) { 682 668 683 &gsprintf(STDERR, "\nError message: $!\n\n"); 669 684 670 &gsprintf(STDERR, "**** Failed to m ake a hard-link copy of:\n");685 &gsprintf(STDERR, "**** Failed to move:\n"); 671 686 &gsprintf(STDERR, "**** $archivedir\n"); 672 687 &gsprintf(STDERR, "**** to:\n"); … … 679 694 } 680 695 681 # create the archives dir if needed 696 # Create the archives dir if needed 697 # coincidentally fldv-history: Action Step 2 682 698 &FileUtils::makeAllDirectories($archivedir); 683 699 684 # read the archive information file 685 700 if ($keepold || $replaceold) { 701 # fldv-history: Action Step 3 702 703 my ($ret_val_success,$fullpath_files) = &FileUtils::readdirFullpath($archivedir_keepold, { 'strict' => 1, 'exclude_dirs' => 1 }); 704 705 my $copy_ok = &FileUtils::copyFilesGeneral($fullpath_files,$archivedir, { 'strict' => 1 }); 706 if (!$copy_ok) { 707 &gsprintf(STDERR, "**** Failed to copy top-leve files from:\n"); 708 &gsprintf(STDERR, "**** $archivedir_keepold\n"); 709 &gsprintf(STDERR, "**** to:\n"); 710 &gsprintf(STDERR, "**** $archivedir\n"); 711 &gsprintf(STDERR, "****\n"); 712 &gsprintf(STDERR, "**** Unable to proceed with file-level document-version history $inexport_mode => Stopping\n"); 713 714 exit 1; 715 } 716 717 print STDERR "\n\n\n"; 718 print STDERR "*****!!!!! No easy way in perl to perform file copy and perserve timestamps\n"; 719 print STDERR "*****!!!!! SO => need to implement file with timestamp within (and DBinfo type for good measure)\n"; 720 print STDERR "*****!!!!! and change plugin/incremental building that depends on/uses -M \n"; 721 # ArchiveInfoPlugin, DirectoryPlugin inexport.pm, arcinfo.pma 722 # DirectoryPlugin inexport.pm, arcinfo.pm (convertutil.pm OK, as working on the two files passed to it) 723 print STDERR "\n\n\n"; 724 } 725 726 727 # Read the archive information file 728 # coincidentally fldv-history: Action Step 4 729 686 730 # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes) 687 731 &util::rename_ldb_or_bdb_file(&FileUtils::filenameConcatenate($archivedir, "archiveinf-doc")); … … 1103 1147 $archive_info->save_revinfo_db($arcinfo_src_filename); 1104 1148 } 1149 1150 $archive_info->save_arcinfo_doc_timestamp($arcinfo_doc_filename); 1105 1151 } 1106 1152 … … 1111 1157 1112 1158 if ($keepold || $replaceold) { 1159 1160 # fldv-history: Action Step 5 1113 1161 1114 1162 &DocHistoryFileUtils::archivedir_keepold_to_archivedir($collectcfg, $keepold, $replaceold, $incremental_mode, $archive_info, $archivedir,$archivedir_keepold); … … 1290 1338 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archivedir); 1291 1339 1292 my $archiveinf_timestamp = -M $arcinfo_doc_filename; 1340 #my $archiveinf_timestamp = -M $arcinfo_doc_filename; 1341 my ($unused_infodbtype,$archiveinf_timestamp) = $archive_info->load_timestamp($arcinfo_doc_filename); 1293 1342 1294 1343 # First convert all files to absolute form … … 1609 1658 1610 1659 1660 1661 1611 1662 1; -
main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm
r36372 r37187 136 136 $infodbtype = "gdbm" if $infodbtype eq "gdbm-txtgz"; # in archives, cannot use txtgz version 137 137 my $output_dir = $processor->getoutputdir(); 138 my $archives_inf = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $output_dir); 139 140 if ( -e $archives_inf ) { 141 $self->{'inf_timestamp'} = -M $archives_inf; 138 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $output_dir); 139 140 if ( -e $arcinfo_doc_filename ) { 141 my $archive_info = new arcinfo($infodbtype); 142 my ($unused_infodbtype,$archiveinf_timestamp) = $archive_info->load_timestamp($arcinfo_doc_filename); 143 144 # $self->{'inf_timestamp'} = -M $archives_inf; 145 $self->{'inf_timestamp'} = $archiveinf_timestamp; 142 146 } 143 147 }
Note:
See TracChangeset
for help on using the changeset viewer.