changeset 2149:b526decec0b8 HEAD

EXAMINE/STATUS should also update metadata changes, they don't really open the mbox as readonly.
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Jun 2004 09:09:31 +0300
parents 219fe7776a0c
children 347ca1cf6372
files src/lib-storage/index/index-storage.h src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-sync.c
diffstat 3 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.h	Wed Jun 16 08:54:43 2004 +0300
+++ b/src/lib-storage/index/index-storage.h	Wed Jun 16 09:09:31 2004 +0300
@@ -87,6 +87,7 @@
 	unsigned int mbox_locks;
 	struct dotlock mbox_dotlock;
 	unsigned int mbox_lock_id, mbox_mail_lock_id;
+	int mbox_readonly;
 
 	uint32_t mbox_extra_idx;
 
--- a/src/lib-storage/index/mbox/mbox-file.c	Wed Jun 16 08:54:43 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-file.c	Wed Jun 16 09:09:31 2004 +0300
@@ -15,7 +15,12 @@
 
 	i_assert(ibox->mbox_fd == -1);
 
-	fd = open(ibox->path, ibox->readonly ? O_RDONLY : O_RDWR);
+	fd = open(ibox->path, ibox->mbox_readonly ? O_RDONLY : O_RDWR);
+	if (fd == -1 && errno == EACCES && !ibox->mbox_readonly) {
+                ibox->mbox_readonly = TRUE;
+		fd = open(ibox->path, O_RDONLY);
+	}
+
 	if (fd == -1) {
 		mbox_set_syscall_error(ibox, "open()");
 		return -1;
--- a/src/lib-storage/index/mbox/mbox-sync.c	Wed Jun 16 08:54:43 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Wed Jun 16 09:09:31 2004 +0300
@@ -69,6 +69,8 @@
 	struct stat old_st, st;
 	uoff_t old_from_offset = 0, old_offset = 0;
 
+	i_assert(lock_type != F_WRLCK || !ibox->mbox_readonly);
+
 	if (sync_ctx->lock_id != 0) {
 		if (fstat(sync_ctx->fd, &old_st) < 0) {
 			mbox_set_syscall_error(ibox, "stat()");
@@ -232,7 +234,7 @@
 
 	*sync_expunge_r = FALSE;
 
-	if (sync_ctx->ibox->readonly || sync_ctx->index_sync_ctx == NULL)
+	if (sync_ctx->ibox->mbox_readonly || sync_ctx->index_sync_ctx == NULL)
 		return 0;
 
 	mbox_sync_buffer_delete_old(sync_ctx->syncs, uid);
@@ -506,7 +508,7 @@
 	if (sync_ctx->first_uid == 0)
 		sync_ctx->first_uid = mail_ctx->mail.uid;
 
-	if (sync_ctx->ibox->readonly)
+	if (sync_ctx->ibox->mbox_readonly)
 		return 0;
 
 	if (sync_ctx->expunged_space > 0 && sync_ctx->need_space_seq == 0) {
@@ -1055,7 +1057,8 @@
 	if (mail_index_sync_end(index_sync_ctx) < 0)
 		ret = -1;
 
-	if (sync_ctx.base_uid_last != sync_ctx.next_uid-1 && ret == 0) {
+	if (sync_ctx.base_uid_last != sync_ctx.next_uid-1 && ret == 0 &&
+	    !ibox->mbox_readonly) {
 		/* rewrite X-IMAPbase header. do it after mail_index_sync_end()
 		   so previous transactions have been committed. */
 		/* FIXME: ugly .. */