diff --git a/lib/mu-store-priv.hh b/lib/mu-store-priv.hh index e055ea55..2f1c09c1 100644 --- a/lib/mu-store-priv.hh +++ b/lib/mu-store-priv.hh @@ -97,7 +97,6 @@ public: _processed = 0; _read_only = read_only; _ref_count = 1; - _version = NULL; } void set_my_addresses (const char **my_addresses) { @@ -124,7 +123,7 @@ public: else if (g_strcmp0 (version, MU_STORE_SCHEMA_VERSION) != 0) { g_free (version); throw MuStoreError (MU_ERROR_XAPIAN_NOT_UP_TO_DATE, - ("store needs an upgrade")); + "store needs an upgrade"); } else g_free (version); } @@ -134,8 +133,6 @@ public: if (_ref_count != 0) g_warning ("ref count != 0"); - g_free (_version); - mu_contacts_destroy (_contacts); if (!_read_only) mu_store_flush (this); @@ -165,14 +162,15 @@ public: mu_contacts_clear (_contacts); } - std::string get_uid_term (const char *path); + std::string get_uid_term (const char *path) const; MuContacts* contacts() { return _contacts; } - const char* version () { - g_free (_version); - return _version = mu_store_get_metadata (this, MU_STORE_VERSION_KEY, - NULL); + const std::string version () const { + char *v = mu_store_get_metadata (this, MU_STORE_VERSION_KEY, NULL); + _version = v; + g_free (v); + return _version; } void set_version (const char *version) { @@ -233,7 +231,7 @@ private: MuContacts *_contacts; std::string _path; - gchar *_version; + mutable std::string _version; Xapian::Database *_db; bool _read_only; diff --git a/lib/mu-store-read.cc b/lib/mu-store-read.cc index 15b0a41b..51abe67f 100644 --- a/lib/mu-store-read.cc +++ b/lib/mu-store-read.cc @@ -45,7 +45,7 @@ // note: not re-entrant std::string -_MuStore::get_uid_term (const char* path) +_MuStore::get_uid_term (const char* path) const { char real_path[PATH_MAX + 1]; @@ -84,7 +84,7 @@ mu_store_new_read_only (const char* xpath, GError **err) gboolean -mu_store_is_read_only (MuStore *store) +mu_store_is_read_only (const MuStore *store) { g_return_val_if_fail (store, FALSE); @@ -97,7 +97,7 @@ mu_store_is_read_only (MuStore *store) unsigned -mu_store_count (MuStore *store, GError **err) +mu_store_count (const MuStore *store, GError **err) { g_return_val_if_fail (store, (unsigned)-1); @@ -110,25 +110,30 @@ mu_store_count (MuStore *store, GError **err) const char* -mu_store_version (MuStore *store) +mu_store_version (const MuStore *store) { g_return_val_if_fail (store, NULL); - return store->version (); + return store->version().c_str(); } gboolean -mu_store_needs_upgrade (MuStore *store) +mu_store_needs_upgrade (const MuStore *store) { g_return_val_if_fail (store, TRUE); - return (g_strcmp0 (mu_store_version (store), - MU_STORE_SCHEMA_VERSION) == 0) ? FALSE : TRUE; + MU_WRITE_LOG ("'%s' '%s'\n", mu_store_version(store), MU_STORE_SCHEMA_VERSION); + + if (g_strcmp0 (mu_store_version (store), + MU_STORE_SCHEMA_VERSION) == 0) + return FALSE; + else + return TRUE; } char* -mu_store_get_metadata (MuStore *store, const char *key, GError **err) +mu_store_get_metadata (const MuStore *store, const char *key, GError **err) { g_return_val_if_fail (store, NULL); g_return_val_if_fail (key, NULL); @@ -151,7 +156,7 @@ mu_store_get_read_only_database (MuStore *store) gboolean -mu_store_contains_message (MuStore *store, const char* path, GError **err) +mu_store_contains_message (const MuStore *store, const char* path, GError **err) { g_return_val_if_fail (store, FALSE); g_return_val_if_fail (path, FALSE); @@ -166,7 +171,7 @@ mu_store_contains_message (MuStore *store, const char* path, GError **err) unsigned -mu_store_get_docid_for_path (MuStore *store, const char* path, GError **err) +mu_store_get_docid_for_path (const MuStore *store, const char* path, GError **err) { g_return_val_if_fail (store, FALSE); g_return_val_if_fail (path, FALSE); @@ -192,7 +197,7 @@ mu_store_get_docid_for_path (MuStore *store, const char* path, GError **err) time_t -mu_store_get_timestamp (MuStore *store, const char *msgpath, GError **err) +mu_store_get_timestamp (const MuStore *store, const char *msgpath, GError **err) { char *stampstr; time_t rv; @@ -248,7 +253,7 @@ mu_store_foreach (MuStore *self, MuMsg* -mu_store_get_msg (MuStore *self, unsigned docid, GError **err) +mu_store_get_msg (const MuStore *self, unsigned docid, GError **err) { g_return_val_if_fail (self, NULL); g_return_val_if_fail (docid != 0, NULL); diff --git a/lib/mu-store.h b/lib/mu-store.h index b50e8694..6df0cdee 100644 --- a/lib/mu-store.h +++ b/lib/mu-store.h @@ -153,7 +153,7 @@ void mu_store_set_my_addresses (MuStore *store, const char **my_addresses); * @return the number of documents in the database; (unsigned)-1 in * case of error */ -unsigned mu_store_count (MuStore *store, GError **err); +unsigned mu_store_count (const MuStore *store, GError **err); /** * get a version string for the database; it's a const string, which @@ -164,7 +164,7 @@ unsigned mu_store_count (MuStore *store, GError **err); * * @return the version string or NULL in case of error */ -const char* mu_store_version (MuStore *store); +const char* mu_store_version (const MuStore *store); /** @@ -244,7 +244,7 @@ gboolean mu_store_remove_path (MuStore *store, const char* msgpath); * * @return TRUE if the message exists, FALSE otherwise */ -gboolean mu_store_contains_message (MuStore *store, const char* path, +gboolean mu_store_contains_message (const MuStore *store, const char* path, GError **err); @@ -258,7 +258,7 @@ gboolean mu_store_contains_message (MuStore *store, const char* path, * * @return the docid if the message was found, MU_STORE_INVALID_DOCID (0) otherwise * */ -unsigned mu_store_get_docid_for_path (MuStore *store, const char* path, GError **err); +unsigned mu_store_get_docid_for_path (const MuStore *store, const char* path, GError **err); /** * store a timestamp for a directory @@ -282,7 +282,7 @@ gboolean mu_store_set_timestamp (MuStore *store, const char* msgpath, * * @return the timestamp, or 0 in case of error */ -time_t mu_store_get_timestamp (MuStore *store, const char* msgpath, +time_t mu_store_get_timestamp (const MuStore *store, const char* msgpath, GError **err); @@ -294,7 +294,7 @@ time_t mu_store_get_timestamp (MuStore *store, const char* msgpath, * @return TRUE if the store is read-only, FALSE otherwise (and in * case of error) */ -gboolean mu_store_is_read_only (MuStore *store); +gboolean mu_store_is_read_only (const MuStore *store); /** @@ -335,7 +335,7 @@ gboolean mu_store_set_metadata (MuStore *store, const char *key, const char *val * @return the value of the metadata (gfree when done with it), or * NULL in case of error */ -char* mu_store_get_metadata (MuStore *store, const char *key, GError **err) +char* mu_store_get_metadata (const MuStore *store, const char *key, GError **err) G_GNUC_WARN_UNUSED_RESULT; @@ -360,7 +360,7 @@ gchar* mu_store_database_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT; * * @return TRUE if the database needs upgrading, FALSE otherwise */ -gboolean mu_store_needs_upgrade (MuStore *store); +gboolean mu_store_needs_upgrade (const MuStore *store); /** * clear the database, ie., remove all of the contents. This is a @@ -396,7 +396,7 @@ gboolean mu_store_database_is_locked (const gchar *xpath); * @return a MuMsg instance (use mu_msg_unref when done with it), or * NULL in case of error */ -MuMsg* mu_store_get_msg (MuStore *self, unsigned docid, GError **err) +MuMsg* mu_store_get_msg (const MuStore *self, unsigned docid, GError **err) G_GNUC_WARN_UNUSED_RESULT;