<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -206,11 +206,11 @@ module ActsAsXapian
         
         prepare_environment
 
-        new_path = @@db_path + suffix
+        full_path = @@db_path + suffix
         raise &quot;writable_suffix/suffix inconsistency&quot; if @@writable_suffix &amp;&amp; @@writable_suffix != suffix
 
         # for indexing
-        @@writable_db = Xapian::WritableDatabase.new(new_path, Xapian::DB_CREATE_OR_OPEN)
+        @@writable_db = Xapian::WritableDatabase.new(full_path, Xapian::DB_CREATE_OR_OPEN)
         @@term_generator = Xapian::TermGenerator.new()
         @@term_generator.set_flags(Xapian::TermGenerator::FLAG_SPELLING, 0)
         @@term_generator.database = @@writable_db
@@ -509,7 +509,7 @@ module ActsAsXapian
     # logging in the database that it has been.
     def ActsAsXapian.update_index(flush = false, verbose = false)
         # STDOUT.puts(&quot;start of ActsAsXapian.update_index&quot;) if verbose
-
+        
         # Before calling writable_init we have to make sure every model class has been initialized.
         # i.e. has had its class code loaded, so acts_as_xapian has been called inside it, and
         # we have the info from acts_as_xapian.
@@ -519,6 +519,12 @@ module ActsAsXapian
 
         ActsAsXapian.writable_init
 
+        # Abort if full rebuild is going on
+        new_path = ActsAsXapian.db_path + &quot;.new&quot;
+        if File.exist?(new_path)
+            raise &quot;aborting incremental index update while full index rebuild happens; found existing &quot; + new_path
+        end
+
         ids_to_refresh = ActsAsXapianJob.find(:all).map() { |i| i.id }
         for id in ids_to_refresh
             job = nil
@@ -566,8 +572,12 @@ module ActsAsXapian
         end
     end
         
-    # You must specify *all* the models here, this totally rebuilds the Xapian database.
-    # You'll want any readers to reopen the database after this.
+    # You must specify *all* the models here, this totally rebuilds the Xapian
+    # database.  You'll want any readers to reopen the database after this.
+    #
+    # Incremental update_index calls above are suspended while this rebuild
+    # happens (i.e. while the .new database is there) - any index update jobs
+    # are left in the database, and will run after the rebuild has finished.
     def ActsAsXapian.rebuild_index(model_classes, verbose = false)
         raise &quot;when rebuilding all, please call as first and only thing done in process / task&quot; if not ActsAsXapian.writable_db.nil?
 
@@ -582,12 +592,6 @@ module ActsAsXapian
         ActsAsXapian.writable_init(&quot;.new&quot;)
 
         # Index everything 
-        # XXX not a good place to do this destroy, as unindexed list is lost if
-        # process is aborted and old database carries on being used. Perhaps do in
-        # transaction and commit after rename below? Not sure if thenlocking is then bad
-        # for live website running at same time.
-        
-        ActsAsXapianJob.destroy_all 
         batch_size = 1000
         for model_class in model_classes
           model_class.transaction do</diff>
      <filename>lib/acts_as_xapian.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>33206072ef464b14063fd4c73c71559f9308d256</id>
    </parent>
  </parents>
  <author>
    <name>Francis Irving</name>
    <email>francis@flourish.org</email>
  </author>
  <url>http://github.com/frabcus/acts_as_xapian/commit/c73c083d60fdbf1f8b2b0b24b73b812f9dd4101e</url>
  <id>c73c083d60fdbf1f8b2b0b24b73b812f9dd4101e</id>
  <committed-date>2009-04-21T18:21:02-07:00</committed-date>
  <authored-date>2009-04-21T18:21:02-07:00</authored-date>
  <message>Don't allow incremental index update while doing full rebuild.</message>
  <tree>b5aab606d751e656a9f1c6d38e637b49419c16d4</tree>
  <committer>
    <name>Francis Irving</name>
    <email>francis@flourish.org</email>
  </committer>
</commit>
