aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2008-11-19 04:52:32 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2008-11-19 04:52:32 +0000
commitfe9f255aa83af29fc78c04357a48bbc4900e47ba (patch)
tree2d8d9bdcb5953985d7700d5756f8ac4dc197e493
parent5ce80c8f8e2cc1895183f2e5e1b90b4ca3fbc741 (diff)
keep backups of config files for four generations.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2071 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog5
-rw-r--r--ChangeLog.ja5
-rw-r--r--libsylph/prefs.c48
3 files changed, 43 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 50c7348c..c960a8d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-19
+
+ * libsylph/prefs.c: prefs_file_close(): keep backups for four
+ generations.
+
2008-11-14
* version 2.6.0beta2
diff --git a/ChangeLog.ja b/ChangeLog.ja
index f9bf4ddb..1c793b59 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,8 @@
+2008-11-19
+
+ * libsylph/prefs.c: prefs_file_close(): 4世代にわたってバックアップ
+ を保持するようにした。
+
2008-11-14
* version 2.6.0beta2
diff --git a/libsylph/prefs.c b/libsylph/prefs.c
index 030cc746..230d2dc5 100644
--- a/libsylph/prefs.c
+++ b/libsylph/prefs.c
@@ -348,6 +348,7 @@ gint prefs_file_close(PrefFile *pfile)
gchar *path;
gchar *tmppath;
gchar *bakpath = NULL;
+ gint ret = 0;
g_return_val_if_fail(pfile != NULL, -1);
@@ -358,37 +359,54 @@ gint prefs_file_close(PrefFile *pfile)
tmppath = g_strconcat(path, ".tmp", NULL);
if (fclose(fp) == EOF) {
FILE_OP_ERROR(tmppath, "fclose");
- g_unlink(tmppath);
- g_free(path);
- g_free(tmppath);
- return -1;
+ ret = -1;
+ goto finish;
}
if (is_file_exist(path)) {
bakpath = g_strconcat(path, ".bak", NULL);
+ if (is_file_exist(bakpath)) {
+ gint i;
+ gchar *bakpath_n, *bakpath_p;
+
+ for (i = 4; i > 0; i--) {
+ bakpath_n = g_strdup_printf("%s.%d", bakpath,
+ i);
+ if (i == 1)
+ bakpath_p = g_strdup(bakpath);
+ else
+ bakpath_p = g_strdup_printf
+ ("%s.%d", bakpath, i - 1);
+ if (is_file_exist(bakpath_p)) {
+ if (rename_force(bakpath_p, bakpath_n) < 0) {
+ FILE_OP_ERROR(bakpath_p,
+ "rename");
+ }
+ }
+ g_free(bakpath_p);
+ g_free(bakpath_n);
+ }
+ }
if (rename_force(path, bakpath) < 0) {
FILE_OP_ERROR(path, "rename");
- g_unlink(tmppath);
- g_free(path);
- g_free(tmppath);
- g_free(bakpath);
- return -1;
+ ret = -1;
+ goto finish;
}
}
if (rename_force(tmppath, path) < 0) {
FILE_OP_ERROR(tmppath, "rename");
- g_unlink(tmppath);
- g_free(path);
- g_free(tmppath);
- g_free(bakpath);
- return -1;
+ ret = -1;
+ goto finish;
}
+finish:
+ if (ret < 0)
+ g_unlink(tmppath);
g_free(path);
g_free(tmppath);
g_free(bakpath);
- return 0;
+ return ret;
}
gint prefs_file_close_revert(PrefFile *pfile)