dovecot-1.2: Moved file lock type string parsing code to file-lo...

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 12 11:44:37 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/f472f9ad69be
changeset: 8264:f472f9ad69be
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 12 11:44:33 2008 +0300
description:
Moved file lock type string parsing code to file-lock.c

diffstat:

3 files changed, 19 insertions(+), 6 deletions(-)
src/lib-storage/mail-storage.c |    8 ++------
src/lib/file-lock.c            |   13 +++++++++++++
src/lib/file-lock.h            |    4 ++++

diffs (56 lines):

diff -r c1568782774e -r f472f9ad69be src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Sun Oct 12 00:22:39 2008 +0300
+++ b/src/lib-storage/mail-storage.c	Sun Oct 12 11:44:33 2008 +0300
@@ -109,13 +109,9 @@ void mail_storage_parse_env(enum mail_st
 		*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 -r c1568782774e -r f472f9ad69be src/lib/file-lock.c
--- a/src/lib/file-lock.c	Sun Oct 12 00:22:39 2008 +0300
+++ b/src/lib/file-lock.c	Sun Oct 12 11:44:33 2008 +0300
@@ -14,6 +14,19 @@ struct file_lock {
 	int lock_type;
 	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,
diff -r c1568782774e -r f472f9ad69be src/lib/file-lock.h
--- a/src/lib/file-lock.h	Sun Oct 12 00:22:39 2008 +0300
+++ b/src/lib/file-lock.h	Sun Oct 12 11:44:33 2008 +0300
@@ -13,6 +13,10 @@ enum file_lock_method {
 	FILE_LOCK_METHOD_FLOCK,
 	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. */


More information about the dovecot-cvs mailing list