]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't try to rewrite mbox file if it's read-only.
authorTimo Sirainen <tss@iki.fi>
Thu, 8 May 2003 05:08:29 +0000 (08:08 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 8 May 2003 05:08:29 +0000 (08:08 +0300)
--HG--
branch : HEAD

src/lib-index/mbox/mbox-append.c
src/lib-index/mbox/mbox-rewrite.c
src/lib-index/mbox/mbox-sync.c

index 6c8533665f5b40ca6c806f6f4c36ad67085b17dd..e31626b29a4f881da1a8b6fb38d746dfca32ebdd 100644 (file)
@@ -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;
index 11efb3f1f8691307b5bd17e31304cd84d5232628..da428935678e549ecfbb3cf189c83a0afe2750f8 100644 (file)
@@ -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));
index 2d3d226465455fbeb8df4e751c08ec2d58c42121..b975db7e02e364a6d762aa972dc9ab4c40eaff72 100644 (file)
@@ -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;