dovecot: Added MAIL_INDEX_OPEN_FLAG_READONLY.

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 4 14:48:20 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/610f3d9813b5
changeset: 6686:610f3d9813b5
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Nov 04 14:47:01 2007 +0200
description:
Added MAIL_INDEX_OPEN_FLAG_READONLY.

diffstat:

4 files changed, 17 insertions(+), 7 deletions(-)
src/lib-index/mail-cache-compress.c |    7 ++++---
src/lib-index/mail-cache.c          |    6 ++++--
src/lib-index/mail-index.c          |    9 +++++++--
src/lib-index/mail-index.h          |    2 ++

diffs (82 lines):

diff -r 113bf6033abe -r 610f3d9813b5 src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Sat Nov 03 23:02:55 2007 +0200
+++ b/src/lib-index/mail-cache-compress.c	Sun Nov 04 14:47:01 2007 +0200
@@ -430,7 +430,7 @@ int mail_cache_compress(struct mail_cach
 	bool unlock = FALSE;
 	int ret;
 
-	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
+	if (MAIL_INDEX_IS_IN_MEMORY(cache->index) || cache->index->readonly)
 		return 0;
 
 	if (cache->index->lock_method == FILE_LOCK_METHOD_DOTLOCK) {
@@ -460,5 +460,6 @@ int mail_cache_compress(struct mail_cach
 
 bool mail_cache_need_compress(struct mail_cache *cache)
 {
-	return cache->need_compress_file_seq != 0;
-}
+	return cache->need_compress_file_seq != 0 &&
+		!cache->index->readonly;
+}
diff -r 113bf6033abe -r 610f3d9813b5 src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Sat Nov 03 23:02:55 2007 +0200
+++ b/src/lib-index/mail-cache.c	Sun Nov 04 14:47:01 2007 +0200
@@ -104,7 +104,8 @@ int mail_cache_reopen(struct mail_cache 
 
 	mail_cache_file_close(cache);
 
-	cache->fd = nfs_safe_open(cache->filepath, O_RDWR);
+	cache->fd = nfs_safe_open(cache->filepath,
+				  cache->index->readonly ? O_RDONLY : O_RDWR);
 	if (cache->fd == -1) {
 		if (errno == ENOENT)
 			cache->need_compress_file_seq = 0;
@@ -279,7 +280,8 @@ static int mail_cache_try_open(struct ma
 	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;
 
-	cache->fd = nfs_safe_open(cache->filepath, O_RDWR);
+	cache->fd = nfs_safe_open(cache->filepath,
+				  cache->index->readonly ? O_RDONLY : O_RDWR);
 	if (cache->fd == -1) {
 		if (errno == ENOENT) {
 			cache->need_compress_file_seq = 0;
diff -r 113bf6033abe -r 610f3d9813b5 src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Sat Nov 03 23:02:55 2007 +0200
+++ b/src/lib-index/mail-index.c	Sun Nov 04 14:47:01 2007 +0200
@@ -243,8 +243,12 @@ int mail_index_try_open_only(struct mail
 	i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
 
         /* Note that our caller must close index->fd by itself. */
-	index->fd = nfs_safe_open(index->filepath, O_RDWR);
-	index->readonly = FALSE;
+	if (index->readonly)
+		errno = EACCES;
+	else {
+		index->fd = nfs_safe_open(index->filepath, O_RDWR);
+		index->readonly = FALSE;
+	}
 
 	if (index->fd == -1 && errno == EACCES) {
 		index->fd = open(index->filepath, O_RDONLY);
@@ -396,6 +400,7 @@ int mail_index_open(struct mail_index *i
 	index->fsync_disable =
 		(flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0;
 	index->nfs_flush = (flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
+	index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0;
 	index->lock_method = lock_method;
 
 	if (index->nfs_flush && index->fsync_disable)
diff -r 113bf6033abe -r 610f3d9813b5 src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Sat Nov 03 23:02:55 2007 +0200
+++ b/src/lib-index/mail-index.h	Sun Nov 04 14:47:01 2007 +0200
@@ -21,6 +21,8 @@ enum mail_index_open_flags {
 	MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE	= 0x20,
 	/* Flush NFS attr/data/write cache when necessary */
 	MAIL_INDEX_OPEN_FLAG_NFS_FLUSH		= 0x40,
+	/* Open the index read-only */
+	MAIL_INDEX_OPEN_FLAG_READONLY		= 0x80
 };
 
 enum mail_index_header_compat_flags {


More information about the dovecot-cvs mailing list