commit - f8eebdd4e657c910bdc7d7d8777256f59ddb6465
commit + cc7a354afc4ae05de465ac2cf97b558fec5b271f
blob - f107a850167bfb93f97e10313c9351627cd8eb68
blob + 3857f54da2b2d09d1775f659e036b7fa820b9b3b
--- lib/got_lib_object.h
+++ lib/got_lib_object.h
struct got_object_id *, struct got_repository *, int);
const struct got_error *got_object_open(struct got_object **,
struct got_repository *, struct got_object_id *);
-const struct got_error *got_object_raw_open(struct got_raw_object **,
+const struct got_error *got_object_raw_open(struct got_raw_object **, int,
struct got_repository *, struct got_object_id *, size_t);
void got_object_raw_rewind(struct got_raw_object *);
size_t got_object_raw_get_hdrlen(struct got_raw_object *);
blob - b9d3ec4605ca7d5c2d7b59cde3def136e77c3adc
blob + 5c98d7f542c6cc60b245e230796391a272d5a5ad
--- lib/object.c
+++ lib/object.c
}
const struct got_error *
-got_object_raw_open(struct got_raw_object **obj, struct got_repository *repo,
- struct got_object_id *id, size_t blocksize)
+got_object_raw_open(struct got_raw_object **obj, int outfd,
+ struct got_repository *repo, struct got_object_id *id, size_t blocksize)
{
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
int idx;
uint8_t *outbuf = NULL;
- int outfd = -1;
off_t size = 0;
size_t hdrlen = 0;
char *path_packfile = NULL;
*obj = NULL;
- outfd = got_opentempfd();
- if (outfd == -1)
- return got_error_from_errno("got_opentempfd");
-
err = got_repo_search_packidx(&packidx, &idx, repo, id);
if (err == NULL) {
struct got_pack *pack = NULL;
}
if (outbuf) {
- if (close(outfd) == -1) {
- err = got_error_from_errno("close");
- goto done;
- }
- outfd = -1;
(*obj)->f = fmemopen(outbuf, hdrlen + size, "r");
if ((*obj)->f == NULL) {
err = got_error_from_errno("fdopen");
err = got_error_from_errno("fdopen");
goto done;
}
- outfd = -1;
(*obj)->data = NULL;
}
(*obj)->hdrlen = hdrlen;
got_object_raw_close(*obj);
*obj = NULL;
}
- if (outfd != -1)
- close(outfd);
free(outbuf);
}
return err;
blob - dce64b25f35227709c626d4d561698c07375c735
blob + 8ab75df8dd3ab328895f4354591fe0d968fe613f
--- lib/pack_create.c
+++ lib/pack_create.c
struct got_delta_instruction *deltas;
int i, j, size, ndeltas, best;
const int max_base_candidates = 10;
+ int outfd = -1;
qsort(meta, nmeta, sizeof(struct got_pack_meta *), delta_order_cmp);
for (i = 0; i < nmeta; i++) {
m->obj_type == GOT_OBJ_TYPE_TAG)
continue;
- err = got_object_raw_open(&raw, repo, &m->id, 8192);
+ if (outfd == -1) {
+ outfd = got_opentempfd();
+ if (outfd == -1) {
+ err = got_error_from_errno("got_opentempfd");
+ goto done;
+ }
+ }
+ err = got_object_raw_open(&raw, outfd, repo, &m->id, 8192);
if (err)
goto done;
+ if (raw->data == NULL)
+ outfd = -1; /* outfd is now raw->f */
m->size = raw->size;
err = got_deltify_init(&m->dtab, raw->f, raw->hdrlen,
base->obj_type != m->obj_type)
continue;
- err = got_object_raw_open(&base_raw, repo, &base->id,
- 8192);
+ if (outfd == -1) {
+ outfd = got_opentempfd();
+ if (outfd == -1) {
+ err = got_error_from_errno(
+ "got_opentempfd");
+ goto done;
+ }
+ }
+ err = got_object_raw_open(&base_raw, outfd, repo,
+ &base->id, 8192);
if (err)
goto done;
+ if (base_raw->data == NULL)
+ outfd = -1; /* outfd is now base_raw->f */
err = got_deltify(&deltas, &ndeltas,
raw->f, raw->hdrlen, raw->size + raw->hdrlen,
base->dtab, base_raw->f, base_raw->hdrlen,
got_object_raw_close(raw);
if (base_raw)
got_object_raw_close(base_raw);
+ if (outfd != -1 && close(outfd) == -1 && err == NULL)
+ err = got_error_from_errno("close");
return err;
}
size_t outlen, n;
struct got_deflate_checksum csum;
off_t packfile_size = 0;
+ int outfd = -1;
SHA1Init(&ctx);
csum.output_sha1 = &ctx;
}
m = meta[i];
m->off = ftello(packfile);
- err = got_object_raw_open(&raw, repo, &m->id, 8192);
+ if (outfd == -1) {
+ outfd = got_opentempfd();
+ if (outfd == -1) {
+ err = got_error_from_errno("got_opentempfd");
+ goto done;
+ }
+ }
+ err = got_object_raw_open(&raw, outfd, repo, &m->id, 8192);
if (err)
goto done;
+ if (raw->data == NULL)
+ outfd = -1; /* outfd is now raw->f */
if (m->deltas == NULL) {
err = packhdr(&nh, buf, sizeof(buf),
m->obj_type, raw->size);
err = got_error_from_errno("fclose");
if (raw)
got_object_raw_close(raw);
+ if (outfd != -1 && close(outfd) == -1 && err == NULL)
+ err = got_error_from_errno("close");
return err;
}