]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: If file can't be opened read-write, fallback to read-only.
authorTimo Sirainen <tss@iki.fi>
Thu, 28 Apr 2011 18:31:16 +0000 (21:31 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 28 Apr 2011 18:31:16 +0000 (21:31 +0300)
src/lib-storage/index/dbox-common/dbox-file.c

index e0d5490f0e3dbfb7afbab03048be9ba14bd3d0d6..8bd65eee86ce71a9c849ec376f39b6ac6b7ef4ac 100644 (file)
@@ -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);