commit - c75a6067f1f36c6bbebd9f3737672055674df806
commit + ecf9545f7cd658d63b1bcafc10886998cbaa7870
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 - e62aa2976cf796cf5f35817e8ad9c0a3d1af9309
blob + be8ca1e3c250e88dd5d674742cb8ba1ab406777a
--- 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 - 0182edd3af82986f364ff86ab43cee6b3b88f795
blob + 817d94fd8742d33d9a32144ba72b9f19752ff06f
--- 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;
}