diff options
author | 4 <NotZed@Ximian.com> | 2001-10-05 04:25:18 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-10-05 04:25:18 +0800 |
commit | 840bb7f136f27d2292be4890d6fb113604d2257b (patch) | |
tree | 5a487d86f7a30f05d6b36ed67392d5e7cd87c3dd | |
parent | 46e6d93b25d95e1797e8fdb95a0ebd1c45154436 (diff) | |
download | gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar.gz gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar.bz2 gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar.lz gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar.xz gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.tar.zst gsoc2013-evolution-840bb7f136f27d2292be4890d6fb113604d2257b.zip |
"safe" save code, first save to .#name, then rename to name if it worked,
2001-10-04 <NotZed@Ximian.com>
* rule-context.c (save): "safe" save code, first save to .#name,
then rename to name if it worked, also create backups to name~.
Means filters/etc wont get reset/lost if disk fills up, although
relies on libxml failing properly.
(new_rule_clicked): Removed warning, we do now have changed
signals!
svn path=/trunk/; revision=13422
-rw-r--r-- | filter/ChangeLog | 9 | ||||
-rw-r--r-- | filter/rule-context.c | 27 |
2 files changed, 31 insertions, 5 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index c260cb8fb8..bce28d210e 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,12 @@ +2001-10-04 <NotZed@Ximian.com> + + * rule-context.c (save): "safe" save code, first save to .#name, + then rename to name if it worked, also create backups to name~. + Means filters/etc wont get reset/lost if disk fills up, although + relies on libxml failing properly. + (new_rule_clicked): Removed warning, we do now have changed + signals! + 2001-09-28 <NotZed@Ximian.com> * vfolder-rule.c (vfolder_rule_add_source): Emit changed events diff --git a/filter/rule-context.c b/filter/rule-context.c index 389ef7296a..f77f77b9d0 100644 --- a/filter/rule-context.c +++ b/filter/rule-context.c @@ -22,6 +22,10 @@ #include <config.h> #endif +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif + #include <errno.h> #include <string.h> #include <gtk/gtksignal.h> @@ -356,6 +360,8 @@ save (RuleContext *f, const char *user) GList *l; FilterRule *rule; struct _rule_set_map *map; + char *usersav, *userbak, *slash; + int ret; doc = xmlNewDoc ("1.0"); root = xmlNewDocNode (doc, NULL, "filteroptions", NULL); @@ -373,9 +379,23 @@ save (RuleContext *f, const char *user) } l = g_list_next (l); } - xmlSaveFile (user, doc); + + usersav = alloca(strlen(user)+5); + userbak = alloca(strlen(user)+5); + slash = strrchr(user, '/'); + if (slash) + sprintf(usersav, "%.*s.#%s", slash-user+1, user, slash+1); + else + sprintf(usersav, ".#%s", user); + sprintf(userbak, "%s~", user); + printf("saving rules to '%s' then backup '%s'\n", usersav, userbak); + ret = xmlSaveFile(usersav, doc); + if (ret != -1) { + rename(user, userbak); + ret = rename(usersav, user); + } xmlFreeDoc (doc); - return 0; + return ret; } FilterPart * @@ -432,9 +452,6 @@ rule_context_add_rule (RuleContext *f, FilterRule *new) static void new_rule_clicked (GtkWidget *dialog, int button, RuleContext *context) { -#ifndef NO_WARNINGS -#warning "Need a changed signal for this to work best" -#endif if (button == 0) { FilterRule *rule = gtk_object_get_data (GTK_OBJECT (dialog), "rule"); char *user = gtk_object_get_data (GTK_OBJECT (dialog), "path"); |