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 b61ceafc 2022-10-13 thomas #include <sys/mman.h>
18 b61ceafc 2022-10-13 thomas #include <sys/queue.h>
19 b61ceafc 2022-10-13 thomas #include <sys/types.h>
20 b61ceafc 2022-10-13 thomas #include <sys/stat.h>
21 b61ceafc 2022-10-13 thomas #include <sys/socket.h>
22 b61ceafc 2022-10-13 thomas #include <sys/uio.h>
24 b61ceafc 2022-10-13 thomas #include <errno.h>
25 b61ceafc 2022-10-13 thomas #include <imsg.h>
26 b61ceafc 2022-10-13 thomas #include <stdio.h>
27 b61ceafc 2022-10-13 thomas #include <stdint.h>
28 b61ceafc 2022-10-13 thomas #include <stdlib.h>
29 b61ceafc 2022-10-13 thomas #include <string.h>
30 b61ceafc 2022-10-13 thomas #include <limits.h>
31 b61ceafc 2022-10-13 thomas #include <unistd.h>
33 4fccd2fe 2023-03-08 thomas #include "got_compat.h"
34 b61ceafc 2022-10-13 thomas #include "got_error.h"
35 b61ceafc 2022-10-13 thomas #include "got_object.h"
36 b61ceafc 2022-10-13 thomas #include "got_repository.h"
37 b61ceafc 2022-10-13 thomas #include "got_opentemp.h"
38 b61ceafc 2022-10-13 thomas #include "got_path.h"
40 b61ceafc 2022-10-13 thomas #include "got_lib_delta.h"
41 b61ceafc 2022-10-13 thomas #include "got_lib_object.h"
42 b61ceafc 2022-10-13 thomas #include "got_lib_privsep.h"
43 b61ceafc 2022-10-13 thomas #include "got_lib_object_cache.h"
44 b61ceafc 2022-10-13 thomas #include "got_lib_pack.h"
45 b61ceafc 2022-10-13 thomas #include "got_lib_repository.h"
47 b61ceafc 2022-10-13 thomas static const struct got_error *
48 b61ceafc 2022-10-13 thomas request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
49 b61ceafc 2022-10-13 thomas struct got_object_id *id)
51 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
52 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
54 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_obj_req(ibuf, idx, id);
56 b61ceafc 2022-10-13 thomas return err;
58 b61ceafc 2022-10-13 thomas err = got_privsep_recv_obj(obj, ibuf);
60 b61ceafc 2022-10-13 thomas return err;
62 b61ceafc 2022-10-13 thomas memcpy(&(*obj)->id, id, sizeof((*obj)->id));
64 b61ceafc 2022-10-13 thomas return NULL;
67 b61ceafc 2022-10-13 thomas /* Create temporary files used during delta application. */
68 b61ceafc 2022-10-13 thomas static const struct got_error *
69 b61ceafc 2022-10-13 thomas pack_child_send_tempfiles(struct imsgbuf *ibuf, struct got_pack *pack)
71 b61ceafc 2022-10-13 thomas const struct got_error *err;
72 b61ceafc 2022-10-13 thomas int basefd = -1, accumfd = -1;
75 b61ceafc 2022-10-13 thomas * For performance reasons, the child will keep reusing the
76 b61ceafc 2022-10-13 thomas * same temporary files during every object request.
77 b61ceafc 2022-10-13 thomas * Opening and closing new files for every object request is
78 b61ceafc 2022-10-13 thomas * too expensive during operations such as 'gotadmin pack'.
80 b61ceafc 2022-10-13 thomas if (pack->child_has_tempfiles)
81 b61ceafc 2022-10-13 thomas return NULL;
83 b61ceafc 2022-10-13 thomas basefd = dup(pack->basefd);
84 b61ceafc 2022-10-13 thomas if (basefd == -1)
85 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
87 b61ceafc 2022-10-13 thomas accumfd = dup(pack->accumfd);
88 b61ceafc 2022-10-13 thomas if (accumfd == -1) {
89 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
90 b61ceafc 2022-10-13 thomas goto done;
93 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, basefd);
95 b61ceafc 2022-10-13 thomas goto done;
97 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, accumfd);
99 b61ceafc 2022-10-13 thomas if (err) {
100 b61ceafc 2022-10-13 thomas if (basefd != -1)
101 b61ceafc 2022-10-13 thomas close(basefd);
102 b61ceafc 2022-10-13 thomas if (accumfd != -1)
103 b61ceafc 2022-10-13 thomas close(accumfd);
105 b61ceafc 2022-10-13 thomas pack->child_has_tempfiles = 1;
106 a66a4a50 2023-02-03 thomas return err;
109 b61ceafc 2022-10-13 thomas static const struct got_error *
110 b61ceafc 2022-10-13 thomas request_packed_object_raw(uint8_t **outbuf, off_t *size, size_t *hdrlen,
111 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, int idx, struct got_object_id *id)
113 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
114 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
115 b61ceafc 2022-10-13 thomas int outfd_child;
117 b61ceafc 2022-10-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
119 b61ceafc 2022-10-13 thomas return err;
121 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
122 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
123 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
125 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_raw_obj_req(ibuf, idx, id);
126 b61ceafc 2022-10-13 thomas if (err) {
127 b61ceafc 2022-10-13 thomas close(outfd_child);
128 b61ceafc 2022-10-13 thomas return err;
131 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
133 b61ceafc 2022-10-13 thomas return err;
135 b61ceafc 2022-10-13 thomas err = got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
137 b61ceafc 2022-10-13 thomas return err;
139 b61ceafc 2022-10-13 thomas return NULL;
142 b61ceafc 2022-10-13 thomas static const struct got_error *
143 b61ceafc 2022-10-13 thomas read_packed_object_privsep(struct got_object **obj,
144 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_pack *pack,
145 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int idx, struct got_object_id *id)
147 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
149 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
150 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
152 b61ceafc 2022-10-13 thomas return err;
155 b61ceafc 2022-10-13 thomas return request_packed_object(obj, pack, idx, id);
158 b61ceafc 2022-10-13 thomas static const struct got_error *
159 b61ceafc 2022-10-13 thomas read_packed_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
160 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
161 b61ceafc 2022-10-13 thomas struct got_object_id *id)
163 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
165 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
166 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
168 b61ceafc 2022-10-13 thomas return err;
171 b61ceafc 2022-10-13 thomas return request_packed_object_raw(outbuf, size, hdrlen, outfd, pack,
172 b61ceafc 2022-10-13 thomas idx, id);
175 b61ceafc 2022-10-13 thomas const struct got_error *
176 b61ceafc 2022-10-13 thomas got_object_open_packed(struct got_object **obj, struct got_object_id *id,
177 b61ceafc 2022-10-13 thomas struct got_repository *repo)
179 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
180 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
181 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
183 b61ceafc 2022-10-13 thomas char *path_packfile;
185 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
187 b61ceafc 2022-10-13 thomas return err;
189 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
190 b61ceafc 2022-10-13 thomas packidx->path_packidx);
192 b61ceafc 2022-10-13 thomas return err;
194 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
195 b61ceafc 2022-10-13 thomas if (pack == NULL) {
196 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
198 b61ceafc 2022-10-13 thomas goto done;
201 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(obj, repo, pack, packidx, idx, id);
203 b61ceafc 2022-10-13 thomas goto done;
205 b61ceafc 2022-10-13 thomas free(path_packfile);
206 b61ceafc 2022-10-13 thomas return err;
209 b61ceafc 2022-10-13 thomas const struct got_error *
210 b61ceafc 2022-10-13 thomas got_object_open_from_packfile(struct got_object **obj, struct got_object_id *id,
211 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
212 b61ceafc 2022-10-13 thomas struct got_repository *repo)
214 b61ceafc 2022-10-13 thomas return read_packed_object_privsep(obj, repo, pack, packidx,
215 b61ceafc 2022-10-13 thomas obj_idx, id);
218 b61ceafc 2022-10-13 thomas const struct got_error *
219 b61ceafc 2022-10-13 thomas got_object_read_raw_delta(uint64_t *base_size, uint64_t *result_size,
220 b61ceafc 2022-10-13 thomas off_t *delta_size, off_t *delta_compressed_size, off_t *delta_offset,
221 b61ceafc 2022-10-13 thomas off_t *delta_out_offset, struct got_object_id **base_id, int delta_cache_fd,
222 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
223 b61ceafc 2022-10-13 thomas struct got_repository *repo)
225 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
226 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
227 b61ceafc 2022-10-13 thomas char *path_packfile;
229 b61ceafc 2022-10-13 thomas *base_size = 0;
230 b61ceafc 2022-10-13 thomas *result_size = 0;
231 b61ceafc 2022-10-13 thomas *delta_size = 0;
232 b61ceafc 2022-10-13 thomas *delta_compressed_size = 0;
233 b61ceafc 2022-10-13 thomas *delta_offset = 0;
234 b61ceafc 2022-10-13 thomas *delta_out_offset = 0;
236 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
237 b61ceafc 2022-10-13 thomas packidx->path_packidx);
239 b61ceafc 2022-10-13 thomas return err;
241 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
242 b61ceafc 2022-10-13 thomas if (pack == NULL) {
243 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
245 b61ceafc 2022-10-13 thomas return err;
248 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
249 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
251 b61ceafc 2022-10-13 thomas return err;
254 b61ceafc 2022-10-13 thomas if (!pack->child_has_delta_outfd) {
255 b61ceafc 2022-10-13 thomas int outfd_child;
256 b61ceafc 2022-10-13 thomas outfd_child = dup(delta_cache_fd);
257 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
258 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
259 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_outfd(
260 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, outfd_child);
262 b61ceafc 2022-10-13 thomas return err;
263 b61ceafc 2022-10-13 thomas pack->child_has_delta_outfd = 1;
266 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_req(pack->privsep_child->ibuf,
267 b61ceafc 2022-10-13 thomas obj_idx, id);
269 b61ceafc 2022-10-13 thomas return err;
271 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_delta(base_size, result_size, delta_size,
272 b61ceafc 2022-10-13 thomas delta_compressed_size, delta_offset, delta_out_offset, base_id,
273 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
276 b61ceafc 2022-10-13 thomas static const struct got_error *
277 b61ceafc 2022-10-13 thomas request_object(struct got_object **obj, struct got_object_id *id,
278 b61ceafc 2022-10-13 thomas struct got_repository *repo, int fd)
280 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
281 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
283 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
285 b61ceafc 2022-10-13 thomas err = got_privsep_send_obj_req(ibuf, fd, id);
287 b61ceafc 2022-10-13 thomas return err;
289 b61ceafc 2022-10-13 thomas return got_privsep_recv_obj(obj, ibuf);
292 b61ceafc 2022-10-13 thomas static const struct got_error *
293 b61ceafc 2022-10-13 thomas request_raw_object(uint8_t **outbuf, off_t *size, size_t *hdrlen, int outfd,
294 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int infd)
296 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
297 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
298 b61ceafc 2022-10-13 thomas int outfd_child;
300 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
302 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
303 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
304 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
306 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_req(ibuf, infd, id);
308 b61ceafc 2022-10-13 thomas return err;
310 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
312 b61ceafc 2022-10-13 thomas return err;
314 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
317 b61ceafc 2022-10-13 thomas static const struct got_error *
318 54c22772 2022-10-13 thomas start_child(struct got_repository *repo, int type)
320 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
321 b61ceafc 2022-10-13 thomas int imsg_fds[2];
322 b61ceafc 2022-10-13 thomas pid_t pid;
323 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
324 54c22772 2022-10-13 thomas const char *prog_path;
326 54c22772 2022-10-13 thomas switch (type) {
327 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_OBJECT:
328 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_OBJECT;
330 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TREE:
331 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TREE;
333 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_COMMIT:
334 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_COMMIT;
336 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_BLOB:
337 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_BLOB;
339 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TAG:
340 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TAG;
343 54c22772 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
346 b61ceafc 2022-10-13 thomas ibuf = calloc(1, sizeof(*ibuf));
347 b61ceafc 2022-10-13 thomas if (ibuf == NULL)
348 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
350 b61ceafc 2022-10-13 thomas if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
351 b61ceafc 2022-10-13 thomas err = got_error_from_errno("socketpair");
352 b61ceafc 2022-10-13 thomas free(ibuf);
353 b61ceafc 2022-10-13 thomas return err;
356 b61ceafc 2022-10-13 thomas pid = fork();
357 b61ceafc 2022-10-13 thomas if (pid == -1) {
358 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fork");
359 b61ceafc 2022-10-13 thomas free(ibuf);
360 b61ceafc 2022-10-13 thomas return err;
362 b61ceafc 2022-10-13 thomas else if (pid == 0) {
363 54c22772 2022-10-13 thomas got_privsep_exec_child(imsg_fds, prog_path, repo->path);
364 b61ceafc 2022-10-13 thomas /* not reached */
367 b61ceafc 2022-10-13 thomas if (close(imsg_fds[1]) == -1) {
368 b61ceafc 2022-10-13 thomas err = got_error_from_errno("close");
369 b61ceafc 2022-10-13 thomas free(ibuf);
370 b61ceafc 2022-10-13 thomas return err;
373 54c22772 2022-10-13 thomas repo->privsep_children[type].imsg_fd = imsg_fds[0];
374 54c22772 2022-10-13 thomas repo->privsep_children[type].pid = pid;
375 b61ceafc 2022-10-13 thomas imsg_init(ibuf, imsg_fds[0]);
376 54c22772 2022-10-13 thomas repo->privsep_children[type].ibuf = ibuf;
378 b61ceafc 2022-10-13 thomas return NULL;
381 b61ceafc 2022-10-13 thomas const struct got_error *
382 b61ceafc 2022-10-13 thomas got_object_read_header_privsep(struct got_object **obj,
383 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int obj_fd)
385 b61ceafc 2022-10-13 thomas const struct got_error *err;
387 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
388 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
390 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
392 b61ceafc 2022-10-13 thomas return err;
394 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
397 b61ceafc 2022-10-13 thomas static const struct got_error *
398 b61ceafc 2022-10-13 thomas read_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
399 b61ceafc 2022-10-13 thomas int outfd, struct got_object_id *id, struct got_repository *repo,
400 b61ceafc 2022-10-13 thomas int obj_fd)
402 b61ceafc 2022-10-13 thomas const struct got_error *err;
404 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
405 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id,
406 b61ceafc 2022-10-13 thomas repo, obj_fd);
408 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
410 b61ceafc 2022-10-13 thomas return err;
412 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id, repo,
416 b61ceafc 2022-10-13 thomas const struct got_error *
417 b61ceafc 2022-10-13 thomas got_object_open(struct got_object **obj, struct got_repository *repo,
418 b61ceafc 2022-10-13 thomas struct got_object_id *id)
420 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
423 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_object(repo, id);
424 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
425 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
426 b61ceafc 2022-10-13 thomas return NULL;
429 b61ceafc 2022-10-13 thomas err = got_object_open_packed(obj, id, repo);
430 b61ceafc 2022-10-13 thomas if (err && err->code != GOT_ERR_NO_OBJ)
431 b61ceafc 2022-10-13 thomas return err;
432 b61ceafc 2022-10-13 thomas if (*obj) {
433 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
434 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
437 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
438 b61ceafc 2022-10-13 thomas if (err) {
439 b61ceafc 2022-10-13 thomas if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
440 b61ceafc 2022-10-13 thomas err = got_error_no_obj(id);
441 b61ceafc 2022-10-13 thomas return err;
444 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(obj, id, repo, fd);
446 b61ceafc 2022-10-13 thomas return err;
448 b102a16b 2023-02-07 thomas memcpy(&(*obj)->id, id, sizeof(*id));
450 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
451 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
454 b61ceafc 2022-10-13 thomas /* *outfd must be initialized to -1 by caller */
455 b61ceafc 2022-10-13 thomas const struct got_error *
456 b61ceafc 2022-10-13 thomas got_object_raw_open(struct got_raw_object **obj, int *outfd,
457 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
459 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
460 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
462 b61ceafc 2022-10-13 thomas uint8_t *outbuf = NULL;
463 b61ceafc 2022-10-13 thomas off_t size = 0;
464 b61ceafc 2022-10-13 thomas size_t hdrlen = 0;
465 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
467 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_raw_object(repo, id);
468 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
469 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
470 b61ceafc 2022-10-13 thomas return NULL;
473 b61ceafc 2022-10-13 thomas if (*outfd == -1) {
474 b61ceafc 2022-10-13 thomas *outfd = got_opentempfd();
475 b61ceafc 2022-10-13 thomas if (*outfd == -1)
476 b61ceafc 2022-10-13 thomas return got_error_from_errno("got_opentempfd");
479 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
480 b61ceafc 2022-10-13 thomas if (err == NULL) {
481 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
483 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
484 b61ceafc 2022-10-13 thomas packidx->path_packidx);
486 b61ceafc 2022-10-13 thomas goto done;
488 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
489 b61ceafc 2022-10-13 thomas if (pack == NULL) {
490 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
491 b61ceafc 2022-10-13 thomas packidx);
493 b61ceafc 2022-10-13 thomas goto done;
495 b61ceafc 2022-10-13 thomas err = read_packed_object_raw_privsep(&outbuf, &size, &hdrlen,
496 b61ceafc 2022-10-13 thomas *outfd, pack, packidx, idx, id);
498 b61ceafc 2022-10-13 thomas goto done;
499 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
502 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
504 b61ceafc 2022-10-13 thomas goto done;
505 b61ceafc 2022-10-13 thomas err = read_object_raw_privsep(&outbuf, &size, &hdrlen, *outfd,
506 b61ceafc 2022-10-13 thomas id, repo, fd);
508 b61ceafc 2022-10-13 thomas goto done;
511 ebe6ec92 2023-01-09 thomas err = got_object_raw_alloc(obj, outbuf, outfd,
512 ebe6ec92 2023-01-09 thomas GOT_DELTA_RESULT_SIZE_CACHED_MAX, hdrlen, size);
514 b61ceafc 2022-10-13 thomas goto done;
516 b61ceafc 2022-10-13 thomas err = got_repo_cache_raw_object(repo, id, *obj);
518 b61ceafc 2022-10-13 thomas free(path_packfile);
519 b61ceafc 2022-10-13 thomas if (err) {
520 b61ceafc 2022-10-13 thomas if (*obj) {
521 b61ceafc 2022-10-13 thomas got_object_raw_close(*obj);
522 b61ceafc 2022-10-13 thomas *obj = NULL;
524 b61ceafc 2022-10-13 thomas free(outbuf);
526 b61ceafc 2022-10-13 thomas return err;
529 b61ceafc 2022-10-13 thomas static const struct got_error *
530 b61ceafc 2022-10-13 thomas request_packed_commit(struct got_commit_object **commit, struct got_pack *pack,
531 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
533 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
535 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(pack->privsep_child->ibuf, -1, id,
536 b61ceafc 2022-10-13 thomas pack_idx);
538 b61ceafc 2022-10-13 thomas return err;
540 b61ceafc 2022-10-13 thomas err = got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
542 b61ceafc 2022-10-13 thomas return err;
544 b61ceafc 2022-10-13 thomas (*commit)->flags |= GOT_COMMIT_FLAG_PACKED;
545 b61ceafc 2022-10-13 thomas return NULL;
548 b61ceafc 2022-10-13 thomas static const struct got_error *
549 b61ceafc 2022-10-13 thomas read_packed_commit_privsep(struct got_commit_object **commit,
550 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
551 b61ceafc 2022-10-13 thomas struct got_object_id *id)
553 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
555 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
556 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
558 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
560 b61ceafc 2022-10-13 thomas return err;
562 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
565 b61ceafc 2022-10-13 thomas static const struct got_error *
566 b61ceafc 2022-10-13 thomas request_commit(struct got_commit_object **commit, struct got_repository *repo,
567 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
569 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
570 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
572 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
574 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(ibuf, fd, id, -1);
576 b61ceafc 2022-10-13 thomas return err;
578 b61ceafc 2022-10-13 thomas return got_privsep_recv_commit(commit, ibuf);
581 b61ceafc 2022-10-13 thomas static const struct got_error *
582 b61ceafc 2022-10-13 thomas read_commit_privsep(struct got_commit_object **commit, int obj_fd,
583 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
585 b61ceafc 2022-10-13 thomas const struct got_error *err;
587 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1)
588 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
590 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_COMMIT);
592 b61ceafc 2022-10-13 thomas return err;
594 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
597 b61ceafc 2022-10-13 thomas static const struct got_error *
598 b61ceafc 2022-10-13 thomas open_commit(struct got_commit_object **commit,
599 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, int check_cache)
601 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
602 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
604 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
606 b61ceafc 2022-10-13 thomas if (check_cache) {
607 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
608 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
609 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
610 b61ceafc 2022-10-13 thomas return NULL;
613 b61ceafc 2022-10-13 thomas *commit = NULL;
615 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
616 b61ceafc 2022-10-13 thomas if (err == NULL) {
617 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
619 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
620 b61ceafc 2022-10-13 thomas packidx->path_packidx);
622 b61ceafc 2022-10-13 thomas return err;
624 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
625 b61ceafc 2022-10-13 thomas if (pack == NULL) {
626 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
627 b61ceafc 2022-10-13 thomas packidx);
629 b61ceafc 2022-10-13 thomas goto done;
631 b61ceafc 2022-10-13 thomas err = read_packed_commit_privsep(commit, pack,
632 b61ceafc 2022-10-13 thomas packidx, idx, id);
633 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
636 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
638 b61ceafc 2022-10-13 thomas return err;
639 b61ceafc 2022-10-13 thomas err = read_commit_privsep(commit, fd, id, repo);
642 b61ceafc 2022-10-13 thomas if (err == NULL) {
643 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
644 b61ceafc 2022-10-13 thomas err = got_repo_cache_commit(repo, id, *commit);
647 b61ceafc 2022-10-13 thomas free(path_packfile);
648 b61ceafc 2022-10-13 thomas return err;
651 b61ceafc 2022-10-13 thomas const struct got_error *
652 b61ceafc 2022-10-13 thomas got_object_open_as_commit(struct got_commit_object **commit,
653 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
655 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
656 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
657 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
658 b61ceafc 2022-10-13 thomas return NULL;
661 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, id, 0);
664 b61ceafc 2022-10-13 thomas const struct got_error *
665 b61ceafc 2022-10-13 thomas got_object_commit_open(struct got_commit_object **commit,
666 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
668 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, got_object_get_id(obj), 1);
671 b61ceafc 2022-10-13 thomas static const struct got_error *
672 b61ceafc 2022-10-13 thomas request_packed_tree(struct got_tree_object **tree, struct got_pack *pack,
673 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
675 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
677 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(pack->privsep_child->ibuf, -1, id,
678 b61ceafc 2022-10-13 thomas pack_idx);
680 b61ceafc 2022-10-13 thomas return err;
682 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, pack->privsep_child->ibuf);
685 b61ceafc 2022-10-13 thomas static const struct got_error *
686 b61ceafc 2022-10-13 thomas read_packed_tree_privsep(struct got_tree_object **tree,
687 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
688 b61ceafc 2022-10-13 thomas struct got_object_id *id)
690 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
692 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
693 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
695 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
697 b61ceafc 2022-10-13 thomas return err;
699 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
702 b61ceafc 2022-10-13 thomas static const struct got_error *
703 b61ceafc 2022-10-13 thomas request_tree(struct got_tree_object **tree, struct got_repository *repo,
704 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
706 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
707 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
709 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
711 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(ibuf, fd, id, -1);
713 b61ceafc 2022-10-13 thomas return err;
715 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, ibuf);
718 b61ceafc 2022-10-13 thomas static const struct got_error *
719 b61ceafc 2022-10-13 thomas read_tree_privsep(struct got_tree_object **tree, int obj_fd,
720 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
722 b61ceafc 2022-10-13 thomas const struct got_error *err;
724 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd != -1)
725 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
727 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TREE);
729 b61ceafc 2022-10-13 thomas return err;
731 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
734 b61ceafc 2022-10-13 thomas static const struct got_error *
735 b61ceafc 2022-10-13 thomas open_tree(struct got_tree_object **tree, struct got_repository *repo,
736 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
738 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
739 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
741 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
743 b61ceafc 2022-10-13 thomas if (check_cache) {
744 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
745 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
746 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
747 b61ceafc 2022-10-13 thomas return NULL;
750 b61ceafc 2022-10-13 thomas *tree = NULL;
752 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
753 b61ceafc 2022-10-13 thomas if (err == NULL) {
754 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
756 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
757 b61ceafc 2022-10-13 thomas packidx->path_packidx);
759 b61ceafc 2022-10-13 thomas return err;
761 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
762 b61ceafc 2022-10-13 thomas if (pack == NULL) {
763 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
764 b61ceafc 2022-10-13 thomas packidx);
766 b61ceafc 2022-10-13 thomas goto done;
768 b61ceafc 2022-10-13 thomas err = read_packed_tree_privsep(tree, pack,
769 b61ceafc 2022-10-13 thomas packidx, idx, id);
770 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
773 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
775 b61ceafc 2022-10-13 thomas return err;
776 b61ceafc 2022-10-13 thomas err = read_tree_privsep(tree, fd, id, repo);
779 b61ceafc 2022-10-13 thomas if (err == NULL) {
780 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
781 b61ceafc 2022-10-13 thomas err = got_repo_cache_tree(repo, id, *tree);
784 b61ceafc 2022-10-13 thomas free(path_packfile);
785 b61ceafc 2022-10-13 thomas return err;
788 b61ceafc 2022-10-13 thomas const struct got_error *
789 b61ceafc 2022-10-13 thomas got_object_open_as_tree(struct got_tree_object **tree,
790 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
792 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
793 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
794 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
795 b61ceafc 2022-10-13 thomas return NULL;
798 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, id, 0);
801 b61ceafc 2022-10-13 thomas const struct got_error *
802 b61ceafc 2022-10-13 thomas got_object_tree_open(struct got_tree_object **tree,
803 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
805 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, got_object_get_id(obj), 1);
808 b61ceafc 2022-10-13 thomas static const struct got_error *
809 b61ceafc 2022-10-13 thomas request_packed_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
810 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
811 b61ceafc 2022-10-13 thomas struct got_object_id *id)
813 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
814 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
815 b61ceafc 2022-10-13 thomas int outfd_child;
817 b61ceafc 2022-10-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
819 b61ceafc 2022-10-13 thomas return err;
821 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
822 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
823 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
825 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(pack->privsep_child->ibuf, -1, id, idx);
827 b61ceafc 2022-10-13 thomas return err;
829 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(pack->privsep_child->ibuf,
830 b61ceafc 2022-10-13 thomas outfd_child);
831 b61ceafc 2022-10-13 thomas if (err) {
832 b61ceafc 2022-10-13 thomas return err;
835 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen,
836 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
838 b61ceafc 2022-10-13 thomas return err;
840 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
841 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
843 b61ceafc 2022-10-13 thomas return err;
846 b61ceafc 2022-10-13 thomas static const struct got_error *
847 b61ceafc 2022-10-13 thomas read_packed_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
848 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
849 b61ceafc 2022-10-13 thomas struct got_object_id *id)
851 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
853 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
854 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
856 b61ceafc 2022-10-13 thomas return err;
859 b61ceafc 2022-10-13 thomas return request_packed_blob(outbuf, size, hdrlen, outfd, pack, packidx,
860 b61ceafc 2022-10-13 thomas idx, id);
863 b61ceafc 2022-10-13 thomas static const struct got_error *
864 b61ceafc 2022-10-13 thomas request_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
865 b61ceafc 2022-10-13 thomas int infd, struct got_object_id *id, struct imsgbuf *ibuf)
867 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
868 b61ceafc 2022-10-13 thomas int outfd_child;
870 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
871 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
872 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
874 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(ibuf, infd, id, -1);
876 b61ceafc 2022-10-13 thomas return err;
878 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(ibuf, outfd_child);
880 b61ceafc 2022-10-13 thomas return err;
882 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen, ibuf);
884 b61ceafc 2022-10-13 thomas return err;
886 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
887 b61ceafc 2022-10-13 thomas return got_error_from_errno("lseek");
889 b61ceafc 2022-10-13 thomas return err;
892 b61ceafc 2022-10-13 thomas static const struct got_error *
893 b61ceafc 2022-10-13 thomas read_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
894 b61ceafc 2022-10-13 thomas int outfd, int infd, struct got_object_id *id, struct got_repository *repo)
896 b61ceafc 2022-10-13 thomas const struct got_error *err;
897 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
899 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd != -1) {
900 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
901 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id,
905 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_BLOB);
907 b61ceafc 2022-10-13 thomas return err;
909 54c22772 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
910 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id, ibuf);
913 b61ceafc 2022-10-13 thomas static const struct got_error *
914 b61ceafc 2022-10-13 thomas open_blob(struct got_blob_object **blob, struct got_repository *repo,
915 b61ceafc 2022-10-13 thomas struct got_object_id *id, size_t blocksize, int outfd)
917 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
918 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
919 b61ceafc 2022-10-13 thomas int idx, dfd = -1;
920 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
921 b61ceafc 2022-10-13 thomas uint8_t *outbuf;
922 b61ceafc 2022-10-13 thomas size_t size, hdrlen;
923 b61ceafc 2022-10-13 thomas struct stat sb;
925 b61ceafc 2022-10-13 thomas *blob = calloc(1, sizeof(**blob));
926 b61ceafc 2022-10-13 thomas if (*blob == NULL)
927 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
929 b61ceafc 2022-10-13 thomas (*blob)->read_buf = malloc(blocksize);
930 b61ceafc 2022-10-13 thomas if ((*blob)->read_buf == NULL) {
931 b61ceafc 2022-10-13 thomas err = got_error_from_errno("malloc");
932 b61ceafc 2022-10-13 thomas goto done;
935 b61ceafc 2022-10-13 thomas if (ftruncate(outfd, 0L) == -1) {
936 b61ceafc 2022-10-13 thomas err = got_error_from_errno("ftruncate");
937 b61ceafc 2022-10-13 thomas goto done;
939 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1) {
940 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
941 b61ceafc 2022-10-13 thomas goto done;
944 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
945 b61ceafc 2022-10-13 thomas if (err == NULL) {
946 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
948 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
949 b61ceafc 2022-10-13 thomas packidx->path_packidx);
951 b61ceafc 2022-10-13 thomas goto done;
953 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
954 b61ceafc 2022-10-13 thomas if (pack == NULL) {
955 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
956 b61ceafc 2022-10-13 thomas packidx);
958 b61ceafc 2022-10-13 thomas goto done;
960 b61ceafc 2022-10-13 thomas err = read_packed_blob_privsep(&outbuf, &size, &hdrlen, outfd,
961 b61ceafc 2022-10-13 thomas pack, packidx, idx, id);
962 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
963 b61ceafc 2022-10-13 thomas int infd;
965 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&infd, id, repo);
967 b61ceafc 2022-10-13 thomas goto done;
968 b61ceafc 2022-10-13 thomas err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
969 b61ceafc 2022-10-13 thomas id, repo);
972 b61ceafc 2022-10-13 thomas goto done;
974 b61ceafc 2022-10-13 thomas if (hdrlen > size) {
975 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_BAD_OBJ_HDR);
976 b61ceafc 2022-10-13 thomas goto done;
979 b61ceafc 2022-10-13 thomas if (outbuf) {
980 b61ceafc 2022-10-13 thomas (*blob)->f = fmemopen(outbuf, size, "rb");
981 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
982 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fmemopen");
983 b61ceafc 2022-10-13 thomas free(outbuf);
984 b61ceafc 2022-10-13 thomas goto done;
986 b61ceafc 2022-10-13 thomas (*blob)->data = outbuf;
988 b61ceafc 2022-10-13 thomas if (fstat(outfd, &sb) == -1) {
989 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fstat");
990 b61ceafc 2022-10-13 thomas goto done;
993 b61ceafc 2022-10-13 thomas if (sb.st_size != size) {
994 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_PRIVSEP_LEN);
995 b61ceafc 2022-10-13 thomas goto done;
998 b61ceafc 2022-10-13 thomas dfd = dup(outfd);
999 b61ceafc 2022-10-13 thomas if (dfd == -1) {
1000 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
1001 b61ceafc 2022-10-13 thomas goto done;
1004 b61ceafc 2022-10-13 thomas (*blob)->f = fdopen(dfd, "rb");
1005 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
1006 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fdopen");
1007 b61ceafc 2022-10-13 thomas close(dfd);
1008 b61ceafc 2022-10-13 thomas dfd = -1;
1009 b61ceafc 2022-10-13 thomas goto done;
1013 b61ceafc 2022-10-13 thomas (*blob)->hdrlen = hdrlen;
1014 b61ceafc 2022-10-13 thomas (*blob)->blocksize = blocksize;
1015 5b289346 2023-02-17 thomas memcpy(&(*blob)->id, id, sizeof(*id));
1018 b61ceafc 2022-10-13 thomas free(path_packfile);
1019 b61ceafc 2022-10-13 thomas if (err) {
1020 b61ceafc 2022-10-13 thomas if (*blob) {
1021 b61ceafc 2022-10-13 thomas got_object_blob_close(*blob);
1022 b61ceafc 2022-10-13 thomas *blob = NULL;
1025 b61ceafc 2022-10-13 thomas return err;
1028 b61ceafc 2022-10-13 thomas const struct got_error *
1029 b61ceafc 2022-10-13 thomas got_object_open_as_blob(struct got_blob_object **blob,
1030 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, size_t blocksize,
1031 b61ceafc 2022-10-13 thomas int outfd)
1033 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, id, blocksize, outfd);
1036 b61ceafc 2022-10-13 thomas const struct got_error *
1037 b61ceafc 2022-10-13 thomas got_object_blob_open(struct got_blob_object **blob,
1038 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj, size_t blocksize,
1039 b61ceafc 2022-10-13 thomas int outfd)
1041 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, got_object_get_id(obj), blocksize, outfd);
1044 b61ceafc 2022-10-13 thomas static const struct got_error *
1045 b61ceafc 2022-10-13 thomas request_packed_tag(struct got_tag_object **tag, struct got_pack *pack,
1046 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
1048 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1050 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(pack->privsep_child->ibuf, -1, id,
1051 b61ceafc 2022-10-13 thomas pack_idx);
1052 b61ceafc 2022-10-13 thomas if (err)
1053 b61ceafc 2022-10-13 thomas return err;
1055 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, pack->privsep_child->ibuf);
1058 b61ceafc 2022-10-13 thomas static const struct got_error *
1059 b61ceafc 2022-10-13 thomas read_packed_tag_privsep(struct got_tag_object **tag,
1060 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
1061 b61ceafc 2022-10-13 thomas struct got_object_id *id)
1063 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1065 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
1066 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1068 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1069 b61ceafc 2022-10-13 thomas if (err)
1070 b61ceafc 2022-10-13 thomas return err;
1072 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1075 b61ceafc 2022-10-13 thomas static const struct got_error *
1076 b61ceafc 2022-10-13 thomas request_tag(struct got_tag_object **tag, struct got_repository *repo,
1077 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
1079 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1080 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
1082 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].ibuf;
1084 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(ibuf, fd, id, -1);
1085 b61ceafc 2022-10-13 thomas if (err)
1086 b61ceafc 2022-10-13 thomas return err;
1088 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, ibuf);
1091 b61ceafc 2022-10-13 thomas static const struct got_error *
1092 b61ceafc 2022-10-13 thomas read_tag_privsep(struct got_tag_object **tag, int obj_fd,
1093 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
1095 b61ceafc 2022-10-13 thomas const struct got_error *err;
1097 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd != -1)
1098 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1100 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TAG);
1101 54c22772 2022-10-13 thomas if (err)
1102 b61ceafc 2022-10-13 thomas return err;
1104 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1107 b61ceafc 2022-10-13 thomas static const struct got_error *
1108 b61ceafc 2022-10-13 thomas open_tag(struct got_tag_object **tag, struct got_repository *repo,
1109 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
1111 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1112 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1113 b61ceafc 2022-10-13 thomas int idx;
1114 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1115 b61ceafc 2022-10-13 thomas struct got_object *obj = NULL;
1116 b61ceafc 2022-10-13 thomas int obj_type = GOT_OBJ_TYPE_ANY;
1118 b61ceafc 2022-10-13 thomas if (check_cache) {
1119 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1120 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1121 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1122 b61ceafc 2022-10-13 thomas return NULL;
1125 b61ceafc 2022-10-13 thomas *tag = NULL;
1127 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
1128 b61ceafc 2022-10-13 thomas if (err == NULL) {
1129 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1131 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1132 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1133 b61ceafc 2022-10-13 thomas if (err)
1134 b61ceafc 2022-10-13 thomas return err;
1136 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1137 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1138 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
1139 b61ceafc 2022-10-13 thomas packidx);
1140 b61ceafc 2022-10-13 thomas if (err)
1141 b61ceafc 2022-10-13 thomas goto done;
1144 b61ceafc 2022-10-13 thomas /* Beware of "lightweight" tags: Check object type first. */
1145 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(&obj, repo, pack, packidx,
1146 b61ceafc 2022-10-13 thomas idx, id);
1147 b61ceafc 2022-10-13 thomas if (err)
1148 b61ceafc 2022-10-13 thomas goto done;
1149 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1150 b61ceafc 2022-10-13 thomas got_object_close(obj);
1151 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG) {
1152 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_OBJ_TYPE);
1153 b61ceafc 2022-10-13 thomas goto done;
1155 b61ceafc 2022-10-13 thomas err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
1156 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
1159 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1160 b61ceafc 2022-10-13 thomas if (err)
1161 b61ceafc 2022-10-13 thomas return err;
1162 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(&obj, id, repo, fd);
1163 b61ceafc 2022-10-13 thomas if (err)
1164 b61ceafc 2022-10-13 thomas return err;
1165 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1166 b61ceafc 2022-10-13 thomas got_object_close(obj);
1167 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG)
1168 b61ceafc 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
1170 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1171 b61ceafc 2022-10-13 thomas if (err)
1172 b61ceafc 2022-10-13 thomas return err;
1173 b61ceafc 2022-10-13 thomas err = read_tag_privsep(tag, fd, id, repo);
1176 b61ceafc 2022-10-13 thomas if (err == NULL) {
1177 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1178 b61ceafc 2022-10-13 thomas err = got_repo_cache_tag(repo, id, *tag);
1181 b61ceafc 2022-10-13 thomas free(path_packfile);
1182 b61ceafc 2022-10-13 thomas return err;
1185 b61ceafc 2022-10-13 thomas const struct got_error *
1186 b61ceafc 2022-10-13 thomas got_object_open_as_tag(struct got_tag_object **tag,
1187 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
1189 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1190 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1191 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1192 b61ceafc 2022-10-13 thomas return NULL;
1195 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, id, 0);
1198 b61ceafc 2022-10-13 thomas const struct got_error *
1199 b61ceafc 2022-10-13 thomas got_object_tag_open(struct got_tag_object **tag,
1200 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
1202 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, got_object_get_id(obj), 1);
1205 b61ceafc 2022-10-13 thomas const struct got_error *
1206 b61ceafc 2022-10-13 thomas got_traverse_packed_commits(struct got_object_id_queue *traversed_commits,
1207 b61ceafc 2022-10-13 thomas struct got_object_id *commit_id, const char *path,
1208 b61ceafc 2022-10-13 thomas struct got_repository *repo)
1210 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1211 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1212 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1213 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1214 b61ceafc 2022-10-13 thomas struct got_commit_object *changed_commit = NULL;
1215 b61ceafc 2022-10-13 thomas struct got_object_id *changed_commit_id = NULL;
1216 b61ceafc 2022-10-13 thomas int idx;
1218 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, commit_id);
1219 b61ceafc 2022-10-13 thomas if (err) {
1220 b61ceafc 2022-10-13 thomas if (err->code != GOT_ERR_NO_OBJ)
1221 b61ceafc 2022-10-13 thomas return err;
1222 b61ceafc 2022-10-13 thomas return NULL;
1225 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1226 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1227 b61ceafc 2022-10-13 thomas if (err)
1228 b61ceafc 2022-10-13 thomas return err;
1230 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1231 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1232 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1233 b61ceafc 2022-10-13 thomas if (err)
1234 b61ceafc 2022-10-13 thomas goto done;
1237 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1238 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1239 b61ceafc 2022-10-13 thomas if (err)
1240 b61ceafc 2022-10-13 thomas goto done;
1243 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_traversal_request(
1244 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, commit_id, idx, path);
1245 b61ceafc 2022-10-13 thomas if (err)
1246 b61ceafc 2022-10-13 thomas goto done;
1248 b61ceafc 2022-10-13 thomas err = got_privsep_recv_traversed_commits(&changed_commit,
1249 b61ceafc 2022-10-13 thomas &changed_commit_id, traversed_commits, pack->privsep_child->ibuf);
1250 b61ceafc 2022-10-13 thomas if (err)
1251 b61ceafc 2022-10-13 thomas goto done;
1253 b61ceafc 2022-10-13 thomas if (changed_commit) {
1255 b61ceafc 2022-10-13 thomas * Cache the commit in which the path was changed.
1256 b61ceafc 2022-10-13 thomas * This commit might be opened again soon.
1258 b61ceafc 2022-10-13 thomas changed_commit->refcnt++;
1259 b61ceafc 2022-10-13 thomas err = got_repo_cache_commit(repo, changed_commit_id,
1260 b61ceafc 2022-10-13 thomas changed_commit);
1261 b61ceafc 2022-10-13 thomas got_object_commit_close(changed_commit);
1264 b61ceafc 2022-10-13 thomas free(path_packfile);
1265 b61ceafc 2022-10-13 thomas free(changed_commit_id);
1266 b61ceafc 2022-10-13 thomas return err;
1269 b61ceafc 2022-10-13 thomas const struct got_error *
1270 b61ceafc 2022-10-13 thomas got_object_enumerate(int *found_all_objects,
1271 b61ceafc 2022-10-13 thomas got_object_enumerate_commit_cb cb_commit,
1272 b61ceafc 2022-10-13 thomas got_object_enumerate_tree_cb cb_tree, void *cb_arg,
1273 b61ceafc 2022-10-13 thomas struct got_object_id **ours, int nours,
1274 b61ceafc 2022-10-13 thomas struct got_object_id **theirs, int ntheirs,
1275 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, struct got_repository *repo)
1277 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1278 b61ceafc 2022-10-13 thomas struct got_pack *pack;
1279 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1281 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1282 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1283 b61ceafc 2022-10-13 thomas if (err)
1284 b61ceafc 2022-10-13 thomas return err;
1286 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1287 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1288 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1289 b61ceafc 2022-10-13 thomas if (err)
1290 b61ceafc 2022-10-13 thomas goto done;
1293 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1294 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1295 b61ceafc 2022-10-13 thomas if (err)
1296 b61ceafc 2022-10-13 thomas goto done;
1299 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_enumeration_request(
1300 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
1301 b61ceafc 2022-10-13 thomas if (err)
1302 b61ceafc 2022-10-13 thomas goto done;
1304 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1305 b61ceafc 2022-10-13 thomas ours, nours);
1306 b61ceafc 2022-10-13 thomas if (err)
1307 b61ceafc 2022-10-13 thomas goto done;
1308 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1309 b61ceafc 2022-10-13 thomas if (err)
1310 b61ceafc 2022-10-13 thomas goto done;
1312 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1313 b61ceafc 2022-10-13 thomas theirs, ntheirs);
1314 b61ceafc 2022-10-13 thomas if (err)
1315 b61ceafc 2022-10-13 thomas goto done;
1316 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1317 b61ceafc 2022-10-13 thomas if (err)
1318 b61ceafc 2022-10-13 thomas goto done;
1320 b61ceafc 2022-10-13 thomas err = got_privsep_recv_enumerated_objects(found_all_objects,
1321 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo);
1323 b61ceafc 2022-10-13 thomas free(path_packfile);
1324 b61ceafc 2022-10-13 thomas return err;