From 9fcbc8f335c4322c6e4167e0356bfb9802e5edb6 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 24 Jul 2002 15:13:43 +0000 Subject: When writing the summary, use TRUNC flag, duh. Also, write to a temp file 2002-07-25 Not Zed * 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 * camel-partition-table.c (camel_key_table_next): Didn't unlock if we exited on an empty key list. svn path=/trunk/; revision=17570 --- camel/camel-folder-summary.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'camel/camel-folder-summary.c') 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;isummary_path) == -1) { + i = errno; + unlink(path); + errno = i; + return -1; + } s->flags &= ~CAMEL_SUMMARY_DIRTY; return 0; -- cgit v1.2.3