]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail_storage_lock_create()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 6 Feb 2018 15:47:37 +0000 (17:47 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 9 Feb 2018 14:09:22 +0000 (16:09 +0200)
This is split off of mailbox_lock_file_create().

src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index 385c87f1e197a64780bf93b335035b81efa79efe..441b7bc7c6c52cf10ce15a5e6b1f6d982ebdc1fc 100644 (file)
@@ -10,6 +10,9 @@
 #include "mailbox-attribute-private.h"
 #include "mail-index-private.h"
 
+struct file_lock;
+struct file_create_settings;
+
 /* Default prefix for indexes */
 #define MAIL_INDEX_PREFIX "dovecot.index"
 
@@ -818,10 +821,15 @@ bool mailbox_is_autocreated(struct mailbox *box);
 /* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
 int mailbox_create_fd(struct mailbox *box, const char *path, int flags,
                      int *fd_r);
-/* Create a lock file to the mailbox with the given filename. If it succeeds,
+/* Create a lock file with the given path and settings. If it succeeds,
    returns 1 and lock_r, which needs to be freed once finished with the lock.
-   If lock_secs is reached, returns 0 and error_r. Returns -1 and sets error_r
-   on other errors. */
+   If lock_set->lock_timeout_secs is reached, returns 0 and error_r. Returns
+   -1 and sets error_r on other errors. */
+int mail_storage_lock_create(const char *lock_path,
+                            const struct file_create_settings *lock_set,
+                            struct file_lock **lock_r, const char **error_r);
+/* Create a lock file to the mailbox with the given filename. Returns the same
+   as mail_storage_lock_create(). */
 int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
                             unsigned int lock_secs, struct file_lock **lock_r,
                             const char **error_r);
index e650892d1b1cc861d4c24b3ee9b90d298635f7ed..7f3c17832539cd2e01455cd1083e8eecd1f346be 100644 (file)
@@ -2855,6 +2855,23 @@ void mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
        va_end(va);
 }
 
+int mail_storage_lock_create(const char *lock_path,
+                            const struct file_create_settings *lock_set,
+                            struct file_lock **lock_r, const char **error_r)
+{
+       bool created;
+
+       if (file_create_locked(lock_path, lock_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;
+}
+
 int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
                             unsigned int lock_secs, struct file_lock **lock_r,
                             const char **error_r)
@@ -2862,7 +2879,6 @@ int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
        const struct mailbox_permissions *perm;
        struct file_create_settings set;
        const char *lock_path;
-       bool created;
 
        perm = mailbox_get_permissions(box);
        i_zero(&set);
@@ -2893,12 +2909,5 @@ int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
                set.mkdir_mode = 0700;
        }
 
-       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;
+       return mail_storage_lock_create(lock_path, &set, lock_r, error_r);
 }