diff -up evolution-data-server-3.8.5/camel/camel-db.c.cameldb-track-pending-syncs evolution-data-server-3.8.5/camel/camel-db.c
--- evolution-data-server-3.8.5/camel/camel-db.c.cameldb-track-pending-syncs 2013-08-11 00:00:52.000000000 +0200
+++ evolution-data-server-3.8.5/camel/camel-db.c 2014-12-05 08:55:12.403985638 +0100
@@ -55,6 +55,12 @@ typedef struct {
GRecMutex sync_mutex;
guint timeout_id;
gint flags;
+
+ /* Do know how many syncs are pending, to not close
+ the file before the last sync is over */
+ guint pending_syncs;
+ GMutex pending_syncs_lock;
+ GCond pending_syncs_cond;
} CamelSqlite3File;
static gint
@@ -93,6 +99,13 @@ sync_request_thread_cb (gpointer task_da
call_old_file_Sync (sync_data->cFile, sync_data->flags);
+ g_mutex_lock (&sync_data->cFile->pending_syncs_lock);
+ g_warn_if_fail (sync_data->cFile->pending_syncs > 0);
+ sync_data->cFile->pending_syncs--;
+ if (!sync_data->cFile->pending_syncs)
+ g_cond_signal (&sync_data->cFile->pending_syncs_cond);
+ g_mutex_unlock (&sync_data->cFile->pending_syncs_lock);
+
done = sync_data->done;
g_free (sync_data);
@@ -138,6 +151,10 @@ sync_push_request (CamelSqlite3File *cFi
cFile->flags = 0;
+ g_mutex_lock (&cFile->pending_syncs_lock);
+ cFile->pending_syncs++;
+ g_mutex_unlock (&cFile->pending_syncs_lock);
+
g_rec_mutex_unlock (&cFile->sync_mutex);
g_thread_pool_push (sync_pool, data, &error);
@@ -251,6 +268,12 @@ camel_sqlite3_file_xClose (sqlite3_file
/* Make the last sync. */
sync_push_request (cFile, TRUE);
+ g_mutex_lock (&cFile->pending_syncs_lock);
+ while (cFile->pending_syncs > 0) {
+ g_cond_wait (&cFile->pending_syncs_cond, &cFile->pending_syncs_lock);
+ }
+ g_mutex_unlock (&cFile->pending_syncs_lock);
+
if (cFile->old_vfs_file->pMethods)
res = cFile->old_vfs_file->pMethods->xClose (cFile->old_vfs_file);
else
@@ -260,6 +283,8 @@ camel_sqlite3_file_xClose (sqlite3_file
cFile->old_vfs_file = NULL;
g_rec_mutex_clear (&cFile->sync_mutex);
+ g_mutex_clear (&cFile->pending_syncs_lock);
+ g_cond_clear (&cFile->pending_syncs_cond);
return res;
}
@@ -319,6 +344,10 @@ camel_sqlite3_vfs_xOpen (sqlite3_vfs *pV
}
g_rec_mutex_init (&cFile->sync_mutex);
+ g_mutex_init (&cFile->pending_syncs_lock);
+ g_cond_init (&cFile->pending_syncs_cond);
+
+ cFile->pending_syncs = 0;
g_rec_mutex_lock (&only_once_lock);