]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Move .vsize.lock creation to its own function
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 21 Jun 2017 23:07:16 +0000 (02:07 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Jul 2017 12:14:13 +0000 (15:14 +0300)
src/lib-storage/index/index-mailbox-size.c

index fc5dc4adca22a54f6d3b55edb772b4bd6102232e..948c003c168fd4493d384520f4bdf886fea4f18a 100644 (file)
@@ -120,22 +120,16 @@ index_mailbox_vsize_update_init(struct mailbox *box)
        return update;
 }
 
-static bool vsize_update_lock_full(struct mailbox_vsize_update *update,
-                                  unsigned int lock_secs)
+static int
+vsize_lock_create(struct mailbox *box, const char *lock_fname,
+                 unsigned int lock_secs, struct file_lock **lock_r,
+                 const char **error_r)
 {
-       struct mailbox *box = update->box;
        const struct mailbox_permissions *perm;
        struct file_create_settings set;
-       const char *lock_path, *error;
+       const char *lock_path;
        bool created;
 
-       if (update->lock != NULL)
-               return TRUE;
-       if (update->lock_failed)
-               return FALSE;
-       if (MAIL_INDEX_IS_IN_MEMORY(box->index))
-               return FALSE;
-
        perm = mailbox_get_permissions(box);
        i_zero(&set);
        set.lock_timeout_secs =
@@ -145,21 +139,41 @@ static bool vsize_update_lock_full(struct mailbox_vsize_update *update,
        set.gid = perm->file_create_gid;
        set.gid_origin = perm->file_create_gid_origin;
 
-       lock_path = t_strdup_printf("%s/"VSIZE_LOCK_SUFFIX, box->index->dir);
-       if (file_create_locked(lock_path, &set, &update->lock,
-                              &created, &error) == -1) {
+       lock_path = t_strdup_printf("%s/%s", box->index->dir, lock_fname);
+       if (file_create_locked(lock_path, &set, lock_r, &created, error_r) == -1) {
+               *error_r = t_strdup_printf("file_create_locked(%s) failed: %s",
+                                          lock_path, *error_r);
+               return errno == EAGAIN ? 0 : -1;
+       }
+       file_lock_set_close_on_free(*lock_r, TRUE);
+       file_lock_set_unlink_on_free(*lock_r, TRUE);
+       return 1;
+}
+
+static bool vsize_update_lock_full(struct mailbox_vsize_update *update,
+                                  unsigned int lock_secs)
+{
+       struct mailbox *box = update->box;
+       const char *error;
+       int ret;
+
+       if (update->lock != NULL)
+               return TRUE;
+       if (update->lock_failed)
+               return FALSE;
+       if (MAIL_INDEX_IS_IN_MEMORY(box->index))
+               return FALSE;
+
+       ret = vsize_lock_create(box, VSIZE_LOCK_SUFFIX, lock_secs,
+                               &update->lock, &error);
+       if (ret <= 0) {
                /* don't log lock timeouts, because we're somewhat expecting
                   them. Especially when lock_secs is 0. */
-               if (errno != EAGAIN) {
-                       mail_storage_set_critical(box->storage,
-                               "file_create_locked(%s) failed: %s",
-                               update->lock_path, error);
-               }
+               if (ret < 0)
+                       mail_storage_set_critical(box->storage, "%s", error);
                update->lock_failed = TRUE;
                return FALSE;
        }
-       file_lock_set_close_on_free(update->lock, TRUE);
-       file_lock_set_unlink_on_free(update->lock, TRUE);
        update->rebuild = FALSE;
        vsize_header_refresh(update);
        index_mailbox_vsize_check_rebuild(update);