struct timeval locked_time;
int lock_type;
enum file_lock_method lock_method;
+ bool unlink_on_free;
};
static struct timeval lock_wait_start;
return 1;
}
+void file_lock_set_unlink_on_free(struct file_lock *lock, bool set)
+{
+ lock->unlink_on_free = set;
+}
+
void file_unlock(struct file_lock **_lock)
{
struct file_lock *lock = *_lock;
*_lock = NULL;
+ /* unlocking is unnecessary when the file is unlinked. or alternatively
+ the unlink() must be done before unlocking, because otherwise it
+ could be deleting the new lock. */
+ i_assert(!lock->unlink_on_free);
+
if (file_lock_do(lock->fd, lock->path, F_UNLCK,
lock->lock_method, 0, &error) == 0) {
/* this shouldn't happen */
*_lock = NULL;
+ if (lock->unlink_on_free)
+ i_unlink(lock->path);
+
file_lock_log_warning_if_slow(lock);
i_free(lock->path);
i_free(lock);
/* Change the lock type. WARNING: This isn't an atomic operation!
The result is the same as file_unlock() + file_try_lock(). */
int file_lock_try_update(struct file_lock *lock, int lock_type);
+/* When the lock is freed, unlink() the file automatically. This can be useful
+ for files that are only created to exist as lock files. */
+void file_lock_set_unlink_on_free(struct file_lock *lock, bool set);
/* Unlock and free the lock. */
void file_unlock(struct file_lock **lock);