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 f8c03d02 2024-03-30 thomas #include <stddef.h>
29 b61ceafc 2022-10-13 thomas #include <stdio.h>
30 b61ceafc 2022-10-13 thomas #include <stdint.h>
31 b61ceafc 2022-10-13 thomas #include <stdlib.h>
32 b61ceafc 2022-10-13 thomas #include <string.h>
33 b61ceafc 2022-10-13 thomas #include <limits.h>
34 b61ceafc 2022-10-13 thomas #include <unistd.h>
36 b61ceafc 2022-10-13 thomas #include "got_error.h"
37 b61ceafc 2022-10-13 thomas #include "got_object.h"
38 b61ceafc 2022-10-13 thomas #include "got_repository.h"
39 b61ceafc 2022-10-13 thomas #include "got_opentemp.h"
40 b61ceafc 2022-10-13 thomas #include "got_path.h"
42 b61ceafc 2022-10-13 thomas #include "got_lib_delta.h"
43 b61ceafc 2022-10-13 thomas #include "got_lib_object.h"
44 b61ceafc 2022-10-13 thomas #include "got_lib_privsep.h"
45 b61ceafc 2022-10-13 thomas #include "got_lib_object_cache.h"
46 b61ceafc 2022-10-13 thomas #include "got_lib_pack.h"
47 b61ceafc 2022-10-13 thomas #include "got_lib_repository.h"
49 b61ceafc 2022-10-13 thomas static const struct got_error *
50 b61ceafc 2022-10-13 thomas request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
51 b61ceafc 2022-10-13 thomas struct got_object_id *id)
53 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
54 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
56 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_obj_req(ibuf, idx, id);
58 b61ceafc 2022-10-13 thomas return err;
60 b61ceafc 2022-10-13 thomas err = got_privsep_recv_obj(obj, ibuf);
62 b61ceafc 2022-10-13 thomas return err;
64 b61ceafc 2022-10-13 thomas memcpy(&(*obj)->id, id, sizeof((*obj)->id));
66 b61ceafc 2022-10-13 thomas return NULL;
69 b61ceafc 2022-10-13 thomas /* Create temporary files used during delta application. */
70 b61ceafc 2022-10-13 thomas static const struct got_error *
71 b61ceafc 2022-10-13 thomas pack_child_send_tempfiles(struct imsgbuf *ibuf, struct got_pack *pack)
73 b61ceafc 2022-10-13 thomas const struct got_error *err;
74 b61ceafc 2022-10-13 thomas int basefd = -1, accumfd = -1;
77 b61ceafc 2022-10-13 thomas * For performance reasons, the child will keep reusing the
78 b61ceafc 2022-10-13 thomas * same temporary files during every object request.
79 b61ceafc 2022-10-13 thomas * Opening and closing new files for every object request is
80 b61ceafc 2022-10-13 thomas * too expensive during operations such as 'gotadmin pack'.
82 b61ceafc 2022-10-13 thomas if (pack->child_has_tempfiles)
83 b61ceafc 2022-10-13 thomas return NULL;
85 b61ceafc 2022-10-13 thomas basefd = dup(pack->basefd);
86 b61ceafc 2022-10-13 thomas if (basefd == -1)
87 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
89 b61ceafc 2022-10-13 thomas accumfd = dup(pack->accumfd);
90 b61ceafc 2022-10-13 thomas if (accumfd == -1) {
91 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
92 b61ceafc 2022-10-13 thomas goto done;
95 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, basefd);
97 b61ceafc 2022-10-13 thomas goto done;
99 b61ceafc 2022-10-13 thomas err = got_privsep_send_tmpfd(ibuf, accumfd);
101 b61ceafc 2022-10-13 thomas if (err) {
102 b61ceafc 2022-10-13 thomas if (basefd != -1)
103 b61ceafc 2022-10-13 thomas close(basefd);
104 b61ceafc 2022-10-13 thomas if (accumfd != -1)
105 b61ceafc 2022-10-13 thomas close(accumfd);
107 b61ceafc 2022-10-13 thomas pack->child_has_tempfiles = 1;
108 a66a4a50 2023-02-03 thomas return err;
111 b61ceafc 2022-10-13 thomas static const struct got_error *
112 b61ceafc 2022-10-13 thomas request_packed_object_raw(uint8_t **outbuf, off_t *size, size_t *hdrlen,
113 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, int idx, struct got_object_id *id)
115 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
116 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
117 b61ceafc 2022-10-13 thomas int outfd_child;
119 9c57c4c6 2024-02-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
121 b61ceafc 2022-10-13 thomas return err;
123 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
124 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
125 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
127 b61ceafc 2022-10-13 thomas err = got_privsep_send_packed_raw_obj_req(ibuf, idx, id);
128 b61ceafc 2022-10-13 thomas if (err) {
129 b61ceafc 2022-10-13 thomas close(outfd_child);
130 b61ceafc 2022-10-13 thomas return err;
133 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
135 b61ceafc 2022-10-13 thomas return err;
137 b61ceafc 2022-10-13 thomas err = got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
139 b61ceafc 2022-10-13 thomas return err;
141 b61ceafc 2022-10-13 thomas return NULL;
144 b61ceafc 2022-10-13 thomas static const struct got_error *
145 b61ceafc 2022-10-13 thomas read_packed_object_privsep(struct got_object **obj,
146 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_pack *pack,
147 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int idx, struct got_object_id *id)
149 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
151 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
152 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
154 b61ceafc 2022-10-13 thomas return err;
157 b61ceafc 2022-10-13 thomas return request_packed_object(obj, pack, idx, id);
160 b61ceafc 2022-10-13 thomas static const struct got_error *
161 b61ceafc 2022-10-13 thomas read_packed_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
162 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
163 b61ceafc 2022-10-13 thomas struct got_object_id *id)
165 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
167 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
168 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
170 b61ceafc 2022-10-13 thomas return err;
173 b61ceafc 2022-10-13 thomas return request_packed_object_raw(outbuf, size, hdrlen, outfd, pack,
174 b61ceafc 2022-10-13 thomas idx, id);
177 b61ceafc 2022-10-13 thomas const struct got_error *
178 b61ceafc 2022-10-13 thomas got_object_open_packed(struct got_object **obj, struct got_object_id *id,
179 b61ceafc 2022-10-13 thomas struct got_repository *repo)
181 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
182 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
183 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
185 b61ceafc 2022-10-13 thomas char *path_packfile;
187 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
189 b61ceafc 2022-10-13 thomas return err;
191 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
192 b61ceafc 2022-10-13 thomas packidx->path_packidx);
194 b61ceafc 2022-10-13 thomas return err;
196 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
197 b61ceafc 2022-10-13 thomas if (pack == NULL) {
198 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
200 b61ceafc 2022-10-13 thomas goto done;
203 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(obj, repo, pack, packidx, idx, id);
205 b61ceafc 2022-10-13 thomas goto done;
207 b61ceafc 2022-10-13 thomas free(path_packfile);
208 b61ceafc 2022-10-13 thomas return err;
211 b61ceafc 2022-10-13 thomas const struct got_error *
212 b61ceafc 2022-10-13 thomas got_object_open_from_packfile(struct got_object **obj, struct got_object_id *id,
213 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
214 b61ceafc 2022-10-13 thomas struct got_repository *repo)
216 b61ceafc 2022-10-13 thomas return read_packed_object_privsep(obj, repo, pack, packidx,
217 b61ceafc 2022-10-13 thomas obj_idx, id);
220 b61ceafc 2022-10-13 thomas const struct got_error *
221 b61ceafc 2022-10-13 thomas got_object_read_raw_delta(uint64_t *base_size, uint64_t *result_size,
222 b61ceafc 2022-10-13 thomas off_t *delta_size, off_t *delta_compressed_size, off_t *delta_offset,
223 b61ceafc 2022-10-13 thomas off_t *delta_out_offset, struct got_object_id **base_id, int delta_cache_fd,
224 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
225 b61ceafc 2022-10-13 thomas struct got_repository *repo)
227 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
228 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
229 b61ceafc 2022-10-13 thomas char *path_packfile;
231 b61ceafc 2022-10-13 thomas *base_size = 0;
232 b61ceafc 2022-10-13 thomas *result_size = 0;
233 b61ceafc 2022-10-13 thomas *delta_size = 0;
234 b61ceafc 2022-10-13 thomas *delta_compressed_size = 0;
235 b61ceafc 2022-10-13 thomas *delta_offset = 0;
236 b61ceafc 2022-10-13 thomas *delta_out_offset = 0;
238 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
239 b61ceafc 2022-10-13 thomas packidx->path_packidx);
241 b61ceafc 2022-10-13 thomas return err;
243 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
244 b61ceafc 2022-10-13 thomas if (pack == NULL) {
245 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
247 b61ceafc 2022-10-13 thomas return err;
250 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
251 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
253 b61ceafc 2022-10-13 thomas return err;
256 b61ceafc 2022-10-13 thomas if (!pack->child_has_delta_outfd) {
257 b61ceafc 2022-10-13 thomas int outfd_child;
258 b61ceafc 2022-10-13 thomas outfd_child = dup(delta_cache_fd);
259 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
260 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
261 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_outfd(
262 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, outfd_child);
264 b61ceafc 2022-10-13 thomas return err;
265 b61ceafc 2022-10-13 thomas pack->child_has_delta_outfd = 1;
268 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_delta_req(pack->privsep_child->ibuf,
269 b61ceafc 2022-10-13 thomas obj_idx, id);
271 b61ceafc 2022-10-13 thomas return err;
273 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_delta(base_size, result_size, delta_size,
274 b61ceafc 2022-10-13 thomas delta_compressed_size, delta_offset, delta_out_offset, base_id,
275 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
278 b61ceafc 2022-10-13 thomas static const struct got_error *
279 b61ceafc 2022-10-13 thomas request_object(struct got_object **obj, struct got_object_id *id,
280 b61ceafc 2022-10-13 thomas struct got_repository *repo, int fd)
282 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
283 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
285 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
287 b61ceafc 2022-10-13 thomas err = got_privsep_send_obj_req(ibuf, fd, id);
289 b61ceafc 2022-10-13 thomas return err;
291 b61ceafc 2022-10-13 thomas return got_privsep_recv_obj(obj, ibuf);
294 b61ceafc 2022-10-13 thomas static const struct got_error *
295 b61ceafc 2022-10-13 thomas request_raw_object(uint8_t **outbuf, off_t *size, size_t *hdrlen, int outfd,
296 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int infd)
298 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
299 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
300 b61ceafc 2022-10-13 thomas int outfd_child;
302 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
304 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
305 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
306 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
308 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_req(ibuf, infd, id);
310 b61ceafc 2022-10-13 thomas return err;
312 b61ceafc 2022-10-13 thomas err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
314 b61ceafc 2022-10-13 thomas return err;
316 b61ceafc 2022-10-13 thomas return got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
319 b61ceafc 2022-10-13 thomas static const struct got_error *
320 54c22772 2022-10-13 thomas start_child(struct got_repository *repo, int type)
322 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
323 b61ceafc 2022-10-13 thomas int imsg_fds[2];
324 b61ceafc 2022-10-13 thomas pid_t pid;
325 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
326 54c22772 2022-10-13 thomas const char *prog_path;
328 54c22772 2022-10-13 thomas switch (type) {
329 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_OBJECT:
330 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_OBJECT;
332 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TREE:
333 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TREE;
335 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_COMMIT:
336 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_COMMIT;
338 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_BLOB:
339 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_BLOB;
341 54c22772 2022-10-13 thomas case GOT_REPO_PRIVSEP_CHILD_TAG:
342 54c22772 2022-10-13 thomas prog_path = GOT_PATH_PROG_READ_TAG;
345 54c22772 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
348 b61ceafc 2022-10-13 thomas ibuf = calloc(1, sizeof(*ibuf));
349 b61ceafc 2022-10-13 thomas if (ibuf == NULL)
350 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
352 b61ceafc 2022-10-13 thomas if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
353 b61ceafc 2022-10-13 thomas err = got_error_from_errno("socketpair");
354 b61ceafc 2022-10-13 thomas free(ibuf);
355 b61ceafc 2022-10-13 thomas return err;
358 b61ceafc 2022-10-13 thomas pid = fork();
359 b61ceafc 2022-10-13 thomas if (pid == -1) {
360 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fork");
361 b61ceafc 2022-10-13 thomas free(ibuf);
362 b61ceafc 2022-10-13 thomas return err;
364 b61ceafc 2022-10-13 thomas else if (pid == 0) {
365 54c22772 2022-10-13 thomas got_privsep_exec_child(imsg_fds, prog_path, repo->path);
366 b61ceafc 2022-10-13 thomas /* not reached */
369 b61ceafc 2022-10-13 thomas if (close(imsg_fds[1]) == -1) {
370 b61ceafc 2022-10-13 thomas err = got_error_from_errno("close");
371 b61ceafc 2022-10-13 thomas free(ibuf);
372 b61ceafc 2022-10-13 thomas return err;
375 54c22772 2022-10-13 thomas repo->privsep_children[type].imsg_fd = imsg_fds[0];
376 54c22772 2022-10-13 thomas repo->privsep_children[type].pid = pid;
377 b61ceafc 2022-10-13 thomas imsg_init(ibuf, imsg_fds[0]);
378 54c22772 2022-10-13 thomas repo->privsep_children[type].ibuf = ibuf;
380 b61ceafc 2022-10-13 thomas return NULL;
383 b61ceafc 2022-10-13 thomas const struct got_error *
384 b61ceafc 2022-10-13 thomas got_object_read_header_privsep(struct got_object **obj,
385 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo, int obj_fd)
387 b61ceafc 2022-10-13 thomas const struct got_error *err;
389 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
390 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
392 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
394 b61ceafc 2022-10-13 thomas return err;
396 b61ceafc 2022-10-13 thomas return request_object(obj, id, repo, obj_fd);
399 b61ceafc 2022-10-13 thomas static const struct got_error *
400 b61ceafc 2022-10-13 thomas read_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
401 b61ceafc 2022-10-13 thomas int outfd, struct got_object_id *id, struct got_repository *repo,
402 b61ceafc 2022-10-13 thomas int obj_fd)
404 b61ceafc 2022-10-13 thomas const struct got_error *err;
406 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
407 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id,
408 b61ceafc 2022-10-13 thomas repo, obj_fd);
410 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_OBJECT);
412 b61ceafc 2022-10-13 thomas return err;
414 b61ceafc 2022-10-13 thomas return request_raw_object(outbuf, size, hdrlen, outfd, id, repo,
418 b61ceafc 2022-10-13 thomas const struct got_error *
419 b61ceafc 2022-10-13 thomas got_object_open(struct got_object **obj, struct got_repository *repo,
420 b61ceafc 2022-10-13 thomas struct got_object_id *id)
422 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
425 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_object(repo, id);
426 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
427 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
428 b61ceafc 2022-10-13 thomas return NULL;
431 b61ceafc 2022-10-13 thomas err = got_object_open_packed(obj, id, repo);
432 b61ceafc 2022-10-13 thomas if (err && err->code != GOT_ERR_NO_OBJ)
433 b61ceafc 2022-10-13 thomas return err;
434 b61ceafc 2022-10-13 thomas if (*obj) {
435 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
436 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
439 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
440 b61ceafc 2022-10-13 thomas if (err) {
441 b61ceafc 2022-10-13 thomas if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
442 b61ceafc 2022-10-13 thomas err = got_error_no_obj(id);
443 b61ceafc 2022-10-13 thomas return err;
446 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(obj, id, repo, fd);
448 b61ceafc 2022-10-13 thomas return err;
450 b102a16b 2023-02-07 thomas memcpy(&(*obj)->id, id, sizeof(*id));
452 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
453 b61ceafc 2022-10-13 thomas return got_repo_cache_object(repo, id, *obj);
456 b61ceafc 2022-10-13 thomas /* *outfd must be initialized to -1 by caller */
457 b61ceafc 2022-10-13 thomas const struct got_error *
458 b61ceafc 2022-10-13 thomas got_object_raw_open(struct got_raw_object **obj, int *outfd,
459 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
461 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
462 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
464 b61ceafc 2022-10-13 thomas uint8_t *outbuf = NULL;
465 b61ceafc 2022-10-13 thomas off_t size = 0;
466 b61ceafc 2022-10-13 thomas size_t hdrlen = 0;
467 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
469 b61ceafc 2022-10-13 thomas *obj = got_repo_get_cached_raw_object(repo, id);
470 b61ceafc 2022-10-13 thomas if (*obj != NULL) {
471 b61ceafc 2022-10-13 thomas (*obj)->refcnt++;
472 b61ceafc 2022-10-13 thomas return NULL;
475 b61ceafc 2022-10-13 thomas if (*outfd == -1) {
476 b61ceafc 2022-10-13 thomas *outfd = got_opentempfd();
477 b61ceafc 2022-10-13 thomas if (*outfd == -1)
478 b61ceafc 2022-10-13 thomas return got_error_from_errno("got_opentempfd");
481 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
482 b61ceafc 2022-10-13 thomas if (err == NULL) {
483 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
485 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
486 b61ceafc 2022-10-13 thomas packidx->path_packidx);
488 b61ceafc 2022-10-13 thomas goto done;
490 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
491 b61ceafc 2022-10-13 thomas if (pack == NULL) {
492 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
493 b61ceafc 2022-10-13 thomas packidx);
495 b61ceafc 2022-10-13 thomas goto done;
497 b61ceafc 2022-10-13 thomas err = read_packed_object_raw_privsep(&outbuf, &size, &hdrlen,
498 b61ceafc 2022-10-13 thomas *outfd, pack, packidx, idx, id);
500 b61ceafc 2022-10-13 thomas goto done;
501 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
504 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
506 b61ceafc 2022-10-13 thomas goto done;
507 b61ceafc 2022-10-13 thomas err = read_object_raw_privsep(&outbuf, &size, &hdrlen, *outfd,
508 b61ceafc 2022-10-13 thomas id, repo, fd);
510 b61ceafc 2022-10-13 thomas goto done;
513 ebe6ec92 2023-01-09 thomas err = got_object_raw_alloc(obj, outbuf, outfd,
514 ebe6ec92 2023-01-09 thomas GOT_DELTA_RESULT_SIZE_CACHED_MAX, hdrlen, size);
516 b61ceafc 2022-10-13 thomas goto done;
518 b61ceafc 2022-10-13 thomas err = got_repo_cache_raw_object(repo, id, *obj);
520 b61ceafc 2022-10-13 thomas free(path_packfile);
521 b61ceafc 2022-10-13 thomas if (err) {
522 b61ceafc 2022-10-13 thomas if (*obj) {
523 b61ceafc 2022-10-13 thomas got_object_raw_close(*obj);
524 b61ceafc 2022-10-13 thomas *obj = NULL;
526 b61ceafc 2022-10-13 thomas free(outbuf);
528 b61ceafc 2022-10-13 thomas return err;
531 b61ceafc 2022-10-13 thomas static const struct got_error *
532 b61ceafc 2022-10-13 thomas request_packed_commit(struct got_commit_object **commit, struct got_pack *pack,
533 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
535 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
537 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(pack->privsep_child->ibuf, -1, id,
538 b61ceafc 2022-10-13 thomas pack_idx);
540 b61ceafc 2022-10-13 thomas return err;
542 b61ceafc 2022-10-13 thomas err = got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
544 b61ceafc 2022-10-13 thomas return err;
546 b61ceafc 2022-10-13 thomas (*commit)->flags |= GOT_COMMIT_FLAG_PACKED;
547 b61ceafc 2022-10-13 thomas return NULL;
550 b61ceafc 2022-10-13 thomas static const struct got_error *
551 b61ceafc 2022-10-13 thomas read_packed_commit_privsep(struct got_commit_object **commit,
552 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
553 b61ceafc 2022-10-13 thomas struct got_object_id *id)
555 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
557 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
558 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
560 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
562 b61ceafc 2022-10-13 thomas return err;
564 b61ceafc 2022-10-13 thomas return request_packed_commit(commit, pack, idx, id);
567 b61ceafc 2022-10-13 thomas static const struct got_error *
568 b61ceafc 2022-10-13 thomas request_commit(struct got_commit_object **commit, struct got_repository *repo,
569 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
571 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
572 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
574 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
576 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_req(ibuf, fd, id, -1);
578 b61ceafc 2022-10-13 thomas return err;
580 b61ceafc 2022-10-13 thomas return got_privsep_recv_commit(commit, ibuf);
583 b61ceafc 2022-10-13 thomas static const struct got_error *
584 b61ceafc 2022-10-13 thomas read_commit_privsep(struct got_commit_object **commit, int obj_fd,
585 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
587 b61ceafc 2022-10-13 thomas const struct got_error *err;
589 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1)
590 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
592 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_COMMIT);
594 b61ceafc 2022-10-13 thomas return err;
596 b61ceafc 2022-10-13 thomas return request_commit(commit, repo, obj_fd, id);
599 b61ceafc 2022-10-13 thomas static const struct got_error *
600 b61ceafc 2022-10-13 thomas open_commit(struct got_commit_object **commit,
601 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, int check_cache)
603 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
604 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
606 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
608 b61ceafc 2022-10-13 thomas if (check_cache) {
609 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
610 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
611 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
612 b61ceafc 2022-10-13 thomas return NULL;
615 b61ceafc 2022-10-13 thomas *commit = NULL;
617 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
618 b61ceafc 2022-10-13 thomas if (err == NULL) {
619 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
621 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
622 b61ceafc 2022-10-13 thomas packidx->path_packidx);
624 b61ceafc 2022-10-13 thomas return err;
626 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
627 b61ceafc 2022-10-13 thomas if (pack == NULL) {
628 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
629 b61ceafc 2022-10-13 thomas packidx);
631 b61ceafc 2022-10-13 thomas goto done;
633 b61ceafc 2022-10-13 thomas err = read_packed_commit_privsep(commit, pack,
634 b61ceafc 2022-10-13 thomas packidx, idx, id);
635 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
638 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
640 b61ceafc 2022-10-13 thomas return err;
641 b61ceafc 2022-10-13 thomas err = read_commit_privsep(commit, fd, id, repo);
644 b61ceafc 2022-10-13 thomas if (err == NULL) {
645 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
646 b61ceafc 2022-10-13 thomas err = got_repo_cache_commit(repo, id, *commit);
649 b61ceafc 2022-10-13 thomas free(path_packfile);
650 b61ceafc 2022-10-13 thomas return err;
653 b61ceafc 2022-10-13 thomas const struct got_error *
654 b61ceafc 2022-10-13 thomas got_object_open_as_commit(struct got_commit_object **commit,
655 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
657 b61ceafc 2022-10-13 thomas *commit = got_repo_get_cached_commit(repo, id);
658 b61ceafc 2022-10-13 thomas if (*commit != NULL) {
659 b61ceafc 2022-10-13 thomas (*commit)->refcnt++;
660 b61ceafc 2022-10-13 thomas return NULL;
663 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, id, 0);
666 b61ceafc 2022-10-13 thomas const struct got_error *
667 b61ceafc 2022-10-13 thomas got_object_commit_open(struct got_commit_object **commit,
668 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
670 b61ceafc 2022-10-13 thomas return open_commit(commit, repo, got_object_get_id(obj), 1);
673 b61ceafc 2022-10-13 thomas static const struct got_error *
674 b61ceafc 2022-10-13 thomas request_packed_tree(struct got_tree_object **tree, struct got_pack *pack,
675 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
677 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
679 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(pack->privsep_child->ibuf, -1, id,
680 b61ceafc 2022-10-13 thomas pack_idx);
682 b61ceafc 2022-10-13 thomas return err;
684 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, pack->privsep_child->ibuf);
687 b61ceafc 2022-10-13 thomas static const struct got_error *
688 b61ceafc 2022-10-13 thomas read_packed_tree_privsep(struct got_tree_object **tree,
689 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
690 b61ceafc 2022-10-13 thomas struct got_object_id *id)
692 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
694 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
695 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
697 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
699 b61ceafc 2022-10-13 thomas return err;
701 b61ceafc 2022-10-13 thomas return request_packed_tree(tree, pack, idx, id);
704 b61ceafc 2022-10-13 thomas static const struct got_error *
705 b61ceafc 2022-10-13 thomas request_tree(struct got_tree_object **tree, struct got_repository *repo,
706 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
708 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
709 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
711 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
713 b61ceafc 2022-10-13 thomas err = got_privsep_send_tree_req(ibuf, fd, id, -1);
715 b61ceafc 2022-10-13 thomas return err;
717 b61ceafc 2022-10-13 thomas return got_privsep_recv_tree(tree, ibuf);
720 b61ceafc 2022-10-13 thomas static const struct got_error *
721 b61ceafc 2022-10-13 thomas read_tree_privsep(struct got_tree_object **tree, int obj_fd,
722 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
724 b61ceafc 2022-10-13 thomas const struct got_error *err;
726 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd != -1)
727 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
729 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TREE);
731 b61ceafc 2022-10-13 thomas return err;
733 b61ceafc 2022-10-13 thomas return request_tree(tree, repo, obj_fd, id);
736 b61ceafc 2022-10-13 thomas static const struct got_error *
737 b61ceafc 2022-10-13 thomas open_tree(struct got_tree_object **tree, struct got_repository *repo,
738 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
740 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
741 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
743 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
745 b61ceafc 2022-10-13 thomas if (check_cache) {
746 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
747 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
748 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
749 b61ceafc 2022-10-13 thomas return NULL;
752 b61ceafc 2022-10-13 thomas *tree = NULL;
754 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
755 b61ceafc 2022-10-13 thomas if (err == NULL) {
756 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
758 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
759 b61ceafc 2022-10-13 thomas packidx->path_packidx);
761 b61ceafc 2022-10-13 thomas return err;
763 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
764 b61ceafc 2022-10-13 thomas if (pack == NULL) {
765 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
766 b61ceafc 2022-10-13 thomas packidx);
768 b61ceafc 2022-10-13 thomas goto done;
770 b61ceafc 2022-10-13 thomas err = read_packed_tree_privsep(tree, pack,
771 b61ceafc 2022-10-13 thomas packidx, idx, id);
772 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
775 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
777 b61ceafc 2022-10-13 thomas return err;
778 b61ceafc 2022-10-13 thomas err = read_tree_privsep(tree, fd, id, repo);
781 b61ceafc 2022-10-13 thomas if (err == NULL) {
782 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
783 b61ceafc 2022-10-13 thomas err = got_repo_cache_tree(repo, id, *tree);
786 b61ceafc 2022-10-13 thomas free(path_packfile);
787 b61ceafc 2022-10-13 thomas return err;
790 b61ceafc 2022-10-13 thomas const struct got_error *
791 b61ceafc 2022-10-13 thomas got_object_open_as_tree(struct got_tree_object **tree,
792 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
794 b61ceafc 2022-10-13 thomas *tree = got_repo_get_cached_tree(repo, id);
795 b61ceafc 2022-10-13 thomas if (*tree != NULL) {
796 b61ceafc 2022-10-13 thomas (*tree)->refcnt++;
797 b61ceafc 2022-10-13 thomas return NULL;
800 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, id, 0);
803 b61ceafc 2022-10-13 thomas const struct got_error *
804 b61ceafc 2022-10-13 thomas got_object_tree_open(struct got_tree_object **tree,
805 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
807 b61ceafc 2022-10-13 thomas return open_tree(tree, repo, got_object_get_id(obj), 1);
810 b61ceafc 2022-10-13 thomas static const struct got_error *
811 b61ceafc 2022-10-13 thomas request_packed_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
812 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
813 b61ceafc 2022-10-13 thomas struct got_object_id *id)
815 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
816 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf = pack->privsep_child->ibuf;
817 b61ceafc 2022-10-13 thomas int outfd_child;
819 9c57c4c6 2024-02-13 thomas err = pack_child_send_tempfiles(ibuf, pack);
821 b61ceafc 2022-10-13 thomas return err;
823 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
824 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
825 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
827 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(pack->privsep_child->ibuf, -1, id, idx);
829 b61ceafc 2022-10-13 thomas return err;
831 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(pack->privsep_child->ibuf,
832 b61ceafc 2022-10-13 thomas outfd_child);
833 b61ceafc 2022-10-13 thomas if (err) {
834 b61ceafc 2022-10-13 thomas return err;
837 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen,
838 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
840 b61ceafc 2022-10-13 thomas return err;
842 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
843 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
845 b61ceafc 2022-10-13 thomas return err;
848 b61ceafc 2022-10-13 thomas static const struct got_error *
849 b61ceafc 2022-10-13 thomas read_packed_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
850 b61ceafc 2022-10-13 thomas int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
851 b61ceafc 2022-10-13 thomas struct got_object_id *id)
853 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
855 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
856 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
858 b61ceafc 2022-10-13 thomas return err;
861 b61ceafc 2022-10-13 thomas return request_packed_blob(outbuf, size, hdrlen, outfd, pack, packidx,
862 b61ceafc 2022-10-13 thomas idx, id);
865 b61ceafc 2022-10-13 thomas static const struct got_error *
866 b61ceafc 2022-10-13 thomas request_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
867 b61ceafc 2022-10-13 thomas int infd, struct got_object_id *id, struct imsgbuf *ibuf)
869 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
870 b61ceafc 2022-10-13 thomas int outfd_child;
872 b61ceafc 2022-10-13 thomas outfd_child = dup(outfd);
873 b61ceafc 2022-10-13 thomas if (outfd_child == -1)
874 b61ceafc 2022-10-13 thomas return got_error_from_errno("dup");
876 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_req(ibuf, infd, id, -1);
878 b61ceafc 2022-10-13 thomas return err;
880 b61ceafc 2022-10-13 thomas err = got_privsep_send_blob_outfd(ibuf, outfd_child);
882 b61ceafc 2022-10-13 thomas return err;
884 b61ceafc 2022-10-13 thomas err = got_privsep_recv_blob(outbuf, size, hdrlen, ibuf);
886 b61ceafc 2022-10-13 thomas return err;
888 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1)
889 b61ceafc 2022-10-13 thomas return got_error_from_errno("lseek");
891 b61ceafc 2022-10-13 thomas return err;
894 b61ceafc 2022-10-13 thomas static const struct got_error *
895 b61ceafc 2022-10-13 thomas read_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
896 b61ceafc 2022-10-13 thomas int outfd, int infd, struct got_object_id *id, struct got_repository *repo)
898 b61ceafc 2022-10-13 thomas const struct got_error *err;
899 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
901 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd != -1) {
902 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
903 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id,
907 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_BLOB);
909 b61ceafc 2022-10-13 thomas return err;
911 54c22772 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
912 b61ceafc 2022-10-13 thomas return request_blob(outbuf, size, hdrlen, outfd, infd, id, ibuf);
915 b61ceafc 2022-10-13 thomas static const struct got_error *
916 b61ceafc 2022-10-13 thomas open_blob(struct got_blob_object **blob, struct got_repository *repo,
917 b61ceafc 2022-10-13 thomas struct got_object_id *id, size_t blocksize, int outfd)
919 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
920 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
921 b61ceafc 2022-10-13 thomas int idx, dfd = -1;
922 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
923 b61ceafc 2022-10-13 thomas uint8_t *outbuf;
924 b61ceafc 2022-10-13 thomas size_t size, hdrlen;
925 b61ceafc 2022-10-13 thomas struct stat sb;
927 b61ceafc 2022-10-13 thomas *blob = calloc(1, sizeof(**blob));
928 b61ceafc 2022-10-13 thomas if (*blob == NULL)
929 b61ceafc 2022-10-13 thomas return got_error_from_errno("calloc");
931 b61ceafc 2022-10-13 thomas (*blob)->read_buf = malloc(blocksize);
932 b61ceafc 2022-10-13 thomas if ((*blob)->read_buf == NULL) {
933 b61ceafc 2022-10-13 thomas err = got_error_from_errno("malloc");
934 b61ceafc 2022-10-13 thomas goto done;
937 b61ceafc 2022-10-13 thomas if (ftruncate(outfd, 0L) == -1) {
938 b61ceafc 2022-10-13 thomas err = got_error_from_errno("ftruncate");
939 b61ceafc 2022-10-13 thomas goto done;
941 b61ceafc 2022-10-13 thomas if (lseek(outfd, SEEK_SET, 0) == -1) {
942 b61ceafc 2022-10-13 thomas err = got_error_from_errno("lseek");
943 b61ceafc 2022-10-13 thomas goto done;
946 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
947 b61ceafc 2022-10-13 thomas if (err == NULL) {
948 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
950 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
951 b61ceafc 2022-10-13 thomas packidx->path_packidx);
953 b61ceafc 2022-10-13 thomas goto done;
955 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
956 b61ceafc 2022-10-13 thomas if (pack == NULL) {
957 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
958 b61ceafc 2022-10-13 thomas packidx);
960 b61ceafc 2022-10-13 thomas goto done;
962 b61ceafc 2022-10-13 thomas err = read_packed_blob_privsep(&outbuf, &size, &hdrlen, outfd,
963 b61ceafc 2022-10-13 thomas pack, packidx, idx, id);
964 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
965 b61ceafc 2022-10-13 thomas int infd;
967 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&infd, id, repo);
969 b61ceafc 2022-10-13 thomas goto done;
970 b61ceafc 2022-10-13 thomas err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
971 b61ceafc 2022-10-13 thomas id, repo);
974 b61ceafc 2022-10-13 thomas goto done;
976 b61ceafc 2022-10-13 thomas if (hdrlen > size) {
977 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_BAD_OBJ_HDR);
978 b61ceafc 2022-10-13 thomas goto done;
981 b61ceafc 2022-10-13 thomas if (outbuf) {
982 b61ceafc 2022-10-13 thomas (*blob)->f = fmemopen(outbuf, size, "rb");
983 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
984 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fmemopen");
985 b61ceafc 2022-10-13 thomas free(outbuf);
986 b61ceafc 2022-10-13 thomas goto done;
988 b61ceafc 2022-10-13 thomas (*blob)->data = outbuf;
990 b61ceafc 2022-10-13 thomas if (fstat(outfd, &sb) == -1) {
991 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fstat");
992 b61ceafc 2022-10-13 thomas goto done;
995 b61ceafc 2022-10-13 thomas if (sb.st_size != size) {
996 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_PRIVSEP_LEN);
997 b61ceafc 2022-10-13 thomas goto done;
1000 b61ceafc 2022-10-13 thomas dfd = dup(outfd);
1001 b61ceafc 2022-10-13 thomas if (dfd == -1) {
1002 b61ceafc 2022-10-13 thomas err = got_error_from_errno("dup");
1003 b61ceafc 2022-10-13 thomas goto done;
1006 b61ceafc 2022-10-13 thomas (*blob)->f = fdopen(dfd, "rb");
1007 b61ceafc 2022-10-13 thomas if ((*blob)->f == NULL) {
1008 b61ceafc 2022-10-13 thomas err = got_error_from_errno("fdopen");
1009 b61ceafc 2022-10-13 thomas close(dfd);
1010 b61ceafc 2022-10-13 thomas dfd = -1;
1011 b61ceafc 2022-10-13 thomas goto done;
1015 b61ceafc 2022-10-13 thomas (*blob)->hdrlen = hdrlen;
1016 b61ceafc 2022-10-13 thomas (*blob)->blocksize = blocksize;
1017 5b289346 2023-02-17 thomas memcpy(&(*blob)->id, id, sizeof(*id));
1020 b61ceafc 2022-10-13 thomas free(path_packfile);
1021 b61ceafc 2022-10-13 thomas if (err) {
1022 b61ceafc 2022-10-13 thomas if (*blob) {
1023 b61ceafc 2022-10-13 thomas got_object_blob_close(*blob);
1024 b61ceafc 2022-10-13 thomas *blob = NULL;
1027 b61ceafc 2022-10-13 thomas return err;
1030 b61ceafc 2022-10-13 thomas const struct got_error *
1031 b61ceafc 2022-10-13 thomas got_object_open_as_blob(struct got_blob_object **blob,
1032 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id, size_t blocksize,
1033 b61ceafc 2022-10-13 thomas int outfd)
1035 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, id, blocksize, outfd);
1038 b61ceafc 2022-10-13 thomas const struct got_error *
1039 b61ceafc 2022-10-13 thomas got_object_blob_open(struct got_blob_object **blob,
1040 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj, size_t blocksize,
1041 b61ceafc 2022-10-13 thomas int outfd)
1043 b61ceafc 2022-10-13 thomas return open_blob(blob, repo, got_object_get_id(obj), blocksize, outfd);
1046 b61ceafc 2022-10-13 thomas static const struct got_error *
1047 b61ceafc 2022-10-13 thomas request_packed_tag(struct got_tag_object **tag, struct got_pack *pack,
1048 b61ceafc 2022-10-13 thomas int pack_idx, struct got_object_id *id)
1050 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1052 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(pack->privsep_child->ibuf, -1, id,
1053 b61ceafc 2022-10-13 thomas pack_idx);
1054 b61ceafc 2022-10-13 thomas if (err)
1055 b61ceafc 2022-10-13 thomas return err;
1057 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, pack->privsep_child->ibuf);
1060 b61ceafc 2022-10-13 thomas static const struct got_error *
1061 b61ceafc 2022-10-13 thomas read_packed_tag_privsep(struct got_tag_object **tag,
1062 b61ceafc 2022-10-13 thomas struct got_pack *pack, struct got_packidx *packidx, int idx,
1063 b61ceafc 2022-10-13 thomas struct got_object_id *id)
1065 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1067 b61ceafc 2022-10-13 thomas if (pack->privsep_child)
1068 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1070 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1071 b61ceafc 2022-10-13 thomas if (err)
1072 b61ceafc 2022-10-13 thomas return err;
1074 b61ceafc 2022-10-13 thomas return request_packed_tag(tag, pack, idx, id);
1077 b61ceafc 2022-10-13 thomas static const struct got_error *
1078 b61ceafc 2022-10-13 thomas request_tag(struct got_tag_object **tag, struct got_repository *repo,
1079 b61ceafc 2022-10-13 thomas int fd, struct got_object_id *id)
1081 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1082 b61ceafc 2022-10-13 thomas struct imsgbuf *ibuf;
1084 b61ceafc 2022-10-13 thomas ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].ibuf;
1086 b61ceafc 2022-10-13 thomas err = got_privsep_send_tag_req(ibuf, fd, id, -1);
1087 b61ceafc 2022-10-13 thomas if (err)
1088 b61ceafc 2022-10-13 thomas return err;
1090 b61ceafc 2022-10-13 thomas return got_privsep_recv_tag(tag, ibuf);
1093 b61ceafc 2022-10-13 thomas static const struct got_error *
1094 b61ceafc 2022-10-13 thomas read_tag_privsep(struct got_tag_object **tag, int obj_fd,
1095 b61ceafc 2022-10-13 thomas struct got_object_id *id, struct got_repository *repo)
1097 b61ceafc 2022-10-13 thomas const struct got_error *err;
1099 b61ceafc 2022-10-13 thomas if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd != -1)
1100 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1102 54c22772 2022-10-13 thomas err = start_child(repo, GOT_REPO_PRIVSEP_CHILD_TAG);
1103 54c22772 2022-10-13 thomas if (err)
1104 b61ceafc 2022-10-13 thomas return err;
1106 b61ceafc 2022-10-13 thomas return request_tag(tag, repo, obj_fd, id);
1109 b61ceafc 2022-10-13 thomas static const struct got_error *
1110 b61ceafc 2022-10-13 thomas open_tag(struct got_tag_object **tag, struct got_repository *repo,
1111 b61ceafc 2022-10-13 thomas struct got_object_id *id, int check_cache)
1113 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1114 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1115 b61ceafc 2022-10-13 thomas int idx;
1116 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1117 b61ceafc 2022-10-13 thomas struct got_object *obj = NULL;
1118 b61ceafc 2022-10-13 thomas int obj_type = GOT_OBJ_TYPE_ANY;
1120 b61ceafc 2022-10-13 thomas if (check_cache) {
1121 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1122 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1123 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1124 b61ceafc 2022-10-13 thomas return NULL;
1127 b61ceafc 2022-10-13 thomas *tag = NULL;
1129 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, id);
1130 b61ceafc 2022-10-13 thomas if (err == NULL) {
1131 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1133 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1134 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1135 b61ceafc 2022-10-13 thomas if (err)
1136 b61ceafc 2022-10-13 thomas return err;
1138 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1139 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1140 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile,
1141 b61ceafc 2022-10-13 thomas packidx);
1142 b61ceafc 2022-10-13 thomas if (err)
1143 b61ceafc 2022-10-13 thomas goto done;
1146 b61ceafc 2022-10-13 thomas /* Beware of "lightweight" tags: Check object type first. */
1147 b61ceafc 2022-10-13 thomas err = read_packed_object_privsep(&obj, repo, pack, packidx,
1148 b61ceafc 2022-10-13 thomas idx, id);
1149 b61ceafc 2022-10-13 thomas if (err)
1150 b61ceafc 2022-10-13 thomas goto done;
1151 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1152 b61ceafc 2022-10-13 thomas got_object_close(obj);
1153 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG) {
1154 b61ceafc 2022-10-13 thomas err = got_error(GOT_ERR_OBJ_TYPE);
1155 b61ceafc 2022-10-13 thomas goto done;
1157 b61ceafc 2022-10-13 thomas err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
1158 b61ceafc 2022-10-13 thomas } else if (err->code == GOT_ERR_NO_OBJ) {
1161 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1162 b61ceafc 2022-10-13 thomas if (err)
1163 b61ceafc 2022-10-13 thomas return err;
1164 b61ceafc 2022-10-13 thomas err = got_object_read_header_privsep(&obj, id, repo, fd);
1165 b61ceafc 2022-10-13 thomas if (err)
1166 b61ceafc 2022-10-13 thomas return err;
1167 b61ceafc 2022-10-13 thomas obj_type = obj->type;
1168 b61ceafc 2022-10-13 thomas got_object_close(obj);
1169 b61ceafc 2022-10-13 thomas if (obj_type != GOT_OBJ_TYPE_TAG)
1170 b61ceafc 2022-10-13 thomas return got_error(GOT_ERR_OBJ_TYPE);
1172 b61ceafc 2022-10-13 thomas err = got_object_open_loose_fd(&fd, id, repo);
1173 b61ceafc 2022-10-13 thomas if (err)
1174 b61ceafc 2022-10-13 thomas return err;
1175 b61ceafc 2022-10-13 thomas err = read_tag_privsep(tag, fd, id, repo);
1178 b61ceafc 2022-10-13 thomas if (err == NULL) {
1179 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1180 b61ceafc 2022-10-13 thomas err = got_repo_cache_tag(repo, id, *tag);
1183 b61ceafc 2022-10-13 thomas free(path_packfile);
1184 b61ceafc 2022-10-13 thomas return err;
1187 b61ceafc 2022-10-13 thomas const struct got_error *
1188 b61ceafc 2022-10-13 thomas got_object_open_as_tag(struct got_tag_object **tag,
1189 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object_id *id)
1191 b61ceafc 2022-10-13 thomas *tag = got_repo_get_cached_tag(repo, id);
1192 b61ceafc 2022-10-13 thomas if (*tag != NULL) {
1193 b61ceafc 2022-10-13 thomas (*tag)->refcnt++;
1194 b61ceafc 2022-10-13 thomas return NULL;
1197 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, id, 0);
1200 b61ceafc 2022-10-13 thomas const struct got_error *
1201 b61ceafc 2022-10-13 thomas got_object_tag_open(struct got_tag_object **tag,
1202 b61ceafc 2022-10-13 thomas struct got_repository *repo, struct got_object *obj)
1204 b61ceafc 2022-10-13 thomas return open_tag(tag, repo, got_object_get_id(obj), 1);
1207 b61ceafc 2022-10-13 thomas const struct got_error *
1208 b61ceafc 2022-10-13 thomas got_traverse_packed_commits(struct got_object_id_queue *traversed_commits,
1209 b61ceafc 2022-10-13 thomas struct got_object_id *commit_id, const char *path,
1210 b61ceafc 2022-10-13 thomas struct got_repository *repo)
1212 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1213 b61ceafc 2022-10-13 thomas struct got_pack *pack = NULL;
1214 b61ceafc 2022-10-13 thomas struct got_packidx *packidx = NULL;
1215 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1216 b61ceafc 2022-10-13 thomas struct got_commit_object *changed_commit = NULL;
1217 f8c03d02 2024-03-30 thomas struct got_object_qid *changed_commit_qid = NULL;
1218 b61ceafc 2022-10-13 thomas int idx;
1220 b61ceafc 2022-10-13 thomas err = got_repo_search_packidx(&packidx, &idx, repo, commit_id);
1221 b61ceafc 2022-10-13 thomas if (err) {
1222 b61ceafc 2022-10-13 thomas if (err->code != GOT_ERR_NO_OBJ)
1223 b61ceafc 2022-10-13 thomas return err;
1224 b61ceafc 2022-10-13 thomas return NULL;
1227 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1228 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1229 b61ceafc 2022-10-13 thomas if (err)
1230 b61ceafc 2022-10-13 thomas return err;
1232 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1233 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1234 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1235 b61ceafc 2022-10-13 thomas if (err)
1236 b61ceafc 2022-10-13 thomas goto done;
1239 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1240 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1241 b61ceafc 2022-10-13 thomas if (err)
1242 b61ceafc 2022-10-13 thomas goto done;
1245 b61ceafc 2022-10-13 thomas err = got_privsep_send_commit_traversal_request(
1246 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, commit_id, idx, path);
1247 b61ceafc 2022-10-13 thomas if (err)
1248 b61ceafc 2022-10-13 thomas goto done;
1250 b61ceafc 2022-10-13 thomas err = got_privsep_recv_traversed_commits(&changed_commit,
1251 f8c03d02 2024-03-30 thomas traversed_commits, pack->privsep_child->ibuf);
1252 b61ceafc 2022-10-13 thomas if (err)
1253 b61ceafc 2022-10-13 thomas goto done;
1255 b61ceafc 2022-10-13 thomas if (changed_commit) {
1257 b61ceafc 2022-10-13 thomas * Cache the commit in which the path was changed.
1258 b61ceafc 2022-10-13 thomas * This commit might be opened again soon.
1260 b61ceafc 2022-10-13 thomas changed_commit->refcnt++;
1261 f8c03d02 2024-03-30 thomas changed_commit_qid = STAILQ_LAST(traversed_commits, got_object_qid, entry);
1262 f8c03d02 2024-03-30 thomas err = got_repo_cache_commit(repo, &changed_commit_qid->id,
1263 b61ceafc 2022-10-13 thomas changed_commit);
1264 b61ceafc 2022-10-13 thomas got_object_commit_close(changed_commit);
1267 b61ceafc 2022-10-13 thomas free(path_packfile);
1268 b61ceafc 2022-10-13 thomas return err;
1271 b61ceafc 2022-10-13 thomas const struct got_error *
1272 b61ceafc 2022-10-13 thomas got_object_enumerate(int *found_all_objects,
1273 b61ceafc 2022-10-13 thomas got_object_enumerate_commit_cb cb_commit,
1274 b61ceafc 2022-10-13 thomas got_object_enumerate_tree_cb cb_tree, void *cb_arg,
1275 b61ceafc 2022-10-13 thomas struct got_object_id **ours, int nours,
1276 b61ceafc 2022-10-13 thomas struct got_object_id **theirs, int ntheirs,
1277 b61ceafc 2022-10-13 thomas struct got_packidx *packidx, struct got_repository *repo)
1279 b61ceafc 2022-10-13 thomas const struct got_error *err = NULL;
1280 b61ceafc 2022-10-13 thomas struct got_pack *pack;
1281 b61ceafc 2022-10-13 thomas char *path_packfile = NULL;
1283 b61ceafc 2022-10-13 thomas err = got_packidx_get_packfile_path(&path_packfile,
1284 b61ceafc 2022-10-13 thomas packidx->path_packidx);
1285 b61ceafc 2022-10-13 thomas if (err)
1286 b61ceafc 2022-10-13 thomas return err;
1288 b61ceafc 2022-10-13 thomas pack = got_repo_get_cached_pack(repo, path_packfile);
1289 b61ceafc 2022-10-13 thomas if (pack == NULL) {
1290 b61ceafc 2022-10-13 thomas err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
1291 b61ceafc 2022-10-13 thomas if (err)
1292 b61ceafc 2022-10-13 thomas goto done;
1295 b61ceafc 2022-10-13 thomas if (pack->privsep_child == NULL) {
1296 b61ceafc 2022-10-13 thomas err = got_pack_start_privsep_child(pack, packidx);
1297 b61ceafc 2022-10-13 thomas if (err)
1298 b61ceafc 2022-10-13 thomas goto done;
1301 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_enumeration_request(
1302 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf);
1303 b61ceafc 2022-10-13 thomas if (err)
1304 b61ceafc 2022-10-13 thomas goto done;
1306 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1307 b61ceafc 2022-10-13 thomas ours, nours);
1308 b61ceafc 2022-10-13 thomas if (err)
1309 b61ceafc 2022-10-13 thomas goto done;
1310 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1311 b61ceafc 2022-10-13 thomas if (err)
1312 b61ceafc 2022-10-13 thomas goto done;
1314 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
1315 b61ceafc 2022-10-13 thomas theirs, ntheirs);
1316 b61ceafc 2022-10-13 thomas if (err)
1317 b61ceafc 2022-10-13 thomas goto done;
1318 b61ceafc 2022-10-13 thomas err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
1319 b61ceafc 2022-10-13 thomas if (err)
1320 b61ceafc 2022-10-13 thomas goto done;
1322 b61ceafc 2022-10-13 thomas err = got_privsep_recv_enumerated_objects(found_all_objects,
1323 b61ceafc 2022-10-13 thomas pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo);
1325 b61ceafc 2022-10-13 thomas free(path_packfile);
1326 b61ceafc 2022-10-13 thomas return err;