Commit Diff


commit - 54382dcc5e1ccefbc74e7615bc5c0a0aef7ccf3a
commit + 3606d7fc8ecd88d9779619bbe6cb06f5309258cc
blob - d999e8a0e495d5f53e7b22eb8b13a3ac94d3d805
blob + 47d76d27b6b0d7cb999126ff93c9be462456dd24
--- lib/delta.c
+++ lib/delta.c
@@ -27,6 +27,7 @@
 #include "got_object.h"
 
 #include "delta.h"
+#include "path.h"
 #include "zb.h"
 
 #ifndef MIN
@@ -260,8 +261,13 @@ got_delta_apply(FILE *base_compressed, const uint8_t *
 				break;
 			if (base_file == NULL) {
 				size_t inflated_size;
-				err = got_inflate_to_tempfile(&base_file,
-				    &inflated_size, base_compressed);
+				base_file = got_opentemp();
+				if (base_file == NULL) {
+					err = got_error_from_errno();
+					break;
+				}
+				err = got_inflate_to_file(&inflated_size,
+				    base_compressed, base_file);
 				if (err)
 					break;
 				if (inflated_size != base_size) {
blob - e169c217ee8f3cba3a5ec9f6d91e63691772e8ab
blob + 9e010e01438667bfc74ee881619187962c92dc5a
--- lib/pack.c
+++ lib/pack.c
@@ -796,30 +796,6 @@ got_packfile_open_object(struct got_object **obj, stru
 	err = open_packed_object(obj, repo, packidx, idx, id);
 	got_packidx_close(packidx);
 	return err;
-}
-
-static const struct got_error *
-dump_plain_object(FILE *infile, uint8_t type, size_t size, FILE *outfile)
-{
-	size_t n;
-
-	while (size > 0) {
-		uint8_t data[2048];
-		size_t len = MIN(size, sizeof(data));
-
-		n = fread(data, len, 1, infile);
-		if (n != 1)
-			return got_ferror(infile, GOT_ERR_BAD_PACKFILE);
-
-		n = fwrite(data, len, 1, outfile);
-		if (n != 1)
-			return got_ferror(outfile, GOT_ERR_IO);
-
-		size -= len;
-	}
-
-	rewind(outfile);
-	return NULL;
 }
 
 static const struct got_error *
@@ -922,7 +898,7 @@ got_packfile_extract_object(FILE **f, struct got_objec
 			goto done;
 		}
 
-		err = dump_plain_object(packfile, obj->type, obj->size, *f);
+		err = got_inflate_to_file(&obj->size, packfile, *f);
 	} else
 		err = dump_delta_chain(&obj->deltas, *f);
 done:
blob - afccbd6a660789099bba0350408e7af92ebbe9cc
blob + 16623c1a51d435399ec53d6b1ee7e22e0803d766
--- lib/zb.c
+++ lib/zb.c
@@ -155,17 +155,13 @@ done:
 }
 
 const struct got_error *
-got_inflate_to_tempfile(FILE **outfile, size_t *outlen, FILE *f)
+got_inflate_to_file(size_t *outlen, FILE *infile, FILE *outfile)
 {
 	const struct got_error *err;
 	size_t avail;
 	struct got_zstream_buf zb;
 	void *newbuf;
 
-	*outfile = got_opentemp();
-	if (*outfile == NULL)
-		return got_error_from_errno();
-
 	err = got_inflate_init(&zb, 8192);
 	if (err)
 		goto done;
@@ -173,14 +169,14 @@ got_inflate_to_tempfile(FILE **outfile, size_t *outlen
 	*outlen = 0;
 
 	do {
-		err = got_inflate_read(&zb, f, NULL, &avail);
+		err = got_inflate_read(&zb, infile, NULL, &avail);
 		if (err)
 			return err;
 		if (avail > 0) {
 			size_t n;
-			n = fwrite(zb.outbuf, avail, 1, *outfile);
+			n = fwrite(zb.outbuf, avail, 1, outfile);
 			if (n != 1) {
-				err = got_ferror(*outfile, GOT_ERR_IO);
+				err = got_ferror(outfile, GOT_ERR_IO);
 				goto done;
 			}
 			*outlen += avail;
@@ -188,11 +184,8 @@ got_inflate_to_tempfile(FILE **outfile, size_t *outlen
 	} while (avail > 0);
 
 done:
-	if (err) {
-		fclose(*outfile);
-		*outfile = NULL;
-	} else
-		rewind(*outfile);
+	if (err == NULL)
+		rewind(outfile);
 	got_inflate_end(&zb);
 	return err;
 }
blob - 0fc27e548da6a124cd236a741baca6b7ca9d51ed
blob + f71dcda43ea4ef3e830b9e148737e73c3e15fa89
--- lib/zb.h
+++ lib/zb.h
@@ -20,4 +20,4 @@ const struct got_error *got_inflate_read(struct got_zs
 void got_inflate_end(struct got_zstream_buf *);
 const struct got_error *got_inflate_to_mem(uint8_t **, size_t *, FILE *,
     size_t);
-const struct got_error *got_inflate_to_tempfile(FILE **, size_t *, FILE *);
+const struct got_error *got_inflate_to_file(size_t *, FILE *, FILE *);