Index: tests/apitest.cc
===================================================================
--- tests/apitest.cc	(revision 11136)
+++ tests/apitest.cc	(working copy)
@@ -147,7 +147,7 @@
 
 	bool backend = true, remote = false, transactions = true;
 	bool positional = true, writable = true, multi = false;
-	bool spelling = true, metadata = true;
+	bool spelling = true, metadata = false;
 	bool quartz = false, flint = true;
 #include "api_collated.h"
 
Index: backends/flint/flint_database.h
===================================================================
--- backends/flint/flint_database.h	(revision 11136)
+++ backends/flint/flint_database.h	(working copy)
@@ -328,8 +328,6 @@
 	void add_synonym(const string & word, const string & synonym) const;
 	void remove_synonym(const string & word, const string & synonym) const;
 	void clear_synonyms(const string & word) const;
-
-	void set_metadata(const string & key, const string & value);
 	//@}
 };
 
Index: backends/flint/flint_version.cc
===================================================================
--- backends/flint/flint_version.cc	(revision 11136)
+++ backends/flint/flint_version.cc	(working copy)
@@ -40,7 +40,7 @@
 using std::string;
 
 // YYYYMMDDX where X allows multiple format revisions in a day
-#define FLINT_VERSION 200709120
+#define FLINT_VERSION 200706140
 // 200709120 1.0.3 Database::get_metadata(), WritableDatabase::set_metadata().
 //                 Kill the unused "has_termfreqs" flag in the termlist table.
 // 200706140 1.0.2 Optional value and position tables.
@@ -88,7 +88,8 @@
     }
 }
 
-void FlintVersion::read_and_check(bool readonly)
+unsigned int
+FlintVersion::read_and_check()
 {
     int fd = ::open(filename.c_str(), O_RDONLY|O_BINARY);
 
@@ -126,33 +127,13 @@
     const unsigned char *v;
     v = reinterpret_cast<const unsigned char *>(buf) + MAGIC_LEN;
     unsigned int version = v[0] | (v[1] << 8) | (v[2] << 16) | (v[3] << 24);
-    if (version >= 200704230 && version < 200709120) {
-	if (readonly) return;
-	// Upgrade the database to the current version since any changes we
-	// make won't be compatible with older versions of Xapian.
-	string filename_save = filename;
-	filename += ".tmp";
-	create();
-	int result;
-#ifdef __WIN32__
-	result = msvc_posix_rename(filename.c_str(), filename_save.c_str());
-#else
-	result = rename(filename.c_str(), filename_save.c_str());
-#endif
-	filename = filename_save;
-	if (result == -1) {
-	    string msg("Failed to update flint version file: ");
-	    msg += filename;
-	    throw Xapian::DatabaseOpeningError(msg);
-	}
-	return;
-    }
-    if (version != FLINT_VERSION) {
+    if (version < 200704230 || version > 200709120) {
 	string msg("Flint version file ");
 	msg += filename;
 	msg += " is version ";
 	msg += om_tostring(version);
-	msg += " but I only understand "STRINGIZE(FLINT_VERSION);
+	msg += " but I only understand 200704230-200709120";
 	throw Xapian::DatabaseVersionError(msg);
     }
+    return version;
 }
Index: backends/flint/flint_version.h
===================================================================
--- backends/flint/flint_version.h	(revision 11136)
+++ backends/flint/flint_version.h	(working copy)
@@ -41,11 +41,9 @@
 
     /** Read the version file and check it's a version we understand.
      *
-     *  @param readonly    true if the database is being opened readonly.
-     * 
      *  On failure, an exception is thrown.
      */
-    void read_and_check(bool readonly);
+    unsigned int read_and_check();
 };
 
 #endif
Index: backends/flint/flint_database.cc
===================================================================
--- backends/flint/flint_database.cc	(revision 11136)
+++ backends/flint/flint_database.cc	(working copy)
@@ -236,7 +236,10 @@
     flint_revision_number_t cur_rev = record_table.get_open_revision_number();
 
     // Check the version file unless we're reopening.
-    if (cur_rev == 0) version_file.read_and_check(readonly);
+    if (cur_rev == 0) {
+	unsigned int version = version_file.read_and_check();
+	termlist_table.set_version(version);
+    }
 
     record_table.open();
     flint_revision_number_t revision = record_table.get_open_revision_number();
@@ -302,7 +305,9 @@
 FlintDatabase::open_tables(flint_revision_number_t revision)
 {
     DEBUGCALL(DB, void, "FlintDatabase::open_tables", revision);
-    version_file.read_and_check(readonly);
+    unsigned int version = version_file.read_and_check();
+    termlist_table.set_version(version);
+
     record_table.open(revision);
 
     // In case the position, value, synonym, and/or spelling tables don't
@@ -1137,17 +1142,3 @@
 {
     synonym_table.clear_synonyms(term);
 }
-
-void
-FlintWritableDatabase::set_metadata(const string & key, const string & value)
-{
-    DEBUGCALL(DB, string, "FlintWritableDatabase::set_metadata",
-	      key << ", " << value);
-    string btree_key("\x00\xc0", 2);
-    btree_key += key;
-    if (value.empty()) {
-	postlist_table.del(btree_key);
-    } else {
-	postlist_table.add(btree_key, value);
-    }
-}
Index: backends/flint/flint_termlisttable.cc
===================================================================
--- backends/flint/flint_termlisttable.cc	(revision 11136)
+++ backends/flint/flint_termlisttable.cc	(working copy)
@@ -69,7 +69,7 @@
 	// alphabetically is likely to be shorter than average).
 	// FIXME: If we have an incompatible database version bump we should
 	// drop this completely.
-	if (prev_term.size() == '0') tag += '0';
+	if (old_format || prev_term.size() == '0') tag += '0';
 
 	tag += prev_term.size();
 	tag += prev_term;
Index: backends/flint/flint_termlisttable.h
===================================================================
--- backends/flint/flint_termlisttable.h	(revision 11136)
+++ backends/flint/flint_termlisttable.h	(working copy)
@@ -33,6 +33,8 @@
 }
 
 class FlintTermListTable : public FlintTable {
+    bool old_format;
+
   public:
     /** Create a new FlintTermListTable object.
      *
@@ -45,6 +47,10 @@
     FlintTermListTable(std::string dbdir, bool readonly)
 	: FlintTable(dbdir + "/termlist.", readonly, Z_DEFAULT_STRATEGY) { }
 
+    void set_version(unsigned int version) {
+	old_format = (version < 200709120);
+    }
+
     /** Set the termlist data for document @a did.
      *
      *  Any existing data is replaced.

