From 86061c474bf60aea3fa03d65033ea277fc7e99ce Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Wed, 20 Sep 2000 03:58:06 +0000 Subject: New utility function (cal_backend_load): use above (cal_backend_create): 2000-09-19 JP Rosevear * pcs/cal-backend.c (cal_backend_set_uri): New utility function (cal_backend_load): use above (cal_backend_create): use above (cal_backend_log_name): Take a uri instead of a backend param * pcs/cal-backend-file.c: Get rid of useless hash functions (cal_backend_file_load): Check to make sure path exists and is local (cal_backend_file_load): Unref the current uri if there is one (cal_backend_file_create): ditto * pcs/cal-backend.c (cal_backend_last_client_gone): Sync before shooting ourselves in the foot * pcs/cal-backend-file.c (save): Fully implement backing up the calendar before writing out the new entry. svn path=/trunk/; revision=5516 --- calendar/pcs/cal-backend-file.c | 66 ++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'calendar/pcs/cal-backend-file.c') diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index c4a047a262..959224db6a 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -182,20 +182,6 @@ free_cal_component (gpointer key, gpointer value, gpointer data) gtk_object_unref (GTK_OBJECT (comp)); } -/* For hashing pilot id's */ -/* FIX ME, these are not unique */ -static guint -cbf_pilot_hash (gconstpointer v) -{ - return *(const guint*) v; -} - -static gint -cbf_pilot_equal (gconstpointer v1, gconstpointer v2) -{ - return *((const unsigned long*) v1) == *((const unsigned long*) v2); -} - /* Saves the calendar data */ static void save (CalBackendFile *cbfile) @@ -204,20 +190,36 @@ save (CalBackendFile *cbfile) GnomeVFSHandle *handle = NULL; GnomeVFSResult result; GnomeVFSFileSize out; - GnomeVFSURI *backup_uri; + gchar *tmp; char *buf; priv = cbfile->priv; g_assert (priv->uri != NULL); g_assert (priv->icalcomp != NULL); - /* Make a backup copy of the file */ - backup_uri = gnome_vfs_uri_append_file_name (priv->uri, "~"); - result = gnome_vfs_move_uri (priv->uri, backup_uri, TRUE); - gnome_vfs_uri_unref (backup_uri); + /* Make a backup copy of the file if it exists */ + if (gnome_vfs_uri_exists (priv->uri)) { + tmp = gnome_vfs_uri_to_string (priv->uri, GNOME_VFS_URI_HIDE_NONE); + if (tmp) { + GnomeVFSURI *backup_uri; + gchar *backup_uristr; + + backup_uristr = g_strconcat (tmp, "~", NULL); + backup_uri = gnome_vfs_uri_new (backup_uristr); + + result = gnome_vfs_move_uri (priv->uri, backup_uri, TRUE); + gnome_vfs_uri_unref (backup_uri); + + g_free (tmp); + g_free (backup_uristr); + } + } else { + result = GNOME_VFS_OK; + } + -// if (result != GNOME_VFS_OK) -// goto error; + if (result != GNOME_VFS_OK) + goto error; /* Now write the new file out */ result = gnome_vfs_create_uri (&handle, priv->uri, @@ -642,9 +644,11 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri) g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_LOAD_ERROR); g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR); - /* FIXME: this looks rather bad; maybe we should check for local files - * and fail if they are remote. - */ + if (!gnome_vfs_uri_is_local (uri)) + return CAL_BACKEND_LOAD_ERROR; + + if (!gnome_vfs_uri_exists (uri)) + return CAL_BACKEND_LOAD_ERROR;; str_uri = gnome_vfs_uri_to_string (uri, (GNOME_VFS_URI_HIDE_USER_NAME @@ -654,7 +658,6 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri) | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD)); /* Load! */ - file = fopen (str_uri, "r"); g_free (str_uri); @@ -683,12 +686,13 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri) priv->icalcomp = icalcomp; priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); -/* priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); */ priv->comp_pilot_hash = g_hash_table_new (g_int_hash, g_int_equal); scan_vcalendar (cbfile); /* Clean up */ - + if (priv->uri) + gnome_vfs_uri_unref (uri); + gnome_vfs_uri_ref (uri); priv->uri = uri; @@ -730,13 +734,13 @@ cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri) g_assert (priv->comp_uid_hash == NULL); priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); -/* priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); */ priv->comp_pilot_hash = g_hash_table_new (g_int_hash, g_int_equal); - /* Done */ - + /* Clean up */ + if (priv->uri) + gnome_vfs_uri_unref (priv->uri); + gnome_vfs_uri_ref (uri); - priv->uri = uri; mark_dirty (cbfile); -- cgit v1.2.3