Index: backends/flint/flint_table.cc
===================================================================
--- backends/flint/flint_table.cc	(revision 14127)
+++ backends/flint/flint_table.cc	(working copy)
@@ -1841,12 +1841,6 @@
 	    C[i].rewrite = false;
 	}
 
-	if (!flint_io_sync(handle)) {
-	    (void)::close(handle);
-	    handle = -1;
-	    throw Xapian::DatabaseError("Can't commit new revision - failed to flush DB to disk");
-	}
-
 	// Save to "<table>.tmp" and then rename to "<table>.base<letter>" so
 	// that a reader can't try to read a partially written base file.
 	string tmp = name;
@@ -1855,6 +1849,14 @@
 	basefile += "base";
 	basefile += char(base_letter);
 	base.write_to_file(tmp);
+
+	if (!flint_io_sync(handle)) {
+	    (void)::close(handle);
+	    (void)unlink(tmp.c_str());
+	    handle = -1;
+	    throw Xapian::DatabaseError("Can't commit new revision - failed to flush DB to disk");
+	}
+
 #if defined __WIN32__
 	if (msvc_posix_rename(tmp.c_str(), basefile.c_str()) < 0) {
 #else

