2007-10-03 [colin] 3.0.2cvs6

* src/common/template.c
		Fix templates writing (was prone to disk full problems)
This commit is contained in:
Colin Leroy 2007-10-03 18:38:34 +00:00
parent 593bb2c12c
commit 944950effc
4 changed files with 46 additions and 17 deletions

View file

@ -1,3 +1,8 @@
2007-10-03 [colin] 3.0.2cvs6
* src/common/template.c
Fix templates writing (was prone to disk full problems)
2007-10-03 [colin] 3.0.2cvs5
* src/Makefile.am

View file

@ -2918,3 +2918,4 @@
( cvs diff -u -r 1.115.2.167 -r 1.115.2.168 src/main.c; cvs diff -u -r 1.36.2.114 -r 1.36.2.115 src/common/utils.c; cvs diff -u -r 1.20.2.51 -r 1.20.2.52 src/common/utils.h; ) > 3.0.2cvs3.patchset
( cvs diff -u -r 1.75.2.48 -r 1.75.2.49 src/matcher.c; cvs diff -u -r 1.1.2.78 -r 1.1.2.79 src/gtk/quicksearch.c; ) > 3.0.2cvs4.patchset
( cvs diff -u -r 1.155.2.75 -r 1.155.2.76 src/Makefile.am; diff -u /dev/null src/addrduplicates.c; diff -u /dev/null src/addrduplicates.h; cvs diff -u -r 1.60.2.98 -r 1.60.2.99 src/addressbook.c; ) > 3.0.2cvs5.patchset
( cvs diff -u -r 1.2.4.20 -r 1.2.4.21 src/common/template.c; ) > 3.0.2cvs6.patchset

View file

@ -11,7 +11,7 @@ MINOR_VERSION=0
MICRO_VERSION=2
INTERFACE_AGE=0
BINARY_AGE=0
EXTRA_VERSION=5
EXTRA_VERSION=6
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=

View file

@ -188,6 +188,18 @@ GSList *template_read_config(void)
return tmpl_list;
}
#define TRY(func) { \
if (!(func)) \
{ \
g_warning("Failed to write template to file\n"); \
if (fp) fclose(fp); \
if (new) g_unlink(new); \
g_free(new); \
g_free(filename); \
return; \
} \
}
void template_write_config(GSList *tmpl_list)
{
const gchar *path;
@ -209,39 +221,50 @@ void template_write_config(GSList *tmpl_list)
return;
}
remove_all_files(path);
for (cur = tmpl_list, tmpl_num = 1; cur != NULL;
cur = cur->next, tmpl_num++) {
gchar *filename;
gchar *filename, *new = NULL;
tmpl = cur->data;
filename = g_strconcat(path, G_DIR_SEPARATOR_S,
itos(tmpl_num), NULL);
if ((fp = g_fopen(filename, "wb")) == NULL) {
FILE_OP_ERROR(filename, "fopen");
if (is_file_exist(filename)) {
new = g_strconcat(filename, ".new", NULL);
}
if ((fp = g_fopen(new?new:filename, "wb")) == NULL) {
FILE_OP_ERROR(new?new:filename, "fopen");
g_free(new);
g_free(filename);
return;
}
fprintf(fp, "Name: %s\n", tmpl->name);
TRY(fprintf(fp, "Name: %s\n", tmpl->name) > 0);
if (tmpl->subject && *tmpl->subject != '\0')
fprintf(fp, "Subject: %s\n", tmpl->subject);
TRY(fprintf(fp, "Subject: %s\n", tmpl->subject) > 0);
if (tmpl->to && *tmpl->to != '\0')
fprintf(fp, "To: %s\n", tmpl->to);
TRY(fprintf(fp, "To: %s\n", tmpl->to) > 0);
if (tmpl->cc && *tmpl->cc != '\0')
fprintf(fp, "Cc: %s\n", tmpl->cc);
TRY(fprintf(fp, "Cc: %s\n", tmpl->cc) > 0);
if (tmpl->bcc && *tmpl->bcc != '\0')
fprintf(fp, "Bcc: %s\n", tmpl->bcc);
fputs("\n", fp);
if (tmpl->value && *tmpl->value != '\0')
fwrite(tmpl->value, sizeof(gchar), strlen(tmpl->value), fp);
else
fwrite("", sizeof(gchar), 1, fp);
TRY(fprintf(fp, "Bcc: %s\n", tmpl->bcc) > 0);
fclose(fp);
TRY(fputs("\n", fp) != EOF);
if (tmpl->value && *tmpl->value != '\0') {
TRY(fwrite(tmpl->value, sizeof(gchar), strlen(tmpl->value), fp) == strlen(tmpl->value));
} else {
TRY(fwrite("", sizeof(gchar), 1, fp) == 1);
}
TRY(fclose(fp) != EOF);
if (new) {
g_unlink(filename);
rename_force(new, filename);
}
g_free(new);
g_free(filename);
}
}