aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-folder-summary.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-07-24 23:13:43 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-07-24 23:13:43 +0800
commit9fcbc8f335c4322c6e4167e0356bfb9802e5edb6 (patch)
tree86ad5969e40e256b8bedc65b813c9563c14cf40a /camel/camel-folder-summary.c
parent710ba7ca95b2fec221f7d0fd861e7f1d803aabec (diff)
downloadgsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar.gz
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar.bz2
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar.lz
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar.xz
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.tar.zst
gsoc2013-evolution-9fcbc8f335c4322c6e4167e0356bfb9802e5edb6.zip
When writing the summary, use TRUNC flag, duh. Also, write to a temp file
2002-07-25 Not Zed <NotZed@Ximian.com> * camel-folder-summary.c (camel_folder_summary_save): When writing the summary, use TRUNC flag, duh. Also, write to a temp file first, and rename when closed successfully, and check ferror() and fclose() against 0 rather than -1. * providers/local/camel-mbox-summary.c (summary_update): Decrement i if we remove the summary item so we dont skip every 2nd one. * camel-mime-utils.c (header_decode_mailbox): Use rfc2047_decode_word explicitly incase we just found an encoded word. Stops us re-decoding the string twice, which fixes memory corruption in #26330 when the HUGE string is used later. 2002-07-24 Not Zed <NotZed@Ximian.com> * camel-partition-table.c (camel_key_table_next): Didn't unlock if we exited on an empty key list. svn path=/trunk/; revision=17570
Diffstat (limited to 'camel/camel-folder-summary.c')
-rw-r--r--camel/camel-folder-summary.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 665ffab795..b7024ec84e 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -629,17 +629,23 @@ camel_folder_summary_save(CamelFolderSummary *s)
int i;
guint32 count;
CamelMessageInfo *mi;
+ char *path;
if (s->summary_path == NULL
|| (s->flags & CAMEL_SUMMARY_DIRTY) == 0)
return 0;
- fd = open(s->summary_path, O_RDWR|O_CREAT, 0600);
+ path = alloca(strlen(s->summary_path)+4);
+ sprintf(path, "%s~", s->summary_path);
+ fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (fd == -1)
return -1;
out = fdopen(fd, "w");
if ( out == NULL ) {
+ i = errno;
+ unlink(path);
close(fd);
+ errno = i;
return -1;
}
@@ -648,13 +654,16 @@ camel_folder_summary_save(CamelFolderSummary *s)
CAMEL_SUMMARY_LOCK(s, io_lock);
if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_save(s, out) == -1) {
+ i = errno;
fclose(out);
CAMEL_SUMMARY_UNLOCK(s, io_lock);
+ unlink(path);
+ errno = i;
return -1;
}
/* now write out each message ... */
- /* FIXME: check returns */
+ /* we check ferorr when done for i/o errors */
count = s->messages->len;
for (i=0;i<count;i++) {
@@ -668,8 +677,19 @@ camel_folder_summary_save(CamelFolderSummary *s)
CAMEL_SUMMARY_UNLOCK(s, io_lock);
- if (fclose(out) == -1)
+ if (ferror(out) != 0 || fclose(out) != 0) {
+ i = errno;
+ unlink(path);
+ errno = i;
return -1;
+ }
+
+ if (rename(path, s->summary_path) == -1) {
+ i = errno;
+ unlink(path);
+ errno = i;
+ return -1;
+ }
s->flags &= ~CAMEL_SUMMARY_DIRTY;
return 0;