From: Timo Sirainen Date: Sun, 12 Oct 2008 08:44:33 +0000 (+0300) Subject: Moved file lock type string parsing code to file-lock.c X-Git-Tag: 1.2.alpha3~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e77746e501c2b45850b1c530836058ed75e09ee;p=thirdparty%2Fdovecot%2Fcore.git Moved file lock type string parsing code to file-lock.c --HG-- branch : HEAD --- diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index a01c65b939..11ad1cc4a2 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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); } diff --git a/src/lib/file-lock.c b/src/lib/file-lock.c index 6cac0c1369..0cf95caebb 100644 --- a/src/lib/file-lock.c +++ b/src/lib/file-lock.c @@ -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) diff --git a/src/lib/file-lock.h b/src/lib/file-lock.h index 3773764c6e..14b40d26fc 100644 --- a/src/lib/file-lock.h +++ b/src/lib/file-lock.h @@ -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,