Skip to content

Commit 4d423a3

Browse files
mhaggergitster
authored andcommitted
hold_lock_file_for_append(): restore errno before returning
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec38b4e commit 4d423a3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lockfile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,22 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
243243
orig_fd = open(path, O_RDONLY);
244244
if (orig_fd < 0) {
245245
if (errno != ENOENT) {
246+
int save_errno = errno;
247+
246248
if (flags & LOCK_DIE_ON_ERROR)
247249
die("cannot open '%s' for copying", path);
248250
rollback_lock_file(lk);
249-
return error("cannot open '%s' for copying", path);
251+
error("cannot open '%s' for copying", path);
252+
errno = save_errno;
253+
return -1;
250254
}
251255
} else if (copy_fd(orig_fd, fd)) {
256+
int save_errno = errno;
257+
252258
if (flags & LOCK_DIE_ON_ERROR)
253259
exit(128);
254260
rollback_lock_file(lk);
261+
errno = save_errno;
255262
return -1;
256263
}
257264
return fd;

0 commit comments

Comments
 (0)