changeset 8264:f472f9ad69be HEAD

Moved file lock type string parsing code to file-lock.c
author Timo Sirainen <tss@iki.fi>
date Sun, 12 Oct 2008 11:44:33 +0300
parents c1568782774e
children 72b7277aefb3
files src/lib-storage/mail-storage.c src/lib/file-lock.c src/lib/file-lock.h
diffstat 3 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 		*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);
 }
 
--- 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
@@ -15,6 +15,19 @@
 	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)
--- 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
@@ -14,6 +14,10 @@
 	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,