diff options
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/pop.c | 3 | ||||
-rw-r--r-- | libsylph/prefs.c | 40 | ||||
-rw-r--r-- | libsylph/prefs.h | 15 |
3 files changed, 46 insertions, 12 deletions
diff --git a/libsylph/pop.c b/libsylph/pop.c index 25774cbd..57d7fd2b 100644 --- a/libsylph/pop.c +++ b/libsylph/pop.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2006 Hiroyuki Yamamoto + * Copyright (C) 1999-2008 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -543,6 +543,7 @@ gint pop3_write_uidl_list(Pop3Session *session) g_free(path); return -1; } + prefs_file_set_backup_generation(pfile, 0); for (n = 1; n <= session->count; n++) { msg = &session->msg[n]; diff --git a/libsylph/prefs.c b/libsylph/prefs.c index 230d2dc5..d2e01d2a 100644 --- a/libsylph/prefs.c +++ b/libsylph/prefs.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2008 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,6 +38,14 @@ typedef enum DUMMY_PARAM } DummyEnum; +typedef struct _PrefFilePrivate PrefFilePrivate; + +struct _PrefFilePrivate { + FILE *fp; + gchar *path; + gint backup_generation; +}; + static void prefs_config_parse_one_line (GHashTable *param_table, const gchar *buf); @@ -317,7 +325,7 @@ gint prefs_file_write_param(PrefFile *pfile, PrefParam *param) PrefFile *prefs_file_open(const gchar *path) { - PrefFile *pfile; + PrefFilePrivate *pfile; gchar *tmppath; FILE *fp; @@ -335,25 +343,47 @@ PrefFile *prefs_file_open(const gchar *path) g_free(tmppath); - pfile = g_new(PrefFile, 1); + pfile = g_new(PrefFilePrivate, 1); pfile->fp = fp; pfile->path = g_strdup(path); + pfile->backup_generation = 4; + + return (PrefFile *)pfile; +} + +void prefs_file_set_backup_generation(PrefFile *pfile, gint generation) +{ + PrefFilePrivate *priv = (PrefFilePrivate *)pfile; + + g_return_if_fail(pfile != NULL); + + priv->backup_generation = generation; +} + +gint prefs_file_get_backup_generation(PrefFile *pfile) +{ + PrefFilePrivate *priv = (PrefFilePrivate *)pfile; + + g_return_val_if_fail(pfile != NULL, -1); - return pfile; + return priv->backup_generation; } gint prefs_file_close(PrefFile *pfile) { + PrefFilePrivate *priv = (PrefFilePrivate *)pfile; FILE *fp; gchar *path; gchar *tmppath; gchar *bakpath = NULL; + gint generation; gint ret = 0; g_return_val_if_fail(pfile != NULL, -1); fp = pfile->fp; path = pfile->path; + generation = priv->backup_generation; g_free(pfile); tmppath = g_strconcat(path, ".tmp", NULL); @@ -369,7 +399,7 @@ gint prefs_file_close(PrefFile *pfile) gint i; gchar *bakpath_n, *bakpath_p; - for (i = 4; i > 0; i--) { + for (i = generation; i > 0; i--) { bakpath_n = g_strdup_printf("%s.%d", bakpath, i); if (i == 1) diff --git a/libsylph/prefs.h b/libsylph/prefs.h index fd4783ba..733c42da 100644 --- a/libsylph/prefs.h +++ b/libsylph/prefs.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2008 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -65,11 +65,14 @@ void prefs_write_config (PrefParam *param, const gchar *label, const gchar *rcfile); -PrefFile *prefs_file_open (const gchar *path); -gint prefs_file_write_param (PrefFile *pfile, - PrefParam *param); -gint prefs_file_close (PrefFile *pfile); -gint prefs_file_close_revert (PrefFile *pfile); +PrefFile *prefs_file_open (const gchar *path); +gint prefs_file_write_param (PrefFile *pfile, + PrefParam *param); +void prefs_file_set_backup_generation (PrefFile *pfile, + gint generation); +gint prefs_file_get_backup_generation (PrefFile *pfile); +gint prefs_file_close (PrefFile *pfile); +gint prefs_file_close_revert (PrefFile *pfile); void prefs_set_default (PrefParam *param); void prefs_free (PrefParam *param); |