Changeset 28211

Show
Ignore:
Timestamp:
04.09.2013 21:46:07 (6 years ago)
Author:
ak19
Message:

No more absolute paths in archiveinf-doc.gdb and archiveinf-src.gdb

Location:
main/trunk/greenstone2/perllib
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/arcinfo.pm

    r27697 r28211  
    143143 
    144144    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); 
    145147    $self->{'prev_import_filelist'}->{$file} = 1; 
    146148    } 
     
    176178 
    177179    foreach my $srcfile ( keys %$rev_infodb_map ) { 
     180 
    178181    my $vals = $rev_infodb_map->{$srcfile}; 
     182 
     183    $srcfile = &util::abspath_to_placeholders($srcfile); 
    179184 
    180185    foreach my $OID ($vals =~ m/^<oid>(.*)$/gm) { 
     
    251256    foreach my $key ( keys %$rev_infodb_map ) { 
    252257    my $val_hash = $rev_infodb_map->{$key}; 
     258 
     259    $key = &util::abspath_to_placeholders($key);     
     260 
    253261    &dbutil::write_infodb_entry($self->{'infodbtype'}, $rev_infodb_handle, $key, $val_hash); 
    254262    } 
  • main/trunk/greenstone2/perllib/cgiactions/explodeaction.pm

    r26567 r28211  
    135135     
    136136    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; 
    139140        } 
    140141    } 
    141142 
    142143    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; 
    145147        } 
    146148    } 
     
    175177    my %all_oid_keys = (); 
    176178 
    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     
    182185    my $src_rec 
    183186        = &dbutil::read_infodb_entry($infodb_type, $arcinfo_src_filename,  
    184                      $if); 
     187                     $ifile); 
     188 
    185189    my $oids = $src_rec->{'oid'}; 
    186190 
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r28160 r28211  
    318318        # This now stores the full pathname 
    319319        my $import_filename = $doc_rec->{'src-file'}->[0]; 
     320        $import_filename = &util::placeholders_to_abspath($import_filename); 
    320321 
    321322        # figure out correct metadata.xml file [?] 
     
    424425        my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 
    425426        # This now stores the full pathname 
    426         my $doc_filename = $doc_rec->{'doc-file'}->[0];  
     427        my $doc_filename = $doc_rec->{'doc-file'}->[0]; 
    427428        $doc_filename = &util::filename_cat($archive_dir, $doc_filename); 
    428429 
     
    793794    # This now stores the full pathname 
    794795    $import_filename = $doc_rec->{'src-file'}->[0]; 
     796    $import_filename = &util::placeholders_to_abspath($import_filename); 
    795797 
    796798    # figure out correct metadata.xml file [?] 
     
    28742876    # This now stores the full pathname 
    28752877    $import_filename = $doc_rec->{'src-file'}->[0];  
     2878    $import_filename = &util::placeholders_to_abspath($import_filename); 
     2879 
    28762880    } else { # only for set_import_meta, not the case when calling method is set_import_metadata_array 
    28772881         # as the array version of the method doesn't support the -f parameter yet 
     
    29622966        # This now stores the full pathname 
    29632967        $import_filename = $doc_rec->{'src-file'}->[0];  
     2968        $import_filename = &util::placeholders_to_abspath($import_filename); 
    29642969    } 
    29652970 
     
    33933398    # This now stores the full pathname 
    33943399    my $import_filename = $archive_doc_rec->{'src-file'}->[0]; 
     3400    $import_filename = &util::placeholders_to_abspath($import_filename); 
    33953401     
    33963402    # figure out correct metadata.xml file [?] 
  • main/trunk/greenstone2/perllib/inexport.pm

    r28077 r28211  
    729729    &dbutil::read_infodb_file($collectcfg->{'infodbtype'}, $arcinfo_src_filename, $arcinfodb_map); 
    730730    foreach my $f (@full_new_files) { 
     731        my $rel_f = &util::abspath_to_placeholders($f); 
     732 
    731733        # check that we haven't seen it already 
    732         if (defined $arcinfodb_map->{$f}) { 
     734        if (defined $arcinfodb_map->{$rel_f}) { 
    733735        # 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"; 
    735737        } else { 
    736738        $block_hash->{'new_files'}->{$f} = 1; 
     
    12831285    # that this file is used in (note in most cases, it's just one OID) 
    12841286     
    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); 
    12861290    my $oids = $src_rec->{'oid'}; 
    12871291    my $file_record_deleted = 0; 
     
    12891293    # delete the src record 
    12901294    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); 
    12921296    &dbutil::close_infodb_write_handle($infodbtype, $src_infodb_file_handle); 
    12931297 
     
    12981302        my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $oid); 
    12991303        my $doc_source_file = $doc_rec->{'src-file'}->[0]; 
     1304        $doc_source_file = &util::placeholders_to_abspath($doc_source_file); 
     1305 
    13001306        if (!&util::filename_is_absolute($doc_source_file)) { 
    13011307        $doc_source_file = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},$doc_source_file); 
  • main/trunk/greenstone2/perllib/manifest.pm

    r27299 r28211  
    208208        my @all_files = ($doc_source_file); 
    209209        push(@all_files,@$assoc_files) if defined $assoc_files; 
    210          
     210 
    211211        foreach my $filename (@all_files) { 
    212212         
     213        $filename = &util::placeholders_to_abspath($filename); 
     214 
    213215        if (!&util::filename_is_absolute($filename)) { 
    214216            $filename = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},$filename); 
  • main/trunk/greenstone2/perllib/plugin.pm

    r27623 r28211  
    255255    # that this file is used in (note in most cases, it's just one OID) 
    256256     
     257    $file = &util::abspath_to_placeholders($file); 
    257258    my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file); 
    258259    my $oids = $src_rec->{'oid'}; 
  • main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm

    r28022 r28211  
    878878        $reverse_lookups->{$real_filename} = 1; 
    879879        } 
    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);        
    881886        push(@{$oid_files->{$field}},$raw_filename); 
    882887    } 
     
    935940 
    936941    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 
    938943 
    939944    ##print STDERR "*** To set in db: \n\t$doc_db\n\t$oid\n\t$doc_db_text\n"; 
     
    982987    $oid_files->{'doc-file'} = [ $oid_files->{'doc-file'} ]; 
    983988    $oid_files->{'index-status'} = [ $oid_files->{'index-status'} ]; 
     989    $oid_files->{'src-file'} = &util::abspath_to_placeholders($oid_files->{'src-file'}); 
    984990    $oid_files->{'src-file'} = [ $oid_files->{'src-file'} ]; 
    985991    $oid_files->{'sort-meta'} = [ $oid_files->{'sort-meta'} ]; 
  • main/trunk/greenstone2/perllib/util.pm

    r28177 r28211  
    824824    } 
    825825 
     826    if (!defined $ENV{'GREENSTONEHOME'}) { # for GS3, would have been defined in use_site_collection, to GSDL3HOME 
     827     $ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'};  
     828    } 
     829 
    826830    # get and check the collection 
    827831    if (!defined($collection) || $collection eq "") { 
     
    842846    # are defined 
    843847    $ENV{'GSDLCOLLECTION'} = $collection; 
     848    $ENV{'GSDLCOLLECTHOME'} = $collectdir; 
    844849    $ENV{'GSDLCOLLECTDIR'} = &FileUtils::filenameConcatenate($collectdir, $collection); 
    845850 
     
    868873    die "GSDL3HOME not set.\n" unless defined $ENV{'GSDL3HOME'}; 
    869874    $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"; 
    870885    } 
    871886 
     
    12131228    my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode 
    12141229     
     1230    if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists 
     1231        return $ENV{'GSDLCOLLECTDIR'}; 
     1232    } 
     1233 
    12151234    my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);    
    12161235     
     
    12241243# work out the full path to "collect" of this greenstone 2/3 installation 
    12251244sub 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"); 
    12341263    } 
    12351264     
     
    12391268} 
    12401269 
    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 { 
     1270sub is_abs_path_this_os { 
    12731271    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 
     1278sub 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. 
    12741283 
    12751284    return 1 if($path =~ m@^/@); # full paths begin with forward slash on linux/mac 
     
    12771286 
    12781287    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 
    13041290 
    13051291# This subroutine is for improving portability of Greenstone collections from one OS to another, 
     
    13161302    my $path = shift(@_); # path to convert from absolute to one with placeholders 
    13171303 
    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 
    13211305     
    13221306    # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders 
    13231307 
    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@' 
    13301315    ); 
    13311316 
     
    13361321 
    13371322    foreach my $gs_path (@gs_paths) {  
     1323    next if($gs_path eq ""); # site can be empty 
     1324 
    13381325    my $re_path =  &util::filename_to_regex($gs_path); # escape for regex 
    13391326 
    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? 
    13431328 
    13441329        my $placeholder = $placeholder_map{$gs_path}; # get the placeholder to replace the matched path with 
     
    13581343    my $path = shift(@_); # path that can contain placeholders to convert to resolved absolute path 
    13591344 
    1360     my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_; 
    1361  
    13621345    return $path if($path !~ m/@/); # path contains no placeholders 
    13631346     
    13641347    # replace placeholders with gs prefixes  
    1365  
     1348    my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : ""; 
    13661349    my @placeholders = ('@THISCOLLECTPATH@', '@COLLECTHOME@', '@SITEHOME@', '@GSDLHOME@'); # order of paths not crucial in this case,  
    13671350                       # but listed here from longest to shortest once placeholders are have been resolved 
    13681351 
    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 array 
    1370                '@SITEHOME@' => $site_dir, 
    1371                '@COLLECTHOME@' => $collect_dir, 
    1372                '@THISCOLLECTPATH@' => $collection_path 
     1352    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'} 
    13731356    ); 
    13741357