lock_file(): exit early if lockfile cannot be opened
This is a bit easier to read than the old version, which nested part of the non-error code in an "if" block. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
35ff08be09
commit
e31e949b9f
23
lockfile.c
23
lockfile.c
@ -197,19 +197,18 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
|
|||||||
resolve_symlink(lk->filename, max_path_len);
|
resolve_symlink(lk->filename, max_path_len);
|
||||||
strcat(lk->filename, LOCK_SUFFIX);
|
strcat(lk->filename, LOCK_SUFFIX);
|
||||||
lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
|
lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
|
||||||
if (0 <= lk->fd) {
|
if (lk->fd < 0) {
|
||||||
lk->owner = getpid();
|
|
||||||
if (adjust_shared_perm(lk->filename)) {
|
|
||||||
int save_errno = errno;
|
|
||||||
error("cannot fix permission bits on %s",
|
|
||||||
lk->filename);
|
|
||||||
rollback_lock_file(lk);
|
|
||||||
errno = save_errno;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lk->filename[0] = 0;
|
lk->filename[0] = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
lk->owner = getpid();
|
||||||
|
if (adjust_shared_perm(lk->filename)) {
|
||||||
|
int save_errno = errno;
|
||||||
|
error("cannot fix permission bits on %s", lk->filename);
|
||||||
|
rollback_lock_file(lk);
|
||||||
|
errno = save_errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return lk->fd;
|
return lk->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user