From b29763aa9bcbb99a59aec3820e30ff1864cfa765 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Tue, 26 Aug 2014 17:23:24 +0200 Subject: copy_fd(): do not close the input file descriptor The caller, not this function, opened the file descriptor; it is selfish for the callee to close it when it is done reading from it. The caller may want an option to rewind and re-read the contents after it returns. Simplify the loop to copy the input in full to the output; its body essentially is what a call to write_in_full() helper does. Signed-off-by: Steffen Prohaska Helped-by: Jeff King Signed-off-by: Junio C Hamano --- lockfile.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lockfile.c') diff --git a/lockfile.c b/lockfile.c index 2564a7f544..2448d30cd0 100644 --- a/lockfile.c +++ b/lockfile.c @@ -224,8 +224,11 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags) } else if (copy_fd(orig_fd, fd)) { if (flags & LOCK_DIE_ON_ERROR) exit(128); + close(orig_fd); close(fd); return -1; + } else { + close(orig_fd); } return fd; } -- cgit v1.3