Mercurial > dovecot > core-2.2
changeset 599:a7691dc0a869 HEAD
If mbox file is deleted for selected folder, recreate it again so we can
handle locking issues properly. For example mutt deletes the mbox when all
mails are expunged.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 12 Nov 2002 05:58:02 +0200 |
parents | 26691b7d6203 |
children | 3b44bc64afd4 |
files | src/lib-index/mbox/mbox-sync.c |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mbox/mbox-sync.c Thu Nov 07 05:28:48 2002 +0200 +++ b/src/lib-index/mbox/mbox-sync.c Tue Nov 12 05:58:02 2002 +0200 @@ -71,6 +71,7 @@ struct stat st; time_t index_mtime; uoff_t filesize; + int count, fd; i_assert(index->lock_type != MAIL_LOCK_SHARED); @@ -86,8 +87,20 @@ index_mtime = st.st_mtime; } - if (stat(index->mbox_path, &st) < 0) - return mbox_set_syscall_error(index, "stat()"); + count = 0; + while (stat(index->mbox_path, &st) < 0) { + if (errno != ENOENT || ++count == 3) + return mbox_set_syscall_error(index, "stat()"); + + /* mbox was deleted by someone - happens with some MUAs + when all mail is expunged. easiest way to deal with this + is to recreate the file. */ + fd = open(index->mbox_path, O_RDWR | O_CREAT | O_EXCL, 0660); + if (fd != -1) + (void)close(fd); + else if (errno != EEXIST) + return mbox_set_syscall_error(index, "open()"); + } filesize = st.st_size; if (index->mbox_dev != st.st_dev || index->mbox_ino != st.st_ino) {