Changeset 28211 for main/trunk/greenstone2
- Timestamp:
- 2013-09-04T21:46:07+12:00 (11 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/arcinfo.pm
r27697 r28211 143 143 144 144 foreach my $file ( keys %$infodb_map ) { 145 # turn placeholders in the file keys of archiveinf-src file back to absolute paths 146 $file = &util::placeholders_to_abspath($file); 145 147 $self->{'prev_import_filelist'}->{$file} = 1; 146 148 } … … 176 178 177 179 foreach my $srcfile ( keys %$rev_infodb_map ) { 180 178 181 my $vals = $rev_infodb_map->{$srcfile}; 182 183 $srcfile = &util::abspath_to_placeholders($srcfile); 179 184 180 185 foreach my $OID ($vals =~ m/^<oid>(.*)$/gm) { … … 251 256 foreach my $key ( keys %$rev_infodb_map ) { 252 257 my $val_hash = $rev_infodb_map->{$key}; 258 259 $key = &util::abspath_to_placeholders($key); 260 253 261 &dbutil::write_infodb_entry($self->{'infodbtype'}, $rev_infodb_handle, $key, $val_hash); 254 262 } -
main/trunk/greenstone2/perllib/cgiactions/explodeaction.pm
r26567 r28211 135 135 136 136 if (defined $src_files) { 137 foreach my $if (@$src_files) { 138 $all_import_file_keys{$if} = 1; 137 foreach my $ifile (@$src_files) { 138 $ifile = &util::placeholders_to_abspath($ifile); 139 $all_import_file_keys{$ifile} = 1; 139 140 } 140 141 } 141 142 142 143 if (defined $assoc_files) { 143 foreach my $if (@$assoc_files) { 144 $all_import_file_keys{$if} = 1; 144 foreach my $ifile (@$assoc_files) { 145 $ifile = &util::placeholders_to_abspath($ifile); 146 $all_import_file_keys{$ifile} = 1; 145 147 } 146 148 } … … 175 177 my %all_oid_keys = (); 176 178 177 foreach my $if (@$import_filenames) { 178 $if = &util::upgrade_if_dos_filename($if); 179 180 print STDERR "*** looking import filename key \"$if\"\n"; 181 179 foreach my $ifile (@$import_filenames) { 180 $ifile = &util::upgrade_if_dos_filename($ifile); 181 $ifile = &util::abspath_to_placeholders($ifile); 182 183 print STDERR "*** looking up import filename key \"$ifile\"\n"; 184 182 185 my $src_rec 183 186 = &dbutil::read_infodb_entry($infodb_type, $arcinfo_src_filename, 184 $if); 187 $ifile); 188 185 189 my $oids = $src_rec->{'oid'}; 186 190 -
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r28160 r28211 318 318 # This now stores the full pathname 319 319 my $import_filename = $doc_rec->{'src-file'}->[0]; 320 $import_filename = &util::placeholders_to_abspath($import_filename); 320 321 321 322 # figure out correct metadata.xml file [?] … … 424 425 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 425 426 # This now stores the full pathname 426 my $doc_filename = $doc_rec->{'doc-file'}->[0]; 427 my $doc_filename = $doc_rec->{'doc-file'}->[0]; 427 428 $doc_filename = &util::filename_cat($archive_dir, $doc_filename); 428 429 … … 793 794 # This now stores the full pathname 794 795 $import_filename = $doc_rec->{'src-file'}->[0]; 796 $import_filename = &util::placeholders_to_abspath($import_filename); 795 797 796 798 # figure out correct metadata.xml file [?] … … 2874 2876 # This now stores the full pathname 2875 2877 $import_filename = $doc_rec->{'src-file'}->[0]; 2878 $import_filename = &util::placeholders_to_abspath($import_filename); 2879 2876 2880 } else { # only for set_import_meta, not the case when calling method is set_import_metadata_array 2877 2881 # as the array version of the method doesn't support the -f parameter yet … … 2962 2966 # This now stores the full pathname 2963 2967 $import_filename = $doc_rec->{'src-file'}->[0]; 2968 $import_filename = &util::placeholders_to_abspath($import_filename); 2964 2969 } 2965 2970 … … 3393 3398 # This now stores the full pathname 3394 3399 my $import_filename = $archive_doc_rec->{'src-file'}->[0]; 3400 $import_filename = &util::placeholders_to_abspath($import_filename); 3395 3401 3396 3402 # figure out correct metadata.xml file [?] -
main/trunk/greenstone2/perllib/inexport.pm
r28077 r28211 729 729 &dbutil::read_infodb_file($collectcfg->{'infodbtype'}, $arcinfo_src_filename, $arcinfodb_map); 730 730 foreach my $f (@full_new_files) { 731 my $rel_f = &util::abspath_to_placeholders($f); 732 731 733 # check that we haven't seen it already 732 if (defined $arcinfodb_map->{$ f}) {734 if (defined $arcinfodb_map->{$rel_f}) { 733 735 # TODO make better warning 734 print STDERR "Warning: $f already in src archive, \n";736 print STDERR "Warning: $f ($rel_f) already in src archive, \n"; 735 737 } else { 736 738 $block_hash->{'new_files'}->{$f} = 1; … … 1283 1285 # that this file is used in (note in most cases, it's just one OID) 1284 1286 1285 my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file); 1287 my $relfile = &util::abspath_to_placeholders($file); 1288 1289 my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $relfile); 1286 1290 my $oids = $src_rec->{'oid'}; 1287 1291 my $file_record_deleted = 0; … … 1289 1293 # delete the src record 1290 1294 my $src_infodb_file_handle = &dbutil::open_infodb_write_handle($infodbtype, $arcinfo_src_filename, "append"); 1291 &dbutil::delete_infodb_entry($infodbtype, $src_infodb_file_handle, $ file);1295 &dbutil::delete_infodb_entry($infodbtype, $src_infodb_file_handle, $relfile); 1292 1296 &dbutil::close_infodb_write_handle($infodbtype, $src_infodb_file_handle); 1293 1297 … … 1298 1302 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $oid); 1299 1303 my $doc_source_file = $doc_rec->{'src-file'}->[0]; 1304 $doc_source_file = &util::placeholders_to_abspath($doc_source_file); 1305 1300 1306 if (!&util::filename_is_absolute($doc_source_file)) { 1301 1307 $doc_source_file = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},$doc_source_file); -
main/trunk/greenstone2/perllib/manifest.pm
r27299 r28211 208 208 my @all_files = ($doc_source_file); 209 209 push(@all_files,@$assoc_files) if defined $assoc_files; 210 210 211 211 foreach my $filename (@all_files) { 212 212 213 $filename = &util::placeholders_to_abspath($filename); 214 213 215 if (!&util::filename_is_absolute($filename)) { 214 216 $filename = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},$filename); -
main/trunk/greenstone2/perllib/plugin.pm
r27623 r28211 255 255 # that this file is used in (note in most cases, it's just one OID) 256 256 257 $file = &util::abspath_to_placeholders($file); 257 258 my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file); 258 259 my $oids = $src_rec->{'oid'}; -
main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm
r28022 r28211 878 878 $reverse_lookups->{$real_filename} = 1; 879 879 } 880 ### push(@{$oid_files->{$field}},$full_file); 880 881 if($field =~ m@assoc-file|src-file|meta-file@) { 882 $raw_filename = &util::abspath_to_placeholders($raw_filename); 883 } 884 885 ### push(@{$oid_files->{$field}},$full_file); 881 886 push(@{$oid_files->{$field}},$raw_filename); 882 887 } … … 935 940 936 941 my $doc_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $output_dir); 937 my $src_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-src", $output_dir);942 #my $src_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-src", $output_dir); # var unused in this function or file 938 943 939 944 ##print STDERR "*** To set in db: \n\t$doc_db\n\t$oid\n\t$doc_db_text\n"; … … 982 987 $oid_files->{'doc-file'} = [ $oid_files->{'doc-file'} ]; 983 988 $oid_files->{'index-status'} = [ $oid_files->{'index-status'} ]; 989 $oid_files->{'src-file'} = &util::abspath_to_placeholders($oid_files->{'src-file'}); 984 990 $oid_files->{'src-file'} = [ $oid_files->{'src-file'} ]; 985 991 $oid_files->{'sort-meta'} = [ $oid_files->{'sort-meta'} ]; -
main/trunk/greenstone2/perllib/util.pm
r28177 r28211 824 824 } 825 825 826 if (!defined $ENV{'GREENSTONEHOME'}) { # for GS3, would have been defined in use_site_collection, to GSDL3HOME 827 $ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'}; 828 } 829 826 830 # get and check the collection 827 831 if (!defined($collection) || $collection eq "") { … … 842 846 # are defined 843 847 $ENV{'GSDLCOLLECTION'} = $collection; 848 $ENV{'GSDLCOLLECTHOME'} = $collectdir; 844 849 $ENV{'GSDLCOLLECTDIR'} = &FileUtils::filenameConcatenate($collectdir, $collection); 845 850 … … 868 873 die "GSDL3HOME not set.\n" unless defined $ENV{'GSDL3HOME'}; 869 874 $collectdir = &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'}, "sites", $site, "collect"); 875 } 876 877 if (defined $ENV{'GSDL3HOME'}) { 878 $ENV{'GREENSTONEHOME'} = $ENV{'GSDL3HOME'}; 879 $ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site); 880 } elsif (defined $ENV{'GSDL3SRCHOME'}) { 881 $ENV{'GREENSTONEHOME'} = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "web"); 882 $ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site); 883 } else { 884 print STDERR "*** util::use_site_collection(). Warning: Neither GSDL3HOME nor GSDL3SRCHOME set.\n"; 870 885 } 871 886 … … 1213 1228 my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode 1214 1229 1230 if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists 1231 return $ENV{'GSDLCOLLECTDIR'}; 1232 } 1233 1215 1234 my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection); 1216 1235 … … 1224 1243 # work out the full path to "collect" of this greenstone 2/3 installation 1225 1244 sub get_working_collect_dir { 1226 my ($site) = @_; 1227 1228 if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collect dir exists 1229 return $ENV{'GSDLCOLLECTDIR'}; 1230 } 1231 1232 elsif (defined $site && $site) { # site non-empty, so get default collect dir for GS3 1233 return &FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect"); 1245 my ($site) = @_; 1246 1247 if (defined $ENV{'GSDLCOLLECTHOME'}) { # a predefined collect dir exists 1248 return $ENV{'GSDLCOLLECTHOME'}; 1249 } 1250 1251 if (defined $site && $site) { # site non-empty, so get default collect dir for GS3 1252 1253 if (defined $ENV{'GSDL3HOME'}) { 1254 return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site,"collect"); # web folder 1255 } 1256 elsif (defined $ENV{'GSDL3SRCHOME'}) { 1257 return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site,"collect"); 1258 } 1259 } 1260 1261 elsif (defined $ENV{'SITEHOME'}) { #&FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect"); 1262 return &FileUtils::filenameConcatenate($ENV{'SITEHOME'},"collect"); 1234 1263 } 1235 1264 … … 1239 1268 } 1240 1269 1241 # returns path to current GS3 site. 1242 # Returns "" if $site parameter is empty string, undefined or otherwise false 1243 sub get_site_dir { 1244 my ($site) = @_; 1245 1246 if (defined $ENV{'GSDL3HOME'}) { 1247 return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site); # web folder 1248 } 1249 elsif (defined $ENV{'GSDL3SRCHOME'}) { 1250 return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site); 1251 } 1252 else { # site has no meaning, return "" (covers the case of this subroutine having been called for a GS2 situation) 1253 return ""; 1254 } 1255 } 1256 1257 # returns path to GSDL3HOME if GS3, or GSDLHOME if GS2 1258 sub get_gs_home { 1259 my ($site) = @_; 1260 1261 if (defined $site && $site) { # not undefined or empty string, so GS3 case 1262 if (defined $ENV{'GSDL3HOME'}) { 1263 return $ENV{'GSDL3HOME'}; 1264 } else { 1265 return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web"); 1266 } 1267 } else { 1268 return $ENV{'GSDLHOME'}; 1269 } 1270 } 1271 1272 sub is_abs_path { 1270 sub is_abs_path_this_os { 1273 1271 my ($path) = @_; 1272 1273 # File::Spec loads the module appropriate for the OS 1274 return &FileUtils::isFilenameAbsolute(@_); #return File::Spec->file_name_is_absolute( $path ); 1275 } 1276 1277 1278 sub is_abs_path_any_os { 1279 my ($path) = @_; 1280 1281 # We can have filenames in our DBs that were produced on other OS, so this method exists 1282 # to help identify absolute paths in such cases. 1274 1283 1275 1284 return 1 if($path =~ m@^/@); # full paths begin with forward slash on linux/mac … … 1277 1286 1278 1287 return 0; 1279 1280 # File::Spec loads the module appropriate for the OS, but abs paths in archiveinf-doc.xml may be generated on another OS to this one 1281 #return File::Spec->file_name_is_absolute( $path ); 1282 } 1283 1284 # returns an array of the FULL PATHS to the specific collection given, to the general collect_dir, 1285 # to the site directory if gs3 and to the greenstone home folder (GSDLHOME or GSDL3HOME). 1286 # These elements are returned in this ORDER, in order to allow matching from longest to shortest path. 1287 sub get_common_gs_paths { 1288 1289 my ($site, $qualified_collection_name) = @_; 1290 1291 my $collect_dir = &util::get_working_collect_dir($site); 1292 my $collection_path = ""; 1293 if($qualified_collection_name ne "") { 1294 $collection_path = &util::resolve_collection_dir($collect_dir, $qualified_collection_name, $site); 1295 } 1296 1297 my $site_dir = &util::get_site_dir($site); # returns "" for GS2 1298 my $gs_home = &util::get_gs_home(); # GSDLHOME or GSDL3HOME folder 1299 1300 return ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path 1301 #my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path 1302 #return @gs_paths; 1303 } 1288 } 1289 1304 1290 1305 1291 # This subroutine is for improving portability of Greenstone collections from one OS to another, … … 1316 1302 my $path = shift(@_); # path to convert from absolute to one with placeholders 1317 1303 1318 my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_; 1319 1320 return $path unless is_abs_path($path); # path is relative 1304 return $path unless is_abs_path_any_os($path); # path is relative 1321 1305 1322 1306 # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders 1323 1307 1324 my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path 1325 1326 my %placeholder_map = ($gs_home => '@GSDLHOME@', # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array 1327 $site_dir => '@SITEHOME@', 1328 $collect_dir => '@COLLECTHOME@', 1329 $collection_path => '@THISCOLLECTPATH@' 1308 my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : ""; 1309 my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $site, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path 1310 1311 my %placeholder_map = ($ENV{'GREENSTONEHOME'} => '@GSDLHOME@', # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array 1312 $site => '@SITEHOME@', 1313 $ENV{'GSDLCOLLECTHOME'} => '@COLLECTHOME@', 1314 $ENV{'GSDLCOLLECTDIR'} => '@THISCOLLECTPATH@' 1330 1315 ); 1331 1316 … … 1336 1321 1337 1322 foreach my $gs_path (@gs_paths) { 1323 next if($gs_path eq ""); # site can be empty 1324 1338 1325 my $re_path = &util::filename_to_regex($gs_path); # escape for regex 1339 1326 1340 next if($re_path eq ""); # site can be empty 1341 1342 if($path =~ m/^$re_path/) { # case sensitive or not for OS? 1327 if($path =~ m/^$re_path/i) { # case sensitive or not for OS? 1343 1328 1344 1329 my $placeholder = $placeholder_map{$gs_path}; # get the placeholder to replace the matched path with … … 1358 1343 my $path = shift(@_); # path that can contain placeholders to convert to resolved absolute path 1359 1344 1360 my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_;1361 1362 1345 return $path if($path !~ m/@/); # path contains no placeholders 1363 1346 1364 1347 # replace placeholders with gs prefixes 1365 1348 my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : ""; 1366 1349 my @placeholders = ('@THISCOLLECTPATH@', '@COLLECTHOME@', '@SITEHOME@', '@GSDLHOME@'); # order of paths not crucial in this case, 1367 1350 # but listed here from longest to shortest once placeholders are have been resolved 1368 1351 1369 my %placeholder_to_gspath_map = ('@GSDLHOME@' => $ gs_home, # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array1370 '@SITEHOME@' => $site _dir,1371 '@COLLECTHOME@' => $ collect_dir,1372 '@THISCOLLECTPATH@' => $ collection_path1352 my %placeholder_to_gspath_map = ('@GSDLHOME@' => $ENV{'GREENSTONEHOME'}, # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array 1353 '@SITEHOME@' => $site, 1354 '@COLLECTHOME@' => $ENV{'GSDLCOLLECTHOME'}, 1355 '@THISCOLLECTPATH@' => $ENV{'GSDLCOLLECTDIR'} 1373 1356 ); 1374 1357
Note:
See TracChangeset
for help on using the changeset viewer.