}
/* Make sure errno contains a meaningful value on error */
-static int lock_file(struct lock_file *lk, const char *path, int flags)
+static int lock_file(struct lock_file *lk, const char *path, int flags,
+ int mode)
{
struct strbuf filename = STRBUF_INIT;
resolve_symlink(&filename);
strbuf_addstr(&filename, LOCK_SUFFIX);
- lk->tempfile = create_tempfile(filename.buf);
+ lk->tempfile = create_tempfile_mode(filename.buf, mode);
strbuf_release(&filename);
return lk->tempfile ? lk->tempfile->fd : -1;
}
* exactly once. If timeout_ms is -1, try indefinitely.
*/
static int lock_file_timeout(struct lock_file *lk, const char *path,
- int flags, long timeout_ms)
+ int flags, long timeout_ms, int mode)
{
int n = 1;
int multiplier = 1;
static int random_initialized = 0;
if (timeout_ms == 0)
- return lock_file(lk, path, flags);
+ return lock_file(lk, path, flags, mode);
if (!random_initialized) {
srand((unsigned int)getpid());
long backoff_ms, wait_ms;
int fd;
- fd = lock_file(lk, path, flags);
+ fd = lock_file(lk, path, flags, mode);
if (fd >= 0)
return fd; /* success */
}
/* This should return a meaningful errno on failure */
-int hold_lock_file_for_update_timeout(struct lock_file *lk, const char *path,
- int flags, long timeout_ms)
+int hold_lock_file_for_update_timeout_mode(struct lock_file *lk,
+ const char *path, int flags,
+ long timeout_ms, int mode)
{
- int fd = lock_file_timeout(lk, path, flags, timeout_ms);
+ int fd = lock_file_timeout(lk, path, flags, timeout_ms, mode);
if (fd < 0) {
if (flags & LOCK_DIE_ON_ERROR)
unable_to_lock_die(path, errno);