changeset 22267:ce98be82d4d6

lib: Add file_lock_set_path()
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 22 Jun 2017 09:05:06 +0300
parents d165150e8883
children 382ee00c9669
files src/lib/file-lock.c src/lib/file-lock.h
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-lock.c	Thu Jun 22 01:42:56 2017 +0300
+++ b/src/lib/file-lock.c	Thu Jun 22 09:05:06 2017 +0300
@@ -372,6 +372,14 @@
 	return lock->path;
 }
 
+void file_lock_set_path(struct file_lock *lock, const char *path)
+{
+	if (path != lock->path) {
+		i_free(lock->path);
+		lock->path = i_strdup(path);
+	}
+}
+
 void file_lock_wait_start(void)
 {
 	i_assert(lock_wait_start.tv_sec == 0);
--- a/src/lib/file-lock.h	Thu Jun 22 01:42:56 2017 +0300
+++ b/src/lib/file-lock.h	Thu Jun 22 09:05:06 2017 +0300
@@ -53,6 +53,9 @@
 
 /* Returns the path given as parameter to file_*lock*(). */
 const char *file_lock_get_path(struct file_lock *lock);
+/* Update lock file's path (after it gets renamed by the caller). This is
+   useful mainly together with file_lock_set_unlink_on_free(). */
+void file_lock_set_path(struct file_lock *lock, const char *path);
 
 /* Returns human-readable string containing the process that has the file
    currently locked. Returns "" if unknown, otherwise " (string)". */