]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Moved file lock type string parsing code to file-lock.c
authorTimo Sirainen <tss@iki.fi>
Sun, 12 Oct 2008 08:44:33 +0000 (11:44 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 12 Oct 2008 08:44:33 +0000 (11:44 +0300)
--HG--
branch : HEAD

src/lib-storage/mail-storage.c
src/lib/file-lock.c
src/lib/file-lock.h

index a01c65b939b2b51a0f0c0dccba3abec449027678..11ad1cc4a29ae1759c888d69776018afa6f2aeac 100644 (file)
@@ -109,13 +109,9 @@ void mail_storage_parse_env(enum mail_storage_flags *flags_r,
                *flags_r |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5;
 
        str = getenv("LOCK_METHOD");
-       if (str == NULL || strcmp(str, "fcntl") == 0)
+       if (str == NULL)
                *lock_method_r = FILE_LOCK_METHOD_FCNTL;
-       else if (strcmp(str, "flock") == 0)
-               *lock_method_r = FILE_LOCK_METHOD_FLOCK;
-       else if (strcmp(str, "dotlock") == 0)
-               *lock_method_r = FILE_LOCK_METHOD_DOTLOCK;
-       else
+       else if (!file_lock_method_parse(str, lock_method_r))
                i_fatal("Unknown lock_method: %s", str);
 }
 
index 6cac0c1369af89d41abe8ce87b601f3c637e22ad..0cf95caebba86ca92c0caca03d0e11ffedf0b628 100644 (file)
@@ -15,6 +15,19 @@ struct file_lock {
        enum file_lock_method lock_method;
 };
 
+bool file_lock_method_parse(const char *name, enum file_lock_method *method_r)
+{
+       if (strcasecmp(name, "fcntl") == 0)
+               *method_r = FILE_LOCK_METHOD_FCNTL;
+       else if (strcasecmp(name, "flock") == 0)
+               *method_r = FILE_LOCK_METHOD_FLOCK;
+       else if (strcasecmp(name, "dotlock") == 0)
+               *method_r = FILE_LOCK_METHOD_DOTLOCK;
+       else
+               return FALSE;
+       return TRUE;
+}
+
 int file_try_lock(int fd, const char *path, int lock_type,
                  enum file_lock_method lock_method,
                  struct file_lock **lock_r)
index 3773764c6ef0565712a32ce0c343239fc2137f16..14b40d26fca6e8ed8db2b67d48712a7e2a79611f 100644 (file)
@@ -14,6 +14,10 @@ enum file_lock_method {
        FILE_LOCK_METHOD_DOTLOCK
 };
 
+/* Parse lock method from given string. Returns TRUE if ok,
+   FALSE if name is unknown. */
+bool file_lock_method_parse(const char *name, enum file_lock_method *method_r);
+
 /* Lock the file. Returns 1 if successful, 0 if file is already locked,
    or -1 if error. lock_type is F_WRLCK or F_RDLCK. */
 int file_try_lock(int fd, const char *path, int lock_type,