Index: /main/trunk/greenstone2/perllib/arcinfo.pm
===================================================================
--- /main/trunk/greenstone2/perllib/arcinfo.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/arcinfo.pm	(revision 28211)
@@ -143,4 +143,6 @@
 
     foreach my $file ( keys %$infodb_map ) {
+	# turn placeholders in the file keys of archiveinf-src file back to absolute paths
+	$file = &util::placeholders_to_abspath($file);
 	$self->{'prev_import_filelist'}->{$file} = 1;
     }
@@ -176,5 +178,8 @@
 
     foreach my $srcfile ( keys %$rev_infodb_map ) {
+
 	my $vals = $rev_infodb_map->{$srcfile};
+
+	$srcfile = &util::abspath_to_placeholders($srcfile);
 
 	foreach my $OID ($vals =~ m/^<oid>(.*)$/gm) {
@@ -251,4 +256,7 @@
     foreach my $key ( keys %$rev_infodb_map ) {
 	my $val_hash = $rev_infodb_map->{$key};
+
+	$key = &util::abspath_to_placeholders($key);	
+
 	&dbutil::write_infodb_entry($self->{'infodbtype'}, $rev_infodb_handle, $key, $val_hash);
     }
Index: /main/trunk/greenstone2/perllib/cgiactions/explodeaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/explodeaction.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/cgiactions/explodeaction.pm	(revision 28211)
@@ -135,12 +135,14 @@
 	
 	if (defined $src_files) {
-	    foreach my $if (@$src_files) {
-		$all_import_file_keys{$if} = 1;
+	    foreach my $ifile (@$src_files) {
+		$ifile = &util::placeholders_to_abspath($ifile);
+		$all_import_file_keys{$ifile} = 1;
 	    }
 	}
 
 	if (defined $assoc_files) {
-	    foreach my $if (@$assoc_files) {
-		$all_import_file_keys{$if} = 1;
+	    foreach my $ifile (@$assoc_files) {
+		$ifile = &util::placeholders_to_abspath($ifile);
+		$all_import_file_keys{$ifile} = 1;
 	    }
 	}
@@ -175,12 +177,14 @@
     my %all_oid_keys = ();
 
-    foreach my $if (@$import_filenames) {
-		$if = &util::upgrade_if_dos_filename($if);
-
-	print STDERR "*** looking import filename key \"$if\"\n";
-
+    foreach my $ifile (@$import_filenames) {
+	$ifile = &util::upgrade_if_dos_filename($ifile);
+	$ifile = &util::abspath_to_placeholders($ifile);
+
+	print STDERR "*** looking up import filename key \"$ifile\"\n";
+	
 	my $src_rec
 	    = &dbutil::read_infodb_entry($infodb_type, $arcinfo_src_filename, 
-					 $if);
+					 $ifile);
+
 	my $oids = $src_rec->{'oid'};
 
Index: /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm	(revision 28211)
@@ -318,4 +318,5 @@
 	    # This now stores the full pathname
 	    my $import_filename = $doc_rec->{'src-file'}->[0];
+	    $import_filename = &util::placeholders_to_abspath($import_filename);
 
 	    # figure out correct metadata.xml file [?]
@@ -424,5 +425,5 @@
 	    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
 	    # This now stores the full pathname
-	    my $doc_filename = $doc_rec->{'doc-file'}->[0];	
+	    my $doc_filename = $doc_rec->{'doc-file'}->[0];
 	    $doc_filename = &util::filename_cat($archive_dir, $doc_filename);
 
@@ -793,4 +794,5 @@
 	# This now stores the full pathname
 	$import_filename = $doc_rec->{'src-file'}->[0];
+	$import_filename = &util::placeholders_to_abspath($import_filename);
 
 	# figure out correct metadata.xml file [?]
@@ -2874,4 +2876,6 @@
 	# This now stores the full pathname
 	$import_filename = $doc_rec->{'src-file'}->[0];	
+	$import_filename = &util::placeholders_to_abspath($import_filename);
+
     } else { # only for set_import_meta, not the case when calling method is set_import_metadata_array
 	     # as the array version of the method doesn't support the -f parameter yet
@@ -2962,4 +2966,5 @@
 		# This now stores the full pathname
 		$import_filename = $doc_rec->{'src-file'}->[0];	
+		$import_filename = &util::placeholders_to_abspath($import_filename);
 	}
 
@@ -3393,4 +3398,5 @@
     # This now stores the full pathname
     my $import_filename = $archive_doc_rec->{'src-file'}->[0];
+    $import_filename = &util::placeholders_to_abspath($import_filename);
     
     # figure out correct metadata.xml file [?]
Index: /main/trunk/greenstone2/perllib/inexport.pm
===================================================================
--- /main/trunk/greenstone2/perllib/inexport.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/inexport.pm	(revision 28211)
@@ -729,8 +729,10 @@
 	&dbutil::read_infodb_file($collectcfg->{'infodbtype'}, $arcinfo_src_filename, $arcinfodb_map);
 	foreach my $f (@full_new_files) {
+	    my $rel_f = &util::abspath_to_placeholders($f);
+
 	    # check that we haven't seen it already
-	    if (defined $arcinfodb_map->{$f}) {
+	    if (defined $arcinfodb_map->{$rel_f}) {
 		# TODO make better warning
-		print STDERR "Warning: $f already in src archive, \n";
+		print STDERR "Warning: $f ($rel_f) already in src archive, \n";
 	    } else {
 		$block_hash->{'new_files'}->{$f} = 1;
@@ -1283,5 +1285,7 @@
 	# that this file is used in (note in most cases, it's just one OID)
 	
-	my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file);
+	my $relfile = &util::abspath_to_placeholders($file);
+
+	my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $relfile);
 	my $oids = $src_rec->{'oid'};
 	my $file_record_deleted = 0;
@@ -1289,5 +1293,5 @@
 	# delete the src record
 	my $src_infodb_file_handle = &dbutil::open_infodb_write_handle($infodbtype, $arcinfo_src_filename, "append");
-	&dbutil::delete_infodb_entry($infodbtype, $src_infodb_file_handle, $file);
+	&dbutil::delete_infodb_entry($infodbtype, $src_infodb_file_handle, $relfile);
 	&dbutil::close_infodb_write_handle($infodbtype, $src_infodb_file_handle);
 
@@ -1298,4 +1302,6 @@
 	    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $oid);
 	    my $doc_source_file = $doc_rec->{'src-file'}->[0];
+	    $doc_source_file = &util::placeholders_to_abspath($doc_source_file);
+
 	    if (!&util::filename_is_absolute($doc_source_file)) {
 		$doc_source_file = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},$doc_source_file);
Index: /main/trunk/greenstone2/perllib/manifest.pm
===================================================================
--- /main/trunk/greenstone2/perllib/manifest.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/manifest.pm	(revision 28211)
@@ -208,7 +208,9 @@
 	    my @all_files = ($doc_source_file);
 	    push(@all_files,@$assoc_files) if defined $assoc_files;
-		
+
 	    foreach my $filename (@all_files) {
 		
+		$filename = &util::placeholders_to_abspath($filename);
+
 		if (!&util::filename_is_absolute($filename)) {
 		    $filename = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},$filename);
Index: /main/trunk/greenstone2/perllib/plugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugin.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/plugin.pm	(revision 28211)
@@ -255,4 +255,5 @@
 	# that this file is used in (note in most cases, it's just one OID)
 	
+	$file = &util::abspath_to_placeholders($file);
 	my $src_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_src_filename, $file);
 	my $oids = $src_rec->{'oid'};
Index: /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm	(revision 28211)
@@ -878,5 +878,10 @@
 		$reverse_lookups->{$real_filename} = 1;
 	    }
-###	    push(@{$oid_files->{$field}},$full_file);
+
+	    if($field =~ m@assoc-file|src-file|meta-file@) {
+		$raw_filename = &util::abspath_to_placeholders($raw_filename);
+	    }
+
+###	    push(@{$oid_files->{$field}},$full_file);	    
 	    push(@{$oid_files->{$field}},$raw_filename);
 	}
@@ -935,5 +940,5 @@
 
     my $doc_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $output_dir);
-    my $src_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-src", $output_dir);
+    #my $src_db = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-src", $output_dir); # var unused in this function or file
 
     ##print STDERR "*** To set in db: \n\t$doc_db\n\t$oid\n\t$doc_db_text\n";
@@ -982,4 +987,5 @@
     $oid_files->{'doc-file'} = [ $oid_files->{'doc-file'} ];
     $oid_files->{'index-status'} = [ $oid_files->{'index-status'} ];
+    $oid_files->{'src-file'} = &util::abspath_to_placeholders($oid_files->{'src-file'});
     $oid_files->{'src-file'} = [ $oid_files->{'src-file'} ];
     $oid_files->{'sort-meta'} = [ $oid_files->{'sort-meta'} ];
Index: /main/trunk/greenstone2/perllib/util.pm
===================================================================
--- /main/trunk/greenstone2/perllib/util.pm	(revision 28210)
+++ /main/trunk/greenstone2/perllib/util.pm	(revision 28211)
@@ -824,4 +824,8 @@
     }
 
+    if (!defined $ENV{'GREENSTONEHOME'}) { # for GS3, would have been defined in use_site_collection, to GSDL3HOME
+	 $ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'}; 
+    }
+
     # get and check the collection
     if (!defined($collection) || $collection eq "") {
@@ -842,4 +846,5 @@
     # are defined
     $ENV{'GSDLCOLLECTION'} = $collection;
+    $ENV{'GSDLCOLLECTHOME'} = $collectdir;
     $ENV{'GSDLCOLLECTDIR'} = &FileUtils::filenameConcatenate($collectdir, $collection);
 
@@ -868,4 +873,14 @@
 	die "GSDL3HOME not set.\n" unless defined $ENV{'GSDL3HOME'};
 	$collectdir = &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'}, "sites", $site, "collect");
+    }
+
+    if (defined $ENV{'GSDL3HOME'}) {
+	$ENV{'GREENSTONEHOME'} = $ENV{'GSDL3HOME'}; 	
+	$ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site);
+    } elsif (defined $ENV{'GSDL3SRCHOME'}) {
+	$ENV{'GREENSTONEHOME'} = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "web");	
+	$ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site);
+    } else {
+	print STDERR "*** util::use_site_collection(). Warning: Neither GSDL3HOME nor GSDL3SRCHOME set.\n";
     }
 
@@ -1213,4 +1228,8 @@
 	my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode
 	
+	if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists
+	    return $ENV{'GSDLCOLLECTDIR'};
+	}
+
 	my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);	
 	
@@ -1224,12 +1243,22 @@
 # work out the full path to "collect" of this greenstone 2/3 installation
 sub get_working_collect_dir {
-    my ($site) = @_;
-    
-    if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collect dir exists
-	return $ENV{'GSDLCOLLECTDIR'};
-    }
-    
-    elsif (defined $site && $site) { # site non-empty, so get default collect dir for GS3
-	return &FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect");
+    my ($site) = @_;    
+
+    if (defined $ENV{'GSDLCOLLECTHOME'}) { # a predefined collect dir exists
+	return $ENV{'GSDLCOLLECTHOME'};
+    }
+
+    if (defined $site && $site) { # site non-empty, so get default collect dir for GS3
+	
+	if (defined $ENV{'GSDL3HOME'}) {
+	    return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site,"collect"); # web folder
+	} 
+	elsif (defined $ENV{'GSDL3SRCHOME'}) {
+	    return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site,"collect");
+	}
+    } 
+
+    elsif (defined $ENV{'SITEHOME'}) { #&FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect");
+	return &FileUtils::filenameConcatenate($ENV{'SITEHOME'},"collect");
     }
     
@@ -1239,37 +1268,17 @@
 }
 
-# returns path to current GS3 site.
-# Returns "" if $site parameter is empty string, undefined or otherwise false
-sub get_site_dir {
-    my ($site) = @_;
-    
-    if (defined $ENV{'GSDL3HOME'}) {
-	return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site); # web folder
-    } 
-    elsif (defined $ENV{'GSDL3SRCHOME'}) {
-	return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site);
-    }
-    else { # site has no meaning, return "" (covers the case of this subroutine having been called for a GS2 situation)
-	return "";
-    }
-}
-
-# returns path to GSDL3HOME if GS3, or GSDLHOME if GS2
-sub get_gs_home {
-    my ($site) = @_;
-
-    if (defined $site && $site) { # not undefined or empty string, so GS3 case
-	if (defined $ENV{'GSDL3HOME'}) {
-	    return $ENV{'GSDL3HOME'};
-	} else {
-	    return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web");
-	}
-    } else {
-	return $ENV{'GSDLHOME'};
-    }
-}
-
-sub is_abs_path {
+sub is_abs_path_this_os {
     my ($path) = @_;
+
+    # File::Spec loads the module appropriate for the OS
+    return &FileUtils::isFilenameAbsolute(@_); #return File::Spec->file_name_is_absolute( $path );
+}
+
+
+sub is_abs_path_any_os {
+    my ($path) = @_;
+
+    # We can have filenames in our DBs that were produced on other OS, so this method exists
+    # to help identify absolute paths in such cases.
 
     return 1 if($path =~ m@^/@); # full paths begin with forward slash on linux/mac
@@ -1277,29 +1286,6 @@
 
     return 0;
-
-    # 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
-    #return File::Spec->file_name_is_absolute( $path );    
-}
-
-# returns an array of the FULL PATHS to the specific collection given, to the general collect_dir,
-# to the site directory if gs3 and to the greenstone home folder (GSDLHOME or GSDL3HOME). 
-# These elements are returned in this ORDER, in order to allow matching from longest to shortest path.
-sub get_common_gs_paths {
-
-    my ($site, $qualified_collection_name) = @_;
-    
-    my $collect_dir = &util::get_working_collect_dir($site);
-    my $collection_path = "";
-    if($qualified_collection_name ne "") {
-	$collection_path = &util::resolve_collection_dir($collect_dir, $qualified_collection_name, $site);
-    }
-    
-    my $site_dir = &util::get_site_dir($site); # returns "" for GS2
-    my $gs_home = &util::get_gs_home(); # GSDLHOME or GSDL3HOME folder
-    
-    return ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
-    #my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
-    #return @gs_paths;
-}
+}
+
 
 # This subroutine is for improving portability of Greenstone collections from one OS to another,
@@ -1316,16 +1302,15 @@
     my $path = shift(@_); # path to convert from absolute to one with placeholders
 
-    my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_;
-
-    return $path unless is_abs_path($path); # path is relative
+    return $path unless is_abs_path_any_os($path); # path is relative
     
     # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders
 
-    my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
-
-    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
-			   $site_dir => '@SITEHOME@',
-			   $collect_dir => '@COLLECTHOME@',
-			   $collection_path => '@THISCOLLECTPATH@'
+    my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : "";
+    my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $site, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path
+
+    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
+			   $site => '@SITEHOME@',
+			   $ENV{'GSDLCOLLECTHOME'} => '@COLLECTHOME@',
+			   $ENV{'GSDLCOLLECTDIR'} => '@THISCOLLECTPATH@'
 	);
 
@@ -1336,9 +1321,9 @@
 
     foreach my $gs_path (@gs_paths) { 
+	next if($gs_path eq ""); # site can be empty
+
 	my $re_path =  &util::filename_to_regex($gs_path); # escape for regex
 
-	next if($re_path eq ""); # site can be empty
-
-	if($path =~ m/^$re_path/) { # case sensitive or not for OS?
+	if($path =~ m/^$re_path/i) { # case sensitive or not for OS?
 
 	    my $placeholder = $placeholder_map{$gs_path}; # get the placeholder to replace the matched path with
@@ -1358,17 +1343,15 @@
     my $path = shift(@_); # path that can contain placeholders to convert to resolved absolute path
 
-    my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_;
-
     return $path if($path !~ m/@/); # path contains no placeholders
     
     # replace placeholders with gs prefixes 
-
+    my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : "";
     my @placeholders = ('@THISCOLLECTPATH@', '@COLLECTHOME@', '@SITEHOME@', '@GSDLHOME@'); # order of paths not crucial in this case, 
                        # but listed here from longest to shortest once placeholders are have been resolved
 
-    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
-			   '@SITEHOME@' => $site_dir,
-			   '@COLLECTHOME@' => $collect_dir,
-			   '@THISCOLLECTPATH@' => $collection_path
+    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
+			   '@SITEHOME@' => $site,
+			   '@COLLECTHOME@' => $ENV{'GSDLCOLLECTHOME'},
+			   '@THISCOLLECTPATH@' => $ENV{'GSDLCOLLECTDIR'}
 	);
 
