Index: /main/trunk/greenstone2/perllib/inexport.pm
===================================================================
--- /main/trunk/greenstone2/perllib/inexport.pm	(revision 21305)
+++ /main/trunk/greenstone2/perllib/inexport.pm	(revision 21306)
@@ -33,9 +33,24 @@
 use GDBMUtils;
 
+sub src_db_file {
+    my ($archivedir) = @_;
+    return &util::filename_cat ($archivedir, "archiveinf-src.gdb");
+}
+
+sub doc_db_file {
+    my ($archivedir) = @_;
+    return &util::filename_cat ($archivedir, "archiveinf-doc.gdb");
+}
+
+sub oid_count_file {
+    my ($archivedir) = @_;
+    return &util::filename_cat ($archivedir, "OIDcount");
+}
+
 
 sub prime_doc_oid_count
 {
     my ($archivedir) = @_;
-    my $oid_count_filename = &util::filename_cat ($archivedir, "OIDcount");
+    my $oid_count_filename = &oid_count_file($archivedir);
 
     if (-e $oid_count_filename) {
@@ -62,5 +77,5 @@
 
     my ($archivedir) = @_;
-    my $oid_count_filename = &util::filename_cat ($archivedir, "OIDcount");
+    my $oid_count_filename = &oid_count_file($archivedir);
 
 
@@ -82,6 +97,5 @@
 
     # in this method, we want to know if metadata files are modified or not.
-    my $doc_db = "archiveinf-doc.gdb";
-    my $arcinfo_doc_filename = &util::filename_cat ($archivedir, $doc_db);
+    my $arcinfo_doc_filename = &doc_db_file($archivedir);
 
     my $archiveinf_timestamp = -M $arcinfo_doc_filename;
@@ -174,4 +188,6 @@
 
 
+
+
     # Deal with complication of new or modified metadata files by forcing
     # everything from this point down in the file hierarchy to
@@ -199,16 +215,35 @@
 		push(@$reindex_files,$existing_f);
 		$block_hash->{'reindex_files'}->{$existing_f} = 1;
-
-	    }
-	}
-
-	# Reindexing is accomplished by putting them in the list for reindexing (line above)
-	# and then tagging the arcinfo version as to be deleted.
-
-	_mark_docs_for_deletion($archive_info,$block_hash,$reindex_files,$archivedir,$verbosity, "reindex");
+		delete $block_hash->{'existing_files'}->{$existing_f};
+
+	    }
+	}
 	
 	# metadata file needs to be in new_files list so parsed by MetadataXMLPlug
 	# (or equivalent)
 	$block_hash->{'new_files'}->{$new_mdf} = 1; 
+
+    }
+
+    # go through remaining existing files and work out what has changed and needs to be reindexed.
+    my @existing_files = sort keys %{$block_hash->{'existing_files'}};
+
+    my $reindex_files = [];
+
+    foreach my $existing_filename (@existing_files) {
+	if (-M $existing_filename < $archiveinf_timestamp) {
+	    # file is newer than last build
+	    
+	    my $existing_file = $existing_filename;
+	    #my $collectdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'});
+
+	    #my $collectdir_resafe = &util::filename_to_regex($collectdir);
+	    #$existing_file =~ s/^$collectdir_resafe(\\|\/)?//;
+	    
+	    print STDERR "**** Reindexing existing file: $existing_file\n";
+
+	    push(@$reindex_files,$existing_file);
+	    $block_hash->{'reindex_files'}->{$existing_filename} = 1;
+	}
 
     }
@@ -249,31 +284,17 @@
 }
 
-# not used anymore
-sub is_assoc_file
+
+# this is used to delete "deleted" docs, and to remove old versions of "changed" docs
+# $mode is 'delete' or 'reindex'
+sub mark_docs_for_deletion
 {
-    my ($file,$doc_rec) = @_;
-
-    my ($file_root,$dirname,$suffix) = fileparse($file, "\\.[^\\.]+\$");
-
-    foreach my $af (@{$doc_rec->{'assoc-file'}}) {
-	my $full_af = &util::filename_cat($dirname,$af);
-
-	return 1 if ($full_af eq $file);
-    }
-
-    return 0;
-}
-
-
-
-# this is used to delete "deleted" docs, and to remove old versions of "changed" docs
-sub _mark_docs_for_deletion
-{
-    my ($archive_info,$block_hash,$deleted_files,$archivedir,$verbosity,$mode_text) = @_;
-
-    my $doc_db = "archiveinf-doc.gdb";
-    my $src_db = "archiveinf-src.gdb";
-    my $arcinfo_doc_filename = &util::filename_cat ($archivedir, $doc_db);
-    my $arcinfo_src_filename = &util::filename_cat ($archivedir, $src_db);
+    my ($archive_info,$block_hash,$deleted_files,$archivedir,$verbosity,$mode) = @_;
+
+    my $mode_text = "deleted from index";
+    if ($mode eq "reindex") {
+	$mode_text = "reindexed";
+    }
+    my $arcinfo_doc_filename = &doc_db_file($archivedir);
+    my $arcinfo_src_filename = &src_db_file($archivedir);
 
 
@@ -321,58 +342,4 @@
 }
 
-sub mark_docs_for_deletion
-{
-    _mark_docs_for_deletion(@_,"deleted from index");
-}
-
-
-sub mark_docs_for_reindex
-{
-    my ($archive_info,$block_hash,$archivedir,$verbosity) = @_;
-
-    # Reindexing is accomplished by deleting the previously indexed
-    # version of the document, and then allowing the new version to
-    # be indexed (as would a new document be indexed). 
-    # 
-    # The first step (marking for deletion) is implemented by this routine.
-    # 
-    # By default in Greenstone a new version of an index will hash to
-    # a new unique OID, and the above strategy of reindex=delete+add
-    # works fine.  A special case arises when a persistent OID is 
-    # allocated to a document (for instance through a metadata field),
-    # and the second step to reindexing (see XXXX) detects this and
-    # deals with it appropriately.
-
-    my @existing_files = sort keys %{$block_hash->{'existing_files'}};
-
-    my $doc_db = "archiveinf-doc.gdb";
-    my $arcinfo_doc_filename = &util::filename_cat ($archivedir, $doc_db);
-
-    my $archiveinf_timestamp = -M $arcinfo_doc_filename;
-
-    my $reindex_files = [];
-
-    foreach my $existing_filename (@existing_files) {
-	if (-M $existing_filename < $archiveinf_timestamp) {
-	    # file is newer than last build
-	    
-	    my $existing_file = $existing_filename;
-	    #my $collectdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'});
-
-	    #my $collectdir_resafe = &util::filename_to_regex($collectdir);
-	    #$existing_file =~ s/^$collectdir_resafe(\\|\/)?//;
-	    
-	    print STDERR "**** Reindexing existing file: $existing_file\n";
-
-	    push(@$reindex_files,$existing_file);
-	    $block_hash->{'reindex_files'}->{$existing_filename} = 1;
-	}
-
-    }
-    
-    _mark_docs_for_deletion($archive_info,$block_hash,$reindex_files,$archivedir,$verbosity, "reindex");
-
-}
-
 
 
