builtin-fsck: reports missing parent commits
[gitweb.git] / copy.c
diff --git a/copy.c b/copy.c
index 7100eedbc3277b9b0997311459d054ba06950b61..c225d1b0ff0a67e637f7200ab5c2a917b550af4f 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -3,10 +3,9 @@
 int copy_fd(int ifd, int ofd)
 {
        while (1) {
-               int len;
                char buffer[8192];
                char *buf = buffer;
-               len = xread(ifd, buffer, sizeof(buffer));
+               ssize_t len = xread(ifd, buffer, sizeof(buffer));
                if (!len)
                        break;
                if (len < 0) {
@@ -22,14 +21,16 @@ int copy_fd(int ifd, int ofd)
                                buf += written;
                                len -= written;
                        }
-                       else if (!written)
+                       else if (!written) {
+                               close(ifd);
                                return error("copy-fd: write returned 0");
-                       else
+                       } else {
+                               close(ifd);
                                return error("copy-fd: write returned %s",
                                             strerror(errno));
+                       }
                }
        }
        close(ifd);
        return 0;
 }
-