From: Timo Sirainen Date: Thu, 28 Apr 2011 18:31:16 +0000 (+0300) Subject: dbox: If file can't be opened read-write, fallback to read-only. X-Git-Tag: 2.0.13~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ced3c1f44ebc13776baee115f440bf04fd742a77;p=thirdparty%2Fdovecot%2Fcore.git dbox: If file can't be opened read-write, fallback to read-only. --- diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index e0d5490f0e..8bd65eee86 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -165,11 +165,16 @@ static int dbox_file_read_header(struct dbox_file *file) static int dbox_file_open_fd(struct dbox_file *file, bool try_altpath) { const char *path; + int flags = O_RDWR; bool alt = FALSE; /* try the primary path first */ path = file->primary_path; - while ((file->fd = open(path, O_RDWR)) == -1) { + while ((file->fd = open(path, flags)) == -1) { + if (errno == EACCES && flags == O_RDWR) { + flags = O_RDONLY; + continue; + } if (errno != ENOENT) { mail_storage_set_critical(&file->storage->storage, "open(%s) failed: %m", path);