69
* `rollback_lock_file()`.
70
*
71
* * Close the file descriptor without removing or renaming the
72
- * lockfile by calling `close_lock_file()`, and later call
72
+ * lockfile by calling `close_lock_file_gently()`, and later call
73
* `commit_lock_file()`, `commit_lock_file_to()`,
74
* `rollback_lock_file()`, or `reopen_lock_file()`.
75
*
85
*
86
* If you need to close the file descriptor you obtained from a
87
* `hold_lock_file_for_*()` function yourself, do so by calling
88
- * `close_lock_file()`. See "tempfile.h" for more information.
88
+ * `close_lock_file_gently()`. See "tempfile.h" for more information.
89
*
90
*
91
* Under the covers, a lockfile is just a tempfile with a few helper
104
*
105
* Similarly, `commit_lock_file`, `commit_lock_file_to`, and
106
* `close_lock_file` return 0 on success. On failure they set `errno`
107
- * appropriately, do their best to roll back the lockfile, and return
108
- * -1.
107
+ * appropriately and return -1. The `commit` variants (but not `close`)
108
+ * do their best to delete the temporary file before returning.
109
*/
110
111
#include "tempfile.h"
202
/*
203
* Associate a stdio stream with the lockfile (which must still be
204
* open). Return `NULL` (*without* rolling back the lockfile) on
205
- * error. The stream is closed automatically when `close_lock_file()`
206
- * is called or when the file is committed or rolled back.
205
+ * error. The stream is closed automatically when
206
+ * `close_lock_file_gently()` is called or when the file is committed or
207
+ * rolled back.
208
*/
209
static inline FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
210
{
242
* lockfile over the file being locked. Return 0 upon success. On
243
* failure to `close(2)`, return a negative value and roll back the
244
* lock file. Usually `commit_lock_file()`, `commit_lock_file_to()`,
244
- * or `rollback_lock_file()` should eventually be called if
245
- * `close_lock_file()` succeeds.
245
+ * or `rollback_lock_file()` should eventually be called.
246
*/
247
-static inline int close_lock_file(struct lock_file *lk)
247
+static inline int close_lock_file_gently(struct lock_file *lk)
248
{
249
- int ret = close_tempfile_gently(&lk->tempfile);
250
- if (ret) {
251
- int saved_errno = errno;
252
- delete_tempfile(&lk->tempfile);
253
- errno = saved_errno;
254
- }
255
- return ret;
249
+ return close_tempfile_gently(&lk->tempfile);
250
}
251
252
/*
259
- * Re-open a lockfile that has been closed using `close_lock_file()`
253
+ * Re-open a lockfile that has been closed using `close_lock_file_gently()`
254
* but not yet committed or rolled back. This can be used to implement
255
* a sequence of operations like the following:
256
*
257
* * Lock file.
258
*
265
- * * Write new contents to lockfile, then `close_lock_file()` to
259
+ * * Write new contents to lockfile, then `close_lock_file_gently()` to
260
* cause the contents to be written to disk.
261
*
262
* * Pass the name of the lockfile to another program to allow it (and