Skip to content

Commit

Permalink
hold_lock_file_for_append(): restore errno before returning
Browse files Browse the repository at this point in the history
Callers who don't pass LOCK_DIE_ON_ERROR might want to examine errno
to see what went wrong, so restore errno before returning.

In fact this function only has one caller, add_to_alternates_file(),
and it *does* use LOCK_DIE_ON_ERROR, but, you know, think of future
generations.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Oct 1, 2014
1 parent ec38b4e commit 4d423a3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,22 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
orig_fd = open(path, O_RDONLY);
if (orig_fd < 0) {
if (errno != ENOENT) {
int save_errno = errno;

if (flags & LOCK_DIE_ON_ERROR)
die("cannot open '%s' for copying", path);
rollback_lock_file(lk);
return error("cannot open '%s' for copying", path);
error("cannot open '%s' for copying", path);
errno = save_errno;
return -1;
}
} else if (copy_fd(orig_fd, fd)) {
int save_errno = errno;

if (flags & LOCK_DIE_ON_ERROR)
exit(128);
rollback_lock_file(lk);
errno = save_errno;
return -1;
}
return fd;
Expand Down

0 comments on commit 4d423a3

Please sign in to comment.