Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6686:610f3d9813b5 HEAD
Added MAIL_INDEX_OPEN_FLAG_READONLY.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 04 Nov 2007 14:47:01 +0200 |
parents | 113bf6033abe |
children | 294af3a8d974 |
files | src/lib-index/mail-cache-compress.c src/lib-index/mail-cache.c src/lib-index/mail-index.c src/lib-index/mail-index.h |
diffstat | 4 files changed, 16 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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 @@ 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; }
--- 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 @@ 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 @@ 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;
--- 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 @@ 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 @@ 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)
--- 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 @@ 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 {