From: Timo Sirainen Date: Thu, 8 May 2003 05:08:29 +0000 (+0300) Subject: Don't try to rewrite mbox file if it's read-only. X-Git-Tag: 1.1.alpha1~4660 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a23eb06b7285b1c90d1da192d36cbb3444e234f;p=thirdparty%2Fdovecot%2Fcore.git Don't try to rewrite mbox file if it's read-only. --HG-- branch : HEAD --- diff --git a/src/lib-index/mbox/mbox-append.c b/src/lib-index/mbox/mbox-append.c index 6c8533665f..e31626b29a 100644 --- a/src/lib-index/mbox/mbox-append.c +++ b/src/lib-index/mbox/mbox-append.c @@ -93,7 +93,13 @@ static int mbox_index_append_next(struct mail_index *index, if (index->header->messages_count == 0 && ctx.uid_validity != index->header->uid_validity) { /* UID validity is different */ - if (ctx.uid_validity == 0) { + if (ctx.uid_validity != 0) { + /* change it in index */ + index->header->uid_validity = ctx.uid_validity; + index->header->next_uid = 1; + index->header->last_nonrecent_uid = 0; + index->inconsistent = TRUE; + } else if (!index->mailbox_readonly) { /* we have to write it to mbox */ if (index->mbox_lock_type != MAIL_LOCK_EXCLUSIVE) { /* try again */ @@ -103,12 +109,6 @@ static int mbox_index_append_next(struct mail_index *index, MAIL_INDEX_FLAG_DIRTY_MESSAGES; rec->index_flags |= INDEX_MAIL_FLAG_DIRTY; } - } else { - /* change it in index */ - index->header->uid_validity = ctx.uid_validity; - index->header->next_uid = 1; - index->header->last_nonrecent_uid = 0; - index->inconsistent = TRUE; } } @@ -116,7 +116,7 @@ static int mbox_index_append_next(struct mail_index *index, /* X-UID header looks ok */ if (ret != 0) index->header->next_uid = ctx.uid; - dirty = ctx.content_length_broken && !index->mailbox_readonly; + dirty = ctx.content_length_broken; } else if (!index->mailbox_readonly) { /* Write X-UID for it */ dirty = TRUE; @@ -128,7 +128,7 @@ static int mbox_index_append_next(struct mail_index *index, dirty = FALSE; } - if (dirty) { + if (dirty && !index->mailbox_readonly) { if (index->mbox_lock_type != MAIL_LOCK_EXCLUSIVE) { /* try again */ ret = 0; diff --git a/src/lib-index/mbox/mbox-rewrite.c b/src/lib-index/mbox/mbox-rewrite.c index 11efb3f1f8..da42893567 100644 --- a/src/lib-index/mbox/mbox-rewrite.c +++ b/src/lib-index/mbox/mbox-rewrite.c @@ -569,6 +569,7 @@ int mbox_index_rewrite(struct mail_index *index) unsigned int seq; int tmp_fd, failed, dirty_found, rewrite, no_locking; + i_assert(!index->mailbox_readonly); i_assert(index->lock_type == MAIL_LOCK_UNLOCK || (index->lock_type == MAIL_LOCK_EXCLUSIVE && index->mbox_lock_type == MAIL_LOCK_EXCLUSIVE)); diff --git a/src/lib-index/mbox/mbox-sync.c b/src/lib-index/mbox/mbox-sync.c index 2d3d226465..b975db7e02 100644 --- a/src/lib-index/mbox/mbox-sync.c +++ b/src/lib-index/mbox/mbox-sync.c @@ -75,6 +75,13 @@ int mbox_index_sync(struct mail_index *index, i_assert(index->lock_type != MAIL_LOCK_SHARED); + if (index->mailbox_readonly && data_lock_type == MAIL_LOCK_EXCLUSIVE) { + index_set_error(index, "sync: %s is read-only, " + "can't get exclusive lock", + index->mailbox_path); + return FALSE; + } + if (changes != NULL) *changes = FALSE;