2 b61ceafc 2022-10-13 thomas * Copyright (c) 2018, 2019, 2022 Stefan Sperling <stsp@openbsd.org>
4 b61ceafc 2022-10-13 thomas * Permission to use, copy, modify, and distribute this software for any
5 b61ceafc 2022-10-13 thomas * purpose with or without fee is hereby granted, provided that the above
6 b61ceafc 2022-10-13 thomas * copyright notice and this permission notice appear in all copies.
8 b61ceafc 2022-10-13 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 b61ceafc 2022-10-13 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 b61ceafc 2022-10-13 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 b61ceafc 2022-10-13 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 b61ceafc 2022-10-13 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 b61ceafc 2022-10-13 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 b61ceafc 2022-10-13 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 f46da2e2 2024-01-18 thomas #include "got_compat.h"
19 b61ceafc 2022-10-13 thomas #include <sys/mman.h>
20 b61ceafc 2022-10-13 thomas #include <sys/queue.h>
21 b61ceafc 2022-10-13 thomas #include <sys/types.h>
22 b61ceafc 2022-10-13 thomas #include <sys/stat.h>
23 b61ceafc 2022-10-13 thomas #include <sys/socket.h>
24 b61ceafc 2022-10-13 thomas #include <sys/uio.h>
26 b61ceafc 2022-10-13 thomas #include <errno.h>
27 b61ceafc 2022-10-13 thomas #include <imsg.h>
28 b61ceafc 2022-10-13 thomas #include <stdio.h>
29 b61ceafc 2022-10-13 thomas #include <stdint.h>
30 b61ceafc 2022-10-13 thomas #include <stdlib.h>
31 b61ceafc 2022-10-13 thomas #include <string.h>
32 b61ceafc 2022-10-13 thomas #include <limits.h>
33 b61ceafc 2022-10-13 thomas #include <unistd.h>
35 b61ceafc 2022-10-13 thomas #include "got_error.h"
36 b61ceafc 2022-10-13 thomas #include "got_object.h"
37 b61ceafc 2022-10-13 thomas #include "got_repository.h"
38 b61ceafc 2022-10-13 thomas #include "got_opentemp.h"
39 b61ceafc 2022-10-13 thomas #include "got_path.h"
41 b61ceafc 2022-10-13 thomas #include "got_lib_delta.h"
42 b61ceafc 2022-10-13 thomas #include "got_lib_object.h"
43 b61ceafc 2022-10-13 thomas #include "got_lib_privsep.h"
44 b61ceafc 2022-10-13 thomas #include "got_lib_object_cache.h"
45 b61ceafc 2022-10-13 thomas #include "got_lib_pack.h"
46 b61ceafc 2022-10-13 thomas #include "got_lib_repository.h"
48 b61ceafc 2022-10-13 thomas static const struct got_error *
49 b61ceafc 2022-10-13 thomas request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
50 b61ceafc 2022-10-13 thomas struct got_object_id *id)
52 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
53 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
55 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_obj_req(ibuf, idx, id);
57 b61ceafc 2022-10-13 thomas return err;
59 b61ceafc 2022-10-13 thomas err = got_privsep_recv_obj(obj, ibuf);
61 b61ceafc 2022-10-13 thomas return err;
63 b61ceafc 2022-10-13 thomas memcpy(&(*obj)->id, id, sizeof((*obj)->id));
65 b61ceafc 2022-10-13 thomas return NULL;
68 b61ceafc 2022-10-13 thomas /* Create temporary files used during delta application. */
69 b61ceafc 2022-10-13 thomas static const struct got_error *
70 b61ceafc 2022-10-13 thomas pack_child_send_tempfiles(struct imsgbuf *ibuf, struct got_pack *pack)
72 b61ceafc 2022-10-13 thomas const struct got_error *err;
73 b61ceafc 2022-10-13 thomas int basefd = -1, accumfd = -1;
76 b61ceafc 2022-10-13 thomas * For performance reasons, the child will keep reusing the
77 b61ceafc 2022-10-13 thomas * same temporary files during every object request.
78 b61ceafc 2022-10-13 thomas * Opening and closing new files for every object request is
79 b61ceafc 2022-10-13 thomas * too expensive during operations such as 'gotadmin pack'.
81 b61ceafc 2022-10-13 thomas if (pack->child_has_tempfiles)
82 b61ceafc 2022-10-13 thomas return NULL;
84 b61ceafc 2022-10-13 thomas basefd = dup(pack->basefd);
85 b61ceafc 2022-10-13 thomas if (basefd == -1)
86 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
88 b61ceafc 2022-10-13 thomas accumfd = dup(pack->accumfd);
89 b61ceafc 2022-10-13 thomas if (accumfd == -1) {
90 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
91 b61ceafc 2022-10-13 thomas goto done;
94 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, basefd);
96 b61ceafc 2022-10-13 thomas goto done;
98 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, accumfd);
100 b61ceafc 2022-10-13 thomas if (err) {
101 b61ceafc 2022-10-13 thomas if (basefd != -1)
102 b61ceafc 2022-10-13 thomas close(basefd);
103 b61ceafc 2022-10-13 thomas if (accumfd != -1)
104 b61ceafc 2022-10-13 thomas close(accumfd);
106 b61ceafc 2022-10-13 thomas pack->child_has_tempfiles = 1;
107 a66a4a50 2023-02-03 thomas return err;
110 b61ceafc 2022-10-13 thomas static const struct got_error *
111 b61ceafc 2022-10-13 thomas request_packed_object_raw(uint8_t **outbuf, off_t *size, size_t *hdrlen,
112 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, int idx, struct got_object_id *id)
114 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
115 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
116 b61ceafc 2022-10-13 thomas int outfd_child;
118 9c57c4c6 2024-02-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
120 b61ceafc 2022-10-13 thomas return err;
122 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
123 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
124 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
126 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_raw_obj_req(ibuf, idx, id);
127 b61ceafc 2022-10-13 thomas if (err) {
128 b61ceafc 2022-10-13 thomas close(outfd_child);
129 b61ceafc 2022-10-13 thomas return err;
132 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
134 b61ceafc 2022-10-13 thomas return err;
136 b61ceafc 2022-10-13 thomas err = got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
138 b61ceafc 2022-10-13 thomas return err;
140 b61ceafc 2022-10-13 thomas return NULL;
143 b61ceafc 2022-10-13 thomas static const struct got_error *
144 b61ceafc 2022-10-13 thomas read_packed_object_privsep(struct got_object **obj,
145 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_pack *pack,
146 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int idx, struct got_object_id *id)
148 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
150 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
151 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
153 b61ceafc 2022-10-13 thomas return err;
156 b61ceafc 2022-10-13 thomas return request_packed_object(obj, pack, idx, id);
159 b61ceafc 2022-10-13 thomas static const struct got_error *
160 b61ceafc 2022-10-13 thomas read_packed_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
161 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
162 b61ceafc 2022-10-13 thomas struct got_object_id *id)
164 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
166 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
167 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
169 b61ceafc 2022-10-13 thomas return err;
172 b61ceafc 2022-10-13 thomas return request_packed_object_raw(outbuf, size, hdrlen, outfd, pack,
173 b61ceafc 2022-10-13 thomas idx, id);
176 b61ceafc 2022-10-13 thomas const struct got_error *
177 b61ceafc 2022-10-13 thomas got_object_open_packed(struct got_object **obj, struct got_object_id *id,
178 b61ceafc 2022-10-13 thomas struct got_repository *repo)
180 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
181 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
182 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
184 b61ceafc 2022-10-13 thomas char *path_packfile;
186 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
188 b61ceafc 2022-10-13 thomas return err;
190 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
191 b61ceafc 2022-10-13 thomas packidx->path_packidx);
193 b61ceafc 2022-10-13 thomas return err;
195 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
196 b61ceafc 2022-10-13 thomas if (pack == NULL) {
197 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
199 b61ceafc 2022-10-13 thomas goto done;
202 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(obj, repo, pack, packidx, idx, id);
204 b61ceafc 2022-10-13 thomas goto done;
206 b61ceafc 2022-10-13 thomas free(path_packfile);
207 b61ceafc 2022-10-13 thomas return err;
210 b61ceafc 2022-10-13 thomas const struct got_error *
211 b61ceafc 2022-10-13 thomas got_object_open_from_packfile(struct got_object **obj, struct got_object_id *id,
212 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
213 b61ceafc 2022-10-13 thomas struct got_repository *repo)
215 b61ceafc 2022-10-13 thomas return read_packed_object_privsep(obj, repo, pack, packidx,
216 b61ceafc 2022-10-13 thomas obj_idx, id);
219 b61ceafc 2022-10-13 thomas const struct got_error *
220 b61ceafc 2022-10-13 thomas got_object_read_raw_delta(uint64_t *base_size, uint64_t *result_size,
221 b61ceafc 2022-10-13 thomas off_t *delta_size, off_t *delta_compressed_size, off_t *delta_offset,
222 b61ceafc 2022-10-13 thomas off_t *delta_out_offset, struct got_object_id **base_id, int delta_cache_fd,
223 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
224 b61ceafc 2022-10-13 thomas struct got_repository *repo)
226 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
227 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
228 b61ceafc 2022-10-13 thomas char *path_packfile;
230 b61ceafc 2022-10-13 thomas *base_size = 0;
231 b61ceafc 2022-10-13 thomas *result_size = 0;
232 b61ceafc 2022-10-13 thomas *delta_size = 0;
233 b61ceafc 2022-10-13 thomas *delta_compressed_size = 0;
234 b61ceafc 2022-10-13 thomas *delta_offset = 0;
235 b61ceafc 2022-10-13 thomas *delta_out_offset = 0;
237 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
238 b61ceafc 2022-10-13 thomas packidx->path_packidx);
240 b61ceafc 2022-10-13 thomas return err;
242 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
243 b61ceafc 2022-10-13 thomas if (pack == NULL) {
244 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
246 b61ceafc 2022-10-13 thomas return err;
249 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
250 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
252 b61ceafc 2022-10-13 thomas return err;
255 b61ceafc 2022-10-13 thomas if (!pack->child_has_delta_outfd) {
256 b61ceafc 2022-10-13 thomas int outfd_child;
257 b61ceafc 2022-10-13 thomas outfd_child = dup(delta_cache_fd);
258 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
259 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
260 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_outfd(
261 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, outfd_child);
263 b61ceafc 2022-10-13 thomas return err;
264 b61ceafc 2022-10-13 thomas pack->child_has_delta_outfd = 1;
267 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_req(pack->privsep_child->ibuf,
268 b61ceafc 2022-10-13 thomas obj_idx, id);
270 b61ceafc 2022-10-13 thomas return err;
272 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_delta(base_size, result_size, delta_size,
273 b61ceafc 2022-10-13 thomas delta_compressed_size, delta_offset, delta_out_offset, base_id,
274 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
277 b61ceafc 2022-10-13 thomas static const struct got_error *
278 b61ceafc 2022-10-13 thomas request_object(struct got_object **obj, struct got_object_id *id,
279 b61ceafc 2022-10-13 thomas struct got_repository *repo, int fd)
281 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
282 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
284 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
286 b61ceafc 2022-10-13 thomas err = got_privsep_send_obj_req(ibuf, fd, id);
288 b61ceafc 2022-10-13 thomas return err;
290 b61ceafc 2022-10-13 thomas return got_privsep_recv_obj(obj, ibuf);
293 b61ceafc 2022-10-13 thomas static const struct got_error *
294 b61ceafc 2022-10-13 thomas request_raw_object(uint8_t **outbuf, off_t *size, size_t *hdrlen, int outfd,
295 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int infd)
297 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
298 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
299 b61ceafc 2022-10-13 thomas int outfd_child;
301 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
303 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
304 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
305 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
307 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_req(ibuf, infd, id);
309 b61ceafc 2022-10-13 thomas return err;
311 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
313 b61ceafc 2022-10-13 thomas return err;
315 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
318 b61ceafc 2022-10-13 thomas static const struct got_error *
319 54c22772 2022-10-13 thomas start_child(struct got_repository *repo, int type)
321 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
322 b61ceafc 2022-10-13 thomas int imsg_fds[2];
323 b61ceafc 2022-10-13 thomas pid_t pid;
324 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
325 54c22772 2022-10-13 thomas const char *prog_path;
327 54c22772 2022-10-13 thomas switch (type) {
328 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_OBJECT:
329 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_OBJECT;
331 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TREE:
332 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TREE;
334 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_COMMIT:
335 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_COMMIT;
337 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_BLOB:
338 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_BLOB;
340 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TAG:
341 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TAG;
344 54c22772 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
347 b61ceafc 2022-10-13 thomas ibuf = calloc(1, sizeof(*ibuf));
348 b61ceafc 2022-10-13 thomas if (ibuf == NULL)
349 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
351 b61ceafc 2022-10-13 thomas if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
352 b61ceafc 2022-10-13 thomas err = got_error_from_errno("socketpair");
353 b61ceafc 2022-10-13 thomas free(ibuf);
354 b61ceafc 2022-10-13 thomas return err;
357 b61ceafc 2022-10-13 thomas pid = fork();
358 b61ceafc 2022-10-13 thomas if (pid == -1) {
359 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fork");
360 b61ceafc 2022-10-13 thomas free(ibuf);
361 b61ceafc 2022-10-13 thomas return err;
363 b61ceafc 2022-10-13 thomas else if (pid == 0) {
364 54c22772 2022-10-13 thomas got_privsep_exec_child(imsg_fds, prog_path, repo->path);
365 b61ceafc 2022-10-13 thomas /* not reached */
368 b61ceafc 2022-10-13 thomas if (close(imsg_fds[1]) == -1) {
369 b61ceafc 2022-10-13 thomas err = got_error_from_errno("close");
370 b61ceafc 2022-10-13 thomas free(ibuf);
371 b61ceafc 2022-10-13 thomas return err;
374 54c22772 2022-10-13 thomas repo->privsep_children[type].imsg_fd = imsg_fds[0];
375 54c22772 2022-10-13 thomas repo->privsep_children[type].pid = pid;
376 b61ceafc 2022-10-13 thomas imsg_init(ibuf, imsg_fds[0]);
377 54c22772 2022-10-13 thomas repo->privsep_children[type].ibuf = ibuf;
379 b61ceafc 2022-10-13 thomas return NULL;
382 b61ceafc 2022-10-13 thomas const struct got_error *
383 b61ceafc 2022-10-13 thomas got_object_read_header_privsep(struct got_object **obj,
384 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int obj_fd)
386 b61ceafc 2022-10-13 thomas const struct got_error *err;
388 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
389 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
391 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
393 b61ceafc 2022-10-13 thomas return err;
395 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
398 b61ceafc 2022-10-13 thomas static const struct got_error *
399 b61ceafc 2022-10-13 thomas read_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
400 b61ceafc 2022-10-13 thomas int outfd, struct got_object_id *id, struct got_repository *repo,
401 b61ceafc 2022-10-13 thomas int obj_fd)
403 b61ceafc 2022-10-13 thomas const struct got_error *err;
405 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
406 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id,
407 b61ceafc 2022-10-13 thomas repo, obj_fd);
409 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
411 b61ceafc 2022-10-13 thomas return err;
413 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id, repo,
417 b61ceafc 2022-10-13 thomas const struct got_error *
418 b61ceafc 2022-10-13 thomas got_object_open(struct got_object **obj, struct got_repository *repo,
419 b61ceafc 2022-10-13 thomas struct got_object_id *id)
421 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
424 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_object(repo, id);
425 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
426 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
427 b61ceafc 2022-10-13 thomas return NULL;
430 b61ceafc 2022-10-13 thomas err = got_object_open_packed(obj, id, repo);
431 b61ceafc 2022-10-13 thomas if (err && err->code != GOT_ERR_NO_OBJ)
432 b61ceafc 2022-10-13 thomas return err;
433 b61ceafc 2022-10-13 thomas if (*obj) {
434 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
435 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
438 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
439 b61ceafc 2022-10-13 thomas if (err) {
440 b61ceafc 2022-10-13 thomas if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
441 b61ceafc 2022-10-13 thomas err = got_error_no_obj(id);
442 b61ceafc 2022-10-13 thomas return err;
445 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(obj, id, repo, fd);
447 b61ceafc 2022-10-13 thomas return err;
449 b102a16b 2023-02-07 thomas memcpy(&(*obj)->id, id, sizeof(*id));
451 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
452 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
455 b61ceafc 2022-10-13 thomas /* *outfd must be initialized to -1 by caller */
456 b61ceafc 2022-10-13 thomas const struct got_error *
457 b61ceafc 2022-10-13 thomas got_object_raw_open(struct got_raw_object **obj, int *outfd,
458 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
460 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
461 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
463 b61ceafc 2022-10-13 thomas uint8_t *outbuf = NULL;
464 b61ceafc 2022-10-13 thomas off_t size = 0;
465 b61ceafc 2022-10-13 thomas size_t hdrlen = 0;
466 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
468 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_raw_object(repo, id);
469 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
470 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
471 b61ceafc 2022-10-13 thomas return NULL;
474 b61ceafc 2022-10-13 thomas if (*outfd == -1) {
475 b61ceafc 2022-10-13 thomas *outfd = got_opentempfd();
476 b61ceafc 2022-10-13 thomas if (*outfd == -1)
477 b61ceafc 2022-10-13 thomas return got_error_from_errno("got_opentempfd");
480 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
481 b61ceafc 2022-10-13 thomas if (err == NULL) {
482 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
484 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
485 b61ceafc 2022-10-13 thomas packidx->path_packidx);
487 b61ceafc 2022-10-13 thomas goto done;
489 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
490 b61ceafc 2022-10-13 thomas if (pack == NULL) {
491 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
492 b61ceafc 2022-10-13 thomas packidx);
494 b61ceafc 2022-10-13 thomas goto done;
496 b61ceafc 2022-10-13 thomas err = read_packed_object_raw_privsep(&outbuf, &size, &hdrlen,
497 b61ceafc 2022-10-13 thomas *outfd, pack, packidx, idx, id);
499 b61ceafc 2022-10-13 thomas goto done;
500 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
503 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
505 b61ceafc 2022-10-13 thomas goto done;
506 b61ceafc 2022-10-13 thomas err = read_object_raw_privsep(&outbuf, &size, &hdrlen, *outfd,
507 b61ceafc 2022-10-13 thomas id, repo, fd);
509 b61ceafc 2022-10-13 thomas goto done;
512 ebe6ec92 2023-01-09 thomas err = got_object_raw_alloc(obj, outbuf, outfd,
513 ebe6ec92 2023-01-09 thomas GOT_DELTA_RESULT_SIZE_CACHED_MAX, hdrlen, size);
515 b61ceafc 2022-10-13 thomas goto done;
517 b61ceafc 2022-10-13 thomas err = got_repo_cache_raw_object(repo, id, *obj);
519 b61ceafc 2022-10-13 thomas free(path_packfile);
520 b61ceafc 2022-10-13 thomas if (err) {
521 b61ceafc 2022-10-13 thomas if (*obj) {
522 b61ceafc 2022-10-13 thomas got_object_raw_close(*obj);
523 b61ceafc 2022-10-13 thomas *obj = NULL;
525 b61ceafc 2022-10-13 thomas free(outbuf);
527 b61ceafc 2022-10-13 thomas return err;
530 b61ceafc 2022-10-13 thomas static const struct got_error *
531 b61ceafc 2022-10-13 thomas request_packed_commit(struct got_commit_object **commit, struct got_pack *pack,
532 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
534 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
536 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(pack->privsep_child->ibuf, -1, id,
537 b61ceafc 2022-10-13 thomas pack_idx);
539 b61ceafc 2022-10-13 thomas return err;
541 b61ceafc 2022-10-13 thomas err = got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
543 b61ceafc 2022-10-13 thomas return err;
545 b61ceafc 2022-10-13 thomas (*commit)->flags |= GOT_COMMIT_FLAG_PACKED;
546 b61ceafc 2022-10-13 thomas return NULL;
549 b61ceafc 2022-10-13 thomas static const struct got_error *
550 b61ceafc 2022-10-13 thomas read_packed_commit_privsep(struct got_commit_object **commit,
551 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
552 b61ceafc 2022-10-13 thomas struct got_object_id *id)
554 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
556 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
557 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
559 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
561 b61ceafc 2022-10-13 thomas return err;
563 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
566 b61ceafc 2022-10-13 thomas static const struct got_error *
567 b61ceafc 2022-10-13 thomas request_commit(struct got_commit_object **commit, struct got_repository *repo,
568 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
570 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
571 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
573 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
575 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(ibuf, fd, id, -1);
577 b61ceafc 2022-10-13 thomas return err;
579 b61ceafc 2022-10-13 thomas return got_privsep_recv_commit(commit, ibuf);
582 b61ceafc 2022-10-13 thomas static const struct got_error *
583 b61ceafc 2022-10-13 thomas read_commit_privsep(struct got_commit_object **commit, int obj_fd,
584 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
586 b61ceafc 2022-10-13 thomas const struct got_error *err;
588 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1)
589 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
591 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_COMMIT);
593 b61ceafc 2022-10-13 thomas return err;
595 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
598 b61ceafc 2022-10-13 thomas static const struct got_error *
599 b61ceafc 2022-10-13 thomas open_commit(struct got_commit_object **commit,
600 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, int check_cache)
602 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
603 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
605 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
607 b61ceafc 2022-10-13 thomas if (check_cache) {
608 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
609 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
610 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
611 b61ceafc 2022-10-13 thomas return NULL;
614 b61ceafc 2022-10-13 thomas *commit = NULL;
616 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
617 b61ceafc 2022-10-13 thomas if (err == NULL) {
618 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
620 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
621 b61ceafc 2022-10-13 thomas packidx->path_packidx);
623 b61ceafc 2022-10-13 thomas return err;
625 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
626 b61ceafc 2022-10-13 thomas if (pack == NULL) {
627 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
628 b61ceafc 2022-10-13 thomas packidx);
630 b61ceafc 2022-10-13 thomas goto done;
632 b61ceafc 2022-10-13 thomas err = read_packed_commit_privsep(commit, pack,
633 b61ceafc 2022-10-13 thomas packidx, idx, id);
634 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
637 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
639 b61ceafc 2022-10-13 thomas return err;
640 b61ceafc 2022-10-13 thomas err = read_commit_privsep(commit, fd, id, repo);
643 b61ceafc 2022-10-13 thomas if (err == NULL) {
644 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
645 b61ceafc 2022-10-13 thomas err = got_repo_cache_commit(repo, id, *commit);
648 b61ceafc 2022-10-13 thomas free(path_packfile);
649 b61ceafc 2022-10-13 thomas return err;
652 b61ceafc 2022-10-13 thomas const struct got_error *
653 b61ceafc 2022-10-13 thomas got_object_open_as_commit(struct got_commit_object **commit,
654 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
656 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
657 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
658 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
659 b61ceafc 2022-10-13 thomas return NULL;
662 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, id, 0);
665 b61ceafc 2022-10-13 thomas const struct got_error *
666 b61ceafc 2022-10-13 thomas got_object_commit_open(struct got_commit_object **commit,
667 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
669 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, got_object_get_id(obj), 1);
672 b61ceafc 2022-10-13 thomas static const struct got_error *
673 b61ceafc 2022-10-13 thomas request_packed_tree(struct got_tree_object **tree, struct got_pack *pack,
674 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
676 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
678 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(pack->privsep_child->ibuf, -1, id,
679 b61ceafc 2022-10-13 thomas pack_idx);
681 b61ceafc 2022-10-13 thomas return err;
683 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, pack->privsep_child->ibuf);
686 b61ceafc 2022-10-13 thomas static const struct got_error *
687 b61ceafc 2022-10-13 thomas read_packed_tree_privsep(struct got_tree_object **tree,
688 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
689 b61ceafc 2022-10-13 thomas struct got_object_id *id)
691 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
693 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
694 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
696 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
698 b61ceafc 2022-10-13 thomas return err;
700 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
703 b61ceafc 2022-10-13 thomas static const struct got_error *
704 b61ceafc 2022-10-13 thomas request_tree(struct got_tree_object **tree, struct got_repository *repo,
705 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
707 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
708 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
710 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
712 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(ibuf, fd, id, -1);
714 b61ceafc 2022-10-13 thomas return err;
716 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, ibuf);
719 b61ceafc 2022-10-13 thomas static const struct got_error *
720 b61ceafc 2022-10-13 thomas read_tree_privsep(struct got_tree_object **tree, int obj_fd,
721 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
723 b61ceafc 2022-10-13 thomas const struct got_error *err;
725 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd != -1)
726 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
728 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TREE);
730 b61ceafc 2022-10-13 thomas return err;
732 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
735 b61ceafc 2022-10-13 thomas static const struct got_error *
736 b61ceafc 2022-10-13 thomas open_tree(struct got_tree_object **tree, struct got_repository *repo,
737 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
739 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
740 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
742 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
744 b61ceafc 2022-10-13 thomas if (check_cache) {
745 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
746 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
747 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
748 b61ceafc 2022-10-13 thomas return NULL;
751 b61ceafc 2022-10-13 thomas *tree = NULL;
753 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
754 b61ceafc 2022-10-13 thomas if (err == NULL) {
755 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
757 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
758 b61ceafc 2022-10-13 thomas packidx->path_packidx);
760 b61ceafc 2022-10-13 thomas return err;
762 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
763 b61ceafc 2022-10-13 thomas if (pack == NULL) {
764 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
765 b61ceafc 2022-10-13 thomas packidx);
767 b61ceafc 2022-10-13 thomas goto done;
769 b61ceafc 2022-10-13 thomas err = read_packed_tree_privsep(tree, pack,
770 b61ceafc 2022-10-13 thomas packidx, idx, id);
771 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
774 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
776 b61ceafc 2022-10-13 thomas return err;
777 b61ceafc 2022-10-13 thomas err = read_tree_privsep(tree, fd, id, repo);
780 b61ceafc 2022-10-13 thomas if (err == NULL) {
781 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
782 b61ceafc 2022-10-13 thomas err = got_repo_cache_tree(repo, id, *tree);
785 b61ceafc 2022-10-13 thomas free(path_packfile);
786 b61ceafc 2022-10-13 thomas return err;
789 b61ceafc 2022-10-13 thomas const struct got_error *
790 b61ceafc 2022-10-13 thomas got_object_open_as_tree(struct got_tree_object **tree,
791 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
793 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
794 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
795 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
796 b61ceafc 2022-10-13 thomas return NULL;
799 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, id, 0);
802 b61ceafc 2022-10-13 thomas const struct got_error *
803 b61ceafc 2022-10-13 thomas got_object_tree_open(struct got_tree_object **tree,
804 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
806 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, got_object_get_id(obj), 1);
809 b61ceafc 2022-10-13 thomas static const struct got_error *
810 b61ceafc 2022-10-13 thomas request_packed_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
811 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
812 b61ceafc 2022-10-13 thomas struct got_object_id *id)
814 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
815 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
816 b61ceafc 2022-10-13 thomas int outfd_child;
818 9c57c4c6 2024-02-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
820 b61ceafc 2022-10-13 thomas return err;
822 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
823 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
824 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
826 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(pack->privsep_child->ibuf, -1, id, idx);
828 b61ceafc 2022-10-13 thomas return err;
830 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(pack->privsep_child->ibuf,
831 b61ceafc 2022-10-13 thomas outfd_child);
832 b61ceafc 2022-10-13 thomas if (err) {
833 b61ceafc 2022-10-13 thomas return err;
836 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen,
837 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
839 b61ceafc 2022-10-13 thomas return err;
841 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
842 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
844 b61ceafc 2022-10-13 thomas return err;
847 b61ceafc 2022-10-13 thomas static const struct got_error *
848 b61ceafc 2022-10-13 thomas read_packed_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
849 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
850 b61ceafc 2022-10-13 thomas struct got_object_id *id)
852 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
854 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
855 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
857 b61ceafc 2022-10-13 thomas return err;
860 b61ceafc 2022-10-13 thomas return request_packed_blob(outbuf, size, hdrlen, outfd, pack, packidx,
861 b61ceafc 2022-10-13 thomas idx, id);
864 b61ceafc 2022-10-13 thomas static const struct got_error *
865 b61ceafc 2022-10-13 thomas request_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
866 b61ceafc 2022-10-13 thomas int infd, struct got_object_id *id, struct imsgbuf *ibuf)
868 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
869 b61ceafc 2022-10-13 thomas int outfd_child;
871 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
872 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
873 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
875 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(ibuf, infd, id, -1);
877 b61ceafc 2022-10-13 thomas return err;
879 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(ibuf, outfd_child);
881 b61ceafc 2022-10-13 thomas return err;
883 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen, ibuf);
885 b61ceafc 2022-10-13 thomas return err;
887 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
888 b61ceafc 2022-10-13 thomas return got_error_from_errno("lseek");
890 b61ceafc 2022-10-13 thomas return err;
893 b61ceafc 2022-10-13 thomas static const struct got_error *
894 b61ceafc 2022-10-13 thomas read_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
895 b61ceafc 2022-10-13 thomas int outfd, int infd, struct got_object_id *id, struct got_repository *repo)
897 b61ceafc 2022-10-13 thomas const struct got_error *err;
898 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
900 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd != -1) {
901 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
902 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id,
906 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_BLOB);
908 b61ceafc 2022-10-13 thomas return err;
910 54c22772 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
911 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id, ibuf);
914 b61ceafc 2022-10-13 thomas static const struct got_error *
915 b61ceafc 2022-10-13 thomas open_blob(struct got_blob_object **blob, struct got_repository *repo,
916 b61ceafc 2022-10-13 thomas struct got_object_id *id, size_t blocksize, int outfd)
918 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
919 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
920 b61ceafc 2022-10-13 thomas int idx, dfd = -1;
921 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
922 b61ceafc 2022-10-13 thomas uint8_t *outbuf;
923 b61ceafc 2022-10-13 thomas size_t size, hdrlen;
924 b61ceafc 2022-10-13 thomas struct stat sb;
926 b61ceafc 2022-10-13 thomas *blob = calloc(1, sizeof(**blob));
927 b61ceafc 2022-10-13 thomas if (*blob == NULL)
928 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
930 b61ceafc 2022-10-13 thomas (*blob)->read_buf = malloc(blocksize);
931 b61ceafc 2022-10-13 thomas if ((*blob)->read_buf == NULL) {
932 b61ceafc 2022-10-13 thomas err = got_error_from_errno("malloc");
933 b61ceafc 2022-10-13 thomas goto done;
936 b61ceafc 2022-10-13 thomas if (ftruncate(outfd, 0L) == -1) {
937 b61ceafc 2022-10-13 thomas err = got_error_from_errno("ftruncate");
938 b61ceafc 2022-10-13 thomas goto done;
940 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1) {
941 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
942 b61ceafc 2022-10-13 thomas goto done;
945 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
946 b61ceafc 2022-10-13 thomas if (err == NULL) {
947 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
949 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
950 b61ceafc 2022-10-13 thomas packidx->path_packidx);
952 b61ceafc 2022-10-13 thomas goto done;
954 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
955 b61ceafc 2022-10-13 thomas if (pack == NULL) {
956 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
957 b61ceafc 2022-10-13 thomas packidx);
959 b61ceafc 2022-10-13 thomas goto done;
961 b61ceafc 2022-10-13 thomas err = read_packed_blob_privsep(&outbuf, &size, &hdrlen, outfd,
962 b61ceafc 2022-10-13 thomas pack, packidx, idx, id);
963 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
964 b61ceafc 2022-10-13 thomas int infd;
966 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&infd, id, repo);
968 b61ceafc 2022-10-13 thomas goto done;
969 b61ceafc 2022-10-13 thomas err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
970 b61ceafc 2022-10-13 thomas id, repo);
973 b61ceafc 2022-10-13 thomas goto done;
975 b61ceafc 2022-10-13 thomas if (hdrlen > size) {
976 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_BAD_OBJ_HDR);
977 b61ceafc 2022-10-13 thomas goto done;
980 b61ceafc 2022-10-13 thomas if (outbuf) {
981 b61ceafc 2022-10-13 thomas (*blob)->f = fmemopen(outbuf, size, "rb");
982 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
983 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fmemopen");
984 b61ceafc 2022-10-13 thomas free(outbuf);
985 b61ceafc 2022-10-13 thomas goto done;
987 b61ceafc 2022-10-13 thomas (*blob)->data = outbuf;
989 b61ceafc 2022-10-13 thomas if (fstat(outfd, &sb) == -1) {
990 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fstat");
991 b61ceafc 2022-10-13 thomas goto done;
994 b61ceafc 2022-10-13 thomas if (sb.st_size != size) {
995 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_PRIVSEP_LEN);
996 b61ceafc 2022-10-13 thomas goto done;
999 b61ceafc 2022-10-13 thomas dfd = dup(outfd);
1000 b61ceafc 2022-10-13 thomas if (dfd == -1) {
1001 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
1002 b61ceafc 2022-10-13 thomas goto done;
1005 b61ceafc 2022-10-13 thomas (*blob)->f = fdopen(dfd, "rb");
1006 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
1007 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fdopen");
1008 b61ceafc 2022-10-13 thomas close(dfd);
1009 b61ceafc 2022-10-13 thomas dfd = -1;
1010 b61ceafc 2022-10-13 thomas goto done;
1014 b61ceafc 2022-10-13 thomas (*blob)->hdrlen = hdrlen;
1015 b61ceafc 2022-10-13 thomas (*blob)->blocksize = blocksize;
1016 5b289346 2023-02-17 thomas memcpy(&(*blob)->id, id, sizeof(*id));
1019 b61ceafc 2022-10-13 thomas free(path_packfile);
1020 b61ceafc 2022-10-13 thomas if (err) {
1021 b61ceafc 2022-10-13 thomas if (*blob) {
1022 b61ceafc 2022-10-13 thomas got_object_blob_close(*blob);
1023 b61ceafc 2022-10-13 thomas *blob = NULL;
1026 b61ceafc 2022-10-13 thomas return err;
1029 b61ceafc 2022-10-13 thomas const struct got_error *
1030 b61ceafc 2022-10-13 thomas got_object_open_as_blob(struct got_blob_object **blob,
1031 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, size_t blocksize,
1032 b61ceafc 2022-10-13 thomas int outfd)
1034 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, id, blocksize, outfd);
1037 b61ceafc 2022-10-13 thomas const struct got_error *
1038 b61ceafc 2022-10-13 thomas got_object_blob_open(struct got_blob_object **blob,
1039 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj, size_t blocksize,
1040 b61ceafc 2022-10-13 thomas int outfd)
1042 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, got_object_get_id(obj), blocksize, outfd);
1045 b61ceafc 2022-10-13 thomas static const struct got_error *
1046 b61ceafc 2022-10-13 thomas request_packed_tag(struct got_tag_object **tag, struct got_pack *pack,
1047 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
1049 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1051 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(pack->privsep_child->ibuf, -1, id,
1052 b61ceafc 2022-10-13 thomas pack_idx);
1053 b61ceafc 2022-10-13 thomas if (err)
1054 b61ceafc 2022-10-13 thomas return err;
1056 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, pack->privsep_child->ibuf);
1059 b61ceafc 2022-10-13 thomas static const struct got_error *
1060 b61ceafc 2022-10-13 thomas read_packed_tag_privsep(struct got_tag_object **tag,
1061 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
1062 b61ceafc 2022-10-13 thomas struct got_object_id *id)
1064 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1066 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
1067 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1069 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1070 b61ceafc 2022-10-13 thomas if (err)
1071 b61ceafc 2022-10-13 thomas return err;
1073 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1076 b61ceafc 2022-10-13 thomas static const struct got_error *
1077 b61ceafc 2022-10-13 thomas request_tag(struct got_tag_object **tag, struct got_repository *repo,
1078 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
1080 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1081 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
1083 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].ibuf;
1085 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(ibuf, fd, id, -1);
1086 b61ceafc 2022-10-13 thomas if (err)
1087 b61ceafc 2022-10-13 thomas return err;
1089 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, ibuf);
1092 b61ceafc 2022-10-13 thomas static const struct got_error *
1093 b61ceafc 2022-10-13 thomas read_tag_privsep(struct got_tag_object **tag, int obj_fd,
1094 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
1096 b61ceafc 2022-10-13 thomas const struct got_error *err;
1098 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd != -1)
1099 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1101 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TAG);
1102 54c22772 2022-10-13 thomas if (err)
1103 b61ceafc 2022-10-13 thomas return err;
1105 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1108 b61ceafc 2022-10-13 thomas static const struct got_error *
1109 b61ceafc 2022-10-13 thomas open_tag(struct got_tag_object **tag, struct got_repository *repo,
1110 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
1112 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1113 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1114 b61ceafc 2022-10-13 thomas int idx;
1115 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1116 b61ceafc 2022-10-13 thomas struct got_object *obj = NULL;
1117 b61ceafc 2022-10-13 thomas int obj_type = GOT_OBJ_TYPE_ANY;
1119 b61ceafc 2022-10-13 thomas if (check_cache) {
1120 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1121 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1122 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1123 b61ceafc 2022-10-13 thomas return NULL;
1126 b61ceafc 2022-10-13 thomas *tag = NULL;
1128 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
1129 b61ceafc 2022-10-13 thomas if (err == NULL) {
1130 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1132 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1133 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1134 b61ceafc 2022-10-13 thomas if (err)
1135 b61ceafc 2022-10-13 thomas return err;
1137 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1138 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1139 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
1140 b61ceafc 2022-10-13 thomas packidx);
1141 b61ceafc 2022-10-13 thomas if (err)
1142 b61ceafc 2022-10-13 thomas goto done;
1145 b61ceafc 2022-10-13 thomas /* Beware of "lightweight" tags: Check object type first. */
1146 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(&obj, repo, pack, packidx,
1147 b61ceafc 2022-10-13 thomas idx, id);
1148 b61ceafc 2022-10-13 thomas if (err)
1149 b61ceafc 2022-10-13 thomas goto done;
1150 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1151 b61ceafc 2022-10-13 thomas got_object_close(obj);
1152 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG) {
1153 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_OBJ_TYPE);
1154 b61ceafc 2022-10-13 thomas goto done;
1156 b61ceafc 2022-10-13 thomas err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
1157 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
1160 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1161 b61ceafc 2022-10-13 thomas if (err)
1162 b61ceafc 2022-10-13 thomas return err;
1163 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(&obj, id, repo, fd);
1164 b61ceafc 2022-10-13 thomas if (err)
1165 b61ceafc 2022-10-13 thomas return err;
1166 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1167 b61ceafc 2022-10-13 thomas got_object_close(obj);
1168 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG)
1169 b61ceafc 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
1171 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1172 b61ceafc 2022-10-13 thomas if (err)
1173 b61ceafc 2022-10-13 thomas return err;
1174 b61ceafc 2022-10-13 thomas err = read_tag_privsep(tag, fd, id, repo);
1177 b61ceafc 2022-10-13 thomas if (err == NULL) {
1178 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1179 b61ceafc 2022-10-13 thomas err = got_repo_cache_tag(repo, id, *tag);
1182 b61ceafc 2022-10-13 thomas free(path_packfile);
1183 b61ceafc 2022-10-13 thomas return err;
1186 b61ceafc 2022-10-13 thomas const struct got_error *
1187 b61ceafc 2022-10-13 thomas got_object_open_as_tag(struct got_tag_object **tag,
1188 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
1190 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1191 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1192 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1193 b61ceafc 2022-10-13 thomas return NULL;
1196 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, id, 0);
1199 b61ceafc 2022-10-13 thomas const struct got_error *
1200 b61ceafc 2022-10-13 thomas got_object_tag_open(struct got_tag_object **tag,
1201 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
1203 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, got_object_get_id(obj), 1);
1206 b61ceafc 2022-10-13 thomas const struct got_error *
1207 b61ceafc 2022-10-13 thomas got_traverse_packed_commits(struct got_object_id_queue *traversed_commits,
1208 b61ceafc 2022-10-13 thomas struct got_object_id *commit_id, const char *path,
1209 b61ceafc 2022-10-13 thomas struct got_repository *repo)
1211 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1212 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1213 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1214 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1215 b61ceafc 2022-10-13 thomas struct got_commit_object *changed_commit = NULL;
1216 b61ceafc 2022-10-13 thomas struct got_object_id *changed_commit_id = NULL;
1217 b61ceafc 2022-10-13 thomas int idx;
1219 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, commit_id);
1220 b61ceafc 2022-10-13 thomas if (err) {
1221 b61ceafc 2022-10-13 thomas if (err->code != GOT_ERR_NO_OBJ)
1222 b61ceafc 2022-10-13 thomas return err;
1223 b61ceafc 2022-10-13 thomas return NULL;
1226 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1227 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1228 b61ceafc 2022-10-13 thomas if (err)
1229 b61ceafc 2022-10-13 thomas return err;
1231 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1232 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1233 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1234 b61ceafc 2022-10-13 thomas if (err)
1235 b61ceafc 2022-10-13 thomas goto done;
1238 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1239 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1240 b61ceafc 2022-10-13 thomas if (err)
1241 b61ceafc 2022-10-13 thomas goto done;
1244 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_traversal_request(
1245 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, commit_id, idx, path);
1246 b61ceafc 2022-10-13 thomas if (err)
1247 b61ceafc 2022-10-13 thomas goto done;
1249 b61ceafc 2022-10-13 thomas err = got_privsep_recv_traversed_commits(&changed_commit,
1250 b61ceafc 2022-10-13 thomas &changed_commit_id, traversed_commits, pack->privsep_child->ibuf);
1251 b61ceafc 2022-10-13 thomas if (err)
1252 b61ceafc 2022-10-13 thomas goto done;
1254 b61ceafc 2022-10-13 thomas if (changed_commit) {
1256 b61ceafc 2022-10-13 thomas * Cache the commit in which the path was changed.
1257 b61ceafc 2022-10-13 thomas * This commit might be opened again soon.
1259 b61ceafc 2022-10-13 thomas changed_commit->refcnt++;
1260 b61ceafc 2022-10-13 thomas err = got_repo_cache_commit(repo, changed_commit_id,
1261 b61ceafc 2022-10-13 thomas changed_commit);
1262 b61ceafc 2022-10-13 thomas got_object_commit_close(changed_commit);
1265 b61ceafc 2022-10-13 thomas free(path_packfile);
1266 b61ceafc 2022-10-13 thomas free(changed_commit_id);
1267 b61ceafc 2022-10-13 thomas return err;
1270 b61ceafc 2022-10-13 thomas const struct got_error *
1271 b61ceafc 2022-10-13 thomas got_object_enumerate(int *found_all_objects,
1272 b61ceafc 2022-10-13 thomas got_object_enumerate_commit_cb cb_commit,
1273 b61ceafc 2022-10-13 thomas got_object_enumerate_tree_cb cb_tree, void *cb_arg,
1274 b61ceafc 2022-10-13 thomas struct got_object_id **ours, int nours,
1275 b61ceafc 2022-10-13 thomas struct got_object_id **theirs, int ntheirs,
1276 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, struct got_repository *repo)
1278 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1279 b61ceafc 2022-10-13 thomas struct got_pack *pack;
1280 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1282 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1283 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1284 b61ceafc 2022-10-13 thomas if (err)
1285 b61ceafc 2022-10-13 thomas return err;
1287 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1288 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1289 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1290 b61ceafc 2022-10-13 thomas if (err)
1291 b61ceafc 2022-10-13 thomas goto done;
1294 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1295 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1296 b61ceafc 2022-10-13 thomas if (err)
1297 b61ceafc 2022-10-13 thomas goto done;
1300 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_enumeration_request(
1301 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
1302 b61ceafc 2022-10-13 thomas if (err)
1303 b61ceafc 2022-10-13 thomas goto done;
1305 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1306 b61ceafc 2022-10-13 thomas ours, nours);
1307 b61ceafc 2022-10-13 thomas if (err)
1308 b61ceafc 2022-10-13 thomas goto done;
1309 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1310 b61ceafc 2022-10-13 thomas if (err)
1311 b61ceafc 2022-10-13 thomas goto done;
1313 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1314 b61ceafc 2022-10-13 thomas theirs, ntheirs);
1315 b61ceafc 2022-10-13 thomas if (err)
1316 b61ceafc 2022-10-13 thomas goto done;
1317 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1318 b61ceafc 2022-10-13 thomas if (err)
1319 b61ceafc 2022-10-13 thomas goto done;
1321 b61ceafc 2022-10-13 thomas err = got_privsep_recv_enumerated_objects(found_all_objects,
1322 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo);
1324 b61ceafc 2022-10-13 thomas free(path_packfile);
1325 b61ceafc 2022-10-13 thomas return err;