[evolution-data-server] Added api's e_cal_backend_store_clean, e_cal_backend_cache_remove.
- From: Chenthill Palanisamy <pchen src gnome org>
- To: svn-commits-list gnome org
- Subject: [evolution-data-server] Added api's e_cal_backend_store_clean, e_cal_backend_cache_remove.
- Date: Mon, 20 Jul 2009 20:02:27 +0000 (UTC)
commit db3fa5b3f81a98e39aa7c97fa3528237d9b463f3
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Tue Jul 21 01:22:37 2009 +0530
Added api's e_cal_backend_store_clean, e_cal_backend_cache_remove.
Fixed a memory leak.
calendar/libedata-cal/e-cal-backend-cache.c | 46 ++++++++++++++++++++++
calendar/libedata-cal/e-cal-backend-cache.h | 2 +
calendar/libedata-cal/e-cal-backend-file-store.c | 24 +++++++++++-
calendar/libedata-cal/e-cal-backend-store.c | 24 +++++++++++-
calendar/libedata-cal/e-cal-backend-store.h | 7 ++-
5 files changed, 99 insertions(+), 4 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend-cache.c b/calendar/libedata-cal/e-cal-backend-cache.c
index e5ac4c8..c4dc028 100644
--- a/calendar/libedata-cal/e-cal-backend-cache.c
+++ b/calendar/libedata-cal/e-cal-backend-cache.c
@@ -891,3 +891,49 @@ e_cal_backend_cache_get_key_value (ECalBackendCache *cache, const gchar *key)
return value;
}
+
+gboolean
+e_cal_backend_cache_remove (const gchar *uri, ECalSourceType source_type)
+{
+ gchar *filename;
+
+ filename = get_filename_from_uri (uri, source_type);
+
+ if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ gchar *dirname, *full_path;
+ const gchar *fname;
+ GDir *dir;
+ gboolean success;
+
+ /* remove all files in the directory */
+ dirname = g_path_get_dirname (filename);
+ dir = g_dir_open (dirname, 0, NULL);
+ if (dir) {
+ while ((fname = g_dir_read_name (dir))) {
+ full_path = g_build_filename (dirname, fname, NULL);
+ if (g_unlink (full_path) != 0) {
+ g_free (full_path);
+ g_free (dirname);
+ g_dir_close (dir);
+
+ return FALSE;
+ }
+
+ g_free (full_path);
+ }
+
+ g_dir_close (dir);
+ }
+
+ /* remove the directory itself */
+ success = g_rmdir (dirname) == 0;
+
+ /* free all memory */
+ g_free (dirname);
+ g_free (filename);
+ return success;
+ }
+
+ g_free (filename);
+ return FALSE;
+}
diff --git a/calendar/libedata-cal/e-cal-backend-cache.h b/calendar/libedata-cal/e-cal-backend-cache.h
index 4395919..09490d7 100644
--- a/calendar/libedata-cal/e-cal-backend-cache.h
+++ b/calendar/libedata-cal/e-cal-backend-cache.h
@@ -77,6 +77,8 @@ const gchar * e_cal_backend_cache_get_server_utc_time (ECalBackendCache *cache);
gboolean e_cal_backend_cache_put_key_value (ECalBackendCache *cache, const gchar *key, const gchar *value);
const gchar * e_cal_backend_cache_get_key_value (ECalBackendCache *cache, const gchar *key);
+gboolean e_cal_backend_cache_remove (const gchar *uri, ECalSourceType source_type);
+
G_END_DECLS
#endif
diff --git a/calendar/libedata-cal/e-cal-backend-file-store.c b/calendar/libedata-cal/e-cal-backend-file-store.c
index 1790d32..0c1df92 100644
--- a/calendar/libedata-cal/e-cal-backend-file-store.c
+++ b/calendar/libedata-cal/e-cal-backend-file-store.c
@@ -672,7 +672,7 @@ e_cal_backend_file_store_load (ECalBackendStore *store)
scan_vcalendar (fstore, icalcomp);
icalcomponent_free (icalcomp);
-
+
return TRUE;
}
@@ -696,6 +696,26 @@ e_cal_backend_file_store_remove (ECalBackendStore *store)
return TRUE;
}
+static gboolean
+e_cal_backend_file_store_clean (ECalBackendStore *store)
+{
+ ECalBackendFileStore *fstore = E_CAL_BACKEND_FILE_STORE (store);
+ ECalBackendFileStorePrivate *priv;
+
+ priv = GET_PRIVATE (store);
+
+ g_static_rw_lock_writer_lock (&priv->lock);
+
+ e_file_cache_clean (priv->keys_cache);
+ g_hash_table_remove_all (priv->comp_uid_hash);
+ g_hash_table_remove_all (priv->timezones);
+
+ g_static_rw_lock_writer_unlock (&priv->lock);
+
+ save_cache (fstore);
+ return TRUE;
+}
+
static void
save_instance (gpointer key, gpointer value, gpointer user_data)
{
@@ -857,6 +877,7 @@ e_cal_backend_file_store_finalize (GObject *object)
priv->dirty = FALSE;
priv->freeze_changes = FALSE;
+ g_static_rw_lock_free (&priv->lock);
G_OBJECT_CLASS (e_cal_backend_file_store_parent_class)->finalize (object);
}
@@ -874,6 +895,7 @@ e_cal_backend_file_store_class_init (ECalBackendFileStoreClass *klass)
store_class->load = e_cal_backend_file_store_load;
store_class->remove = e_cal_backend_file_store_remove;
+ store_class->clean = e_cal_backend_file_store_clean;
store_class->get_component = e_cal_backend_file_store_get_component;
store_class->put_component = e_cal_backend_file_store_put_component;
store_class->remove_component = e_cal_backend_file_store_remove_component;
diff --git a/calendar/libedata-cal/e-cal-backend-store.c b/calendar/libedata-cal/e-cal-backend-store.c
index fbdef34..1441314 100644
--- a/calendar/libedata-cal/e-cal-backend-store.c
+++ b/calendar/libedata-cal/e-cal-backend-store.c
@@ -30,6 +30,7 @@ struct _ECalBackendStorePrivate {
ECalSourceType source_type;
gchar *uri;
gchar *path;
+ gboolean loaded;
};
/* Property IDs */
@@ -176,6 +177,8 @@ e_cal_backend_store_class_init (ECalBackendStoreClass *klass)
object_class->get_property = e_cal_backend_store_get_property;
klass->load = NULL;
+ klass->remove = NULL;
+ klass->clean = NULL;
klass->get_component = NULL;
klass->put_component = NULL;
klass->remove_component = NULL;
@@ -210,6 +213,7 @@ e_cal_backend_store_init (ECalBackendStore *store)
priv->uri = NULL;
priv->path = NULL;
priv->source_type = E_CAL_SOURCE_TYPE_EVENT;
+ priv->loaded = FALSE;
}
const gchar *
@@ -228,10 +232,19 @@ e_cal_backend_store_get_path (ECalBackendStore *store)
gboolean
e_cal_backend_store_load (ECalBackendStore *store)
{
+ ECalBackendStorePrivate *priv;
+
g_return_val_if_fail (store != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), FALSE);
- return (E_CAL_BACKEND_STORE_GET_CLASS (store))->load (store);
+ priv = GET_PRIVATE(store);
+
+ if (priv->loaded)
+ return TRUE;
+
+ priv->loaded = (E_CAL_BACKEND_STORE_GET_CLASS (store))->load (store);
+
+ return priv->loaded;
}
gboolean
@@ -243,6 +256,15 @@ e_cal_backend_store_remove (ECalBackendStore *store)
return (E_CAL_BACKEND_STORE_GET_CLASS (store))->remove (store);
}
+gboolean
+e_cal_backend_store_clean (ECalBackendStore *store)
+{
+ g_return_val_if_fail (store != NULL, FALSE);
+ g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), FALSE);
+
+ return (E_CAL_BACKEND_STORE_GET_CLASS (store))->clean (store);
+}
+
ECalComponent *
e_cal_backend_store_get_component (ECalBackendStore *store, const gchar *uid, const gchar *rid)
{
diff --git a/calendar/libedata-cal/e-cal-backend-store.h b/calendar/libedata-cal/e-cal-backend-store.h
index 8cef0f2..8578ced 100644
--- a/calendar/libedata-cal/e-cal-backend-store.h
+++ b/calendar/libedata-cal/e-cal-backend-store.h
@@ -58,6 +58,7 @@ typedef struct {
/* virtual methods */
gboolean (*load) (ECalBackendStore *store);
gboolean (*remove) (ECalBackendStore *store);
+ gboolean (*clean) (ECalBackendStore *store);
ECalComponent * (*get_component) (ECalBackendStore *store, const gchar *uid, const gchar *rid);
gboolean (*put_component) (ECalBackendStore *store, ECalComponent *comp);
@@ -78,8 +79,8 @@ typedef struct {
void (*thaw_changes) (ECalBackendStore *store);
void (*freeze_changes) (ECalBackendStore *store);
- const gchar *(*get_key_value) (ECalBackendStore *store, const gchar *key);
- gboolean (*put_key_value) (ECalBackendStore *store, const gchar *key, const gchar *value);
+ const gchar * (*get_key_value) (ECalBackendStore *store, const gchar *key);
+ gboolean (*put_key_value) (ECalBackendStore *store, const gchar *key, const gchar *value);
} ECalBackendStoreClass;
@@ -88,7 +89,9 @@ GType e_cal_backend_store_get_type (void);
const gchar *e_cal_backend_store_get_path (ECalBackendStore *store);
gboolean e_cal_backend_store_load (ECalBackendStore *store);
+gboolean e_cal_backend_store_is_loaded (ECalBackendStore *store);
gboolean e_cal_backend_store_remove (ECalBackendStore *store);
+gboolean e_cal_backend_store_clean (ECalBackendStore *store);
ECalComponent * e_cal_backend_store_get_component (ECalBackendStore *store, const gchar *uid, const gchar *rid);
gboolean e_cal_backend_store_put_component (ECalBackendStore *store, ECalComponent *comp);
gboolean e_cal_backend_store_remove_component (ECalBackendStore *store, const gchar *uid, const gchar *rid);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]