2 f7d653fc 2023-07-09 op * Copyright (c) 2023 Omar Polo <op@openbsd.org>
4 f7d653fc 2023-07-09 op * Permission to use, copy, modify, and distribute this software for any
5 f7d653fc 2023-07-09 op * purpose with or without fee is hereby granted, provided that the above
6 f7d653fc 2023-07-09 op * copyright notice and this permission notice appear in all copies.
8 f7d653fc 2023-07-09 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 f7d653fc 2023-07-09 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 f7d653fc 2023-07-09 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 f7d653fc 2023-07-09 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 f7d653fc 2023-07-09 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 f7d653fc 2023-07-09 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 f7d653fc 2023-07-09 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 f7d653fc 2023-07-09 op #include <sys/queue.h>
18 f7d653fc 2023-07-09 op #include <sys/socket.h>
19 f7d653fc 2023-07-09 op #include <sys/stat.h>
20 f7d653fc 2023-07-09 op #include <sys/time.h>
21 f7d653fc 2023-07-09 op #include <sys/tree.h>
22 f7d653fc 2023-07-09 op #include <sys/types.h>
23 f7d653fc 2023-07-09 op #include <sys/uio.h>
24 f7d653fc 2023-07-09 op #include <sys/wait.h>
26 f7d653fc 2023-07-09 op #include <endian.h>
27 f7d653fc 2023-07-09 op #include <limits.h>
28 f7d653fc 2023-07-09 op #include <sha1.h>
29 f7d653fc 2023-07-09 op #include <sha2.h>
30 f7d653fc 2023-07-09 op #include <stdint.h>
31 f7d653fc 2023-07-09 op #include <stdio.h>
32 f7d653fc 2023-07-09 op #include <stdlib.h>
33 f7d653fc 2023-07-09 op #include <string.h>
34 f7d653fc 2023-07-09 op #include <unistd.h>
35 f7d653fc 2023-07-09 op #include <imsg.h>
37 f7d653fc 2023-07-09 op #include "got_error.h"
38 f7d653fc 2023-07-09 op #include "got_cancel.h"
39 f7d653fc 2023-07-09 op #include "got_object.h"
40 f7d653fc 2023-07-09 op #include "got_opentemp.h"
41 f7d653fc 2023-07-09 op #include "got_path.h"
42 f7d653fc 2023-07-09 op #include "got_reference.h"
43 f7d653fc 2023-07-09 op #include "got_repository.h"
44 f7d653fc 2023-07-09 op #include "got_repository_load.h"
46 f7d653fc 2023-07-09 op #include "got_lib_delta.h"
47 f7d653fc 2023-07-09 op #include "got_lib_hash.h"
48 f7d653fc 2023-07-09 op #include "got_lib_object.h"
49 f7d653fc 2023-07-09 op #include "got_lib_object_cache.h"
50 f7d653fc 2023-07-09 op #include "got_lib_pack.h"
51 f7d653fc 2023-07-09 op #include "got_lib_ratelimit.h"
52 f7d653fc 2023-07-09 op #include "got_lib_repository.h"
53 f7d653fc 2023-07-09 op #include "got_lib_privsep.h"
55 f7d653fc 2023-07-09 op #define GIT_BUNDLE_SIGNATURE_V2 "# v2 git bundle\n"
57 f7d653fc 2023-07-09 op #ifndef nitems
58 f7d653fc 2023-07-09 op #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
61 f7d653fc 2023-07-09 op #ifndef ssizeof
62 f7d653fc 2023-07-09 op #define ssizeof(_x) ((ssize_t)(sizeof(_x)))
65 f7d653fc 2023-07-09 op static const struct got_error *
66 f7d653fc 2023-07-09 op temp_file(int *fd, char **path, const char *ext, struct got_repository *repo)
68 f7d653fc 2023-07-09 op const struct got_error *err;
69 f7d653fc 2023-07-09 op char p[PATH_MAX];
74 f7d653fc 2023-07-09 op r = snprintf(p, sizeof(p), "%s/%s/loading",
75 f7d653fc 2023-07-09 op got_repo_get_path_git_dir(repo), GOT_OBJECTS_PACK_DIR);
76 f7d653fc 2023-07-09 op if (r < 0 || (size_t)r >= sizeof(p))
77 f7d653fc 2023-07-09 op return got_error_from_errno("snprintf");
79 f7d653fc 2023-07-09 op err = got_opentemp_named_fd(path, fd, p, ext);
83 f7d653fc 2023-07-09 op if (fchmod(*fd, GOT_DEFAULT_FILE_MODE) == -1)
84 f7d653fc 2023-07-09 op return got_error_from_errno("fchmod");
89 f7d653fc 2023-07-09 op static const struct got_error *
90 f7d653fc 2023-07-09 op load_report_progress(got_load_progress_cb progress_cb, void *progress_arg,
91 f7d653fc 2023-07-09 op struct got_ratelimit *rl, off_t packsiz, int nobj_total,
92 f7d653fc 2023-07-09 op int nobj_indexed, int nobj_loose, int nobj_resolved)
94 f7d653fc 2023-07-09 op const struct got_error *err;
97 f7d653fc 2023-07-09 op if (progress_cb == NULL)
100 f7d653fc 2023-07-09 op err = got_ratelimit_check(&elapsed, rl);
101 f7d653fc 2023-07-09 op if (err || !elapsed)
104 f7d653fc 2023-07-09 op return progress_cb(progress_arg, packsiz, nobj_total, nobj_indexed,
105 f7d653fc 2023-07-09 op nobj_loose, nobj_resolved);
108 f7d653fc 2023-07-09 op static const struct got_error *
109 f7d653fc 2023-07-09 op copypack(FILE *in, int outfd, off_t *tot,
110 f7d653fc 2023-07-09 op struct got_object_id *id, struct got_ratelimit *rl,
111 f7d653fc 2023-07-09 op got_load_progress_cb progress_cb, void *progress_arg,
112 f7d653fc 2023-07-09 op got_cancel_cb cancel_cb, void *cancel_arg)
114 f7d653fc 2023-07-09 op const struct got_error *err;
115 f7d653fc 2023-07-09 op struct got_hash hash;
116 f7d653fc 2023-07-09 op struct got_object_id expected_id;
117 f7d653fc 2023-07-09 op char buf[BUFSIZ], sha1buf[SHA1_DIGEST_LENGTH];
118 f7d653fc 2023-07-09 op size_t r, sha1buflen = 0;
121 f7d653fc 2023-07-09 op got_hash_init(&hash, GOT_HASH_SHA1);
124 f7d653fc 2023-07-09 op err = cancel_cb(cancel_arg);
128 f7d653fc 2023-07-09 op r = fread(buf, 1, sizeof(buf), in);
133 f7d653fc 2023-07-09 op * An expected SHA1 checksum sits at the end of the
134 f7d653fc 2023-07-09 op * pack file. Since we don't know the file size ahead
135 f7d653fc 2023-07-09 op * of time we have to keep SHA1_DIGEST_LENGTH bytes
136 f7d653fc 2023-07-09 op * buffered and avoid mixing those bytes int our hash
137 f7d653fc 2023-07-09 op * computation until we know for sure that additional
138 f7d653fc 2023-07-09 op * pack file data bytes follow.
140 f7d653fc 2023-07-09 op * We can assume that BUFSIZE is greater than
141 f7d653fc 2023-07-09 op * SHA1_DIGEST_LENGTH and that a short read means that
142 f7d653fc 2023-07-09 op * we've reached EOF.
145 f7d653fc 2023-07-09 op if (r >= sizeof(sha1buf)) {
146 f7d653fc 2023-07-09 op *tot += sha1buflen;
147 f7d653fc 2023-07-09 op got_hash_update(&hash, sha1buf, sha1buflen);
148 f7d653fc 2023-07-09 op if (write(outfd, sha1buf, sha1buflen) == -1)
149 f7d653fc 2023-07-09 op return got_error_from_errno("write");
151 f7d653fc 2023-07-09 op r -= sizeof(sha1buf);
152 f7d653fc 2023-07-09 op memcpy(sha1buf, &buf[r], sizeof(sha1buf));
153 f7d653fc 2023-07-09 op sha1buflen = sizeof(sha1buf);
156 f7d653fc 2023-07-09 op got_hash_update(&hash, buf, r);
157 f7d653fc 2023-07-09 op if (write(outfd, buf, r) == -1)
158 f7d653fc 2023-07-09 op return got_error_from_errno("write");
160 f7d653fc 2023-07-09 op err = load_report_progress(progress_cb, progress_arg,
161 f7d653fc 2023-07-09 op rl, *tot, 0, 0, 0, 0);
168 f7d653fc 2023-07-09 op if (sha1buflen == 0)
169 f7d653fc 2023-07-09 op return got_error(GOT_ERR_BAD_PACKFILE);
171 f7d653fc 2023-07-09 op /* short read, we've reached EOF */
173 f7d653fc 2023-07-09 op got_hash_update(&hash, sha1buf, r);
174 f7d653fc 2023-07-09 op if (write(outfd, sha1buf, r) == -1)
175 f7d653fc 2023-07-09 op return got_error_from_errno("write");
177 f7d653fc 2023-07-09 op memmove(&sha1buf[0], &sha1buf[r], sizeof(sha1buf) - r);
178 f7d653fc 2023-07-09 op memcpy(&sha1buf[sizeof(sha1buf) - r], buf, r);
182 f7d653fc 2023-07-09 op if (sha1buflen == 0)
183 f7d653fc 2023-07-09 op return got_error(GOT_ERR_BAD_PACKFILE);
185 f7d653fc 2023-07-09 op got_hash_final_object_id(&hash, id);
187 f7d653fc 2023-07-09 op /* XXX SHA256 */
188 f7d653fc 2023-07-09 op memset(&expected_id, 0, sizeof(expected_id));
189 f7d653fc 2023-07-09 op memcpy(&expected_id.sha1, sha1buf, sizeof(expected_id.sha1));
191 f7d653fc 2023-07-09 op if (got_object_id_cmp(id, &expected_id) != 0)
192 f7d653fc 2023-07-09 op return got_error(GOT_ERR_PACKIDX_CSUM);
194 f7d653fc 2023-07-09 op /* re-add the expected hash at the end of the pack */
195 f7d653fc 2023-07-09 op if (write(outfd, sha1buf, sizeof(sha1buf)) == -1)
196 f7d653fc 2023-07-09 op return got_error_from_errno("write");
198 f7d653fc 2023-07-09 op *tot += sizeof(sha1buf);
199 f7d653fc 2023-07-09 op err = progress_cb(progress_arg, *tot, 0, 0, 0, 0);
206 f7d653fc 2023-07-09 op const struct got_error *
207 f7d653fc 2023-07-09 op got_repo_load(FILE *in, struct got_pathlist_head *refs_found,
208 f7d653fc 2023-07-09 op struct got_repository *repo, int list_refs_only, int noop,
209 f7d653fc 2023-07-09 op got_load_progress_cb progress_cb, void *progress_arg,
210 f7d653fc 2023-07-09 op got_cancel_cb cancel_cb, void *cancel_arg)
212 f7d653fc 2023-07-09 op const struct got_error *err = NULL;
213 f7d653fc 2023-07-09 op struct got_object_id id;
214 f7d653fc 2023-07-09 op struct got_object *obj;
215 f7d653fc 2023-07-09 op struct got_packfile_hdr pack_hdr;
216 f7d653fc 2023-07-09 op struct got_ratelimit rl;
217 f7d653fc 2023-07-09 op struct imsgbuf idxibuf;
218 f7d653fc 2023-07-09 op const char *repo_path;
219 f7d653fc 2023-07-09 op char *packpath = NULL, *idxpath = NULL;
220 f7d653fc 2023-07-09 op char *tmppackpath = NULL, *tmpidxpath = NULL;
221 f7d653fc 2023-07-09 op int packfd = -1, idxfd = -1;
222 f7d653fc 2023-07-09 op char *spc, *refname, *id_str = NULL;
223 f7d653fc 2023-07-09 op char *line = NULL;
224 f7d653fc 2023-07-09 op size_t linesize = 0;
225 f7d653fc 2023-07-09 op ssize_t linelen;
228 f7d653fc 2023-07-09 op off_t packsiz;
229 f7d653fc 2023-07-09 op int tmpfds[3] = {-1, -1, -1};
230 f7d653fc 2023-07-09 op int imsg_idxfds[2] = {-1, -1};
231 f7d653fc 2023-07-09 op int ch, done, nobj, idxstatus;
232 f7d653fc 2023-07-09 op pid_t idxpid;
234 f7d653fc 2023-07-09 op got_ratelimit_init(&rl, 0, 500);
236 f7d653fc 2023-07-09 op repo_path = got_repo_get_path_git_dir(repo);
238 f7d653fc 2023-07-09 op linelen = getline(&line, &linesize, in);
239 f7d653fc 2023-07-09 op if (linelen == -1) {
240 f7d653fc 2023-07-09 op err = got_ferror(in, GOT_ERR_IO);
244 f7d653fc 2023-07-09 op if (strcmp(line, GIT_BUNDLE_SIGNATURE_V2) != 0) {
245 f7d653fc 2023-07-09 op err = got_error(GOT_ERR_BUNDLE_FORMAT);
249 f7d653fc 2023-07-09 op /* Parse the prerequisite */
251 f7d653fc 2023-07-09 op ch = fgetc(in);
252 f7d653fc 2023-07-09 op if (ch != '-') {
253 f7d653fc 2023-07-09 op if (ch != EOF)
254 f7d653fc 2023-07-09 op ungetc(ch, in);
258 f7d653fc 2023-07-09 op linelen = getline(&line, &linesize, in);
259 f7d653fc 2023-07-09 op if (linelen == -1) {
260 f7d653fc 2023-07-09 op err = got_ferror(in, GOT_ERR_IO);
264 f7d653fc 2023-07-09 op if (line[linelen - 1] == '\n')
265 f7d653fc 2023-07-09 op line[linelen - 1] = '\0';
267 f7d653fc 2023-07-09 op if (!got_parse_object_id(&id, line, GOT_HASH_SHA1)) {
268 f7d653fc 2023-07-09 op err = got_error_path(line, GOT_ERR_BAD_OBJ_ID_STR);
272 f7d653fc 2023-07-09 op err = got_object_open(&obj, repo, &id);
275 f7d653fc 2023-07-09 op got_object_close(obj);
278 f7d653fc 2023-07-09 op /* Read references */
280 f7d653fc 2023-07-09 op struct got_object_id *id;
283 f7d653fc 2023-07-09 op linelen = getline(&line, &linesize, in);
284 f7d653fc 2023-07-09 op if (linelen == -1) {
285 f7d653fc 2023-07-09 op err = got_ferror(in, GOT_ERR_IO);
288 f7d653fc 2023-07-09 op if (line[linelen - 1] == '\n')
289 f7d653fc 2023-07-09 op line[linelen - 1] = '\0';
290 f7d653fc 2023-07-09 op if (*line == '\0')
293 f7d653fc 2023-07-09 op spc = strchr(line, ' ');
294 f7d653fc 2023-07-09 op if (spc == NULL) {
295 f7d653fc 2023-07-09 op err = got_error(GOT_ERR_IO);
300 f7d653fc 2023-07-09 op refname = spc + 1;
301 f7d653fc 2023-07-09 op if (!got_ref_name_is_valid(refname)) {
302 f7d653fc 2023-07-09 op err = got_error(GOT_ERR_BAD_REF_DATA);
306 f7d653fc 2023-07-09 op id = malloc(sizeof(*id));
307 f7d653fc 2023-07-09 op if (id == NULL) {
308 f7d653fc 2023-07-09 op err = got_error_from_errno("malloc");
312 f7d653fc 2023-07-09 op if (!got_parse_object_id(id, line, GOT_HASH_SHA1)) {
314 f7d653fc 2023-07-09 op err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
318 f7d653fc 2023-07-09 op dup = strdup(refname);
319 f7d653fc 2023-07-09 op if (dup == NULL) {
321 f7d653fc 2023-07-09 op err = got_error_from_errno("strdup");
325 f7d653fc 2023-07-09 op err = got_pathlist_append(refs_found, dup, id);
333 f7d653fc 2023-07-09 op if (list_refs_only)
336 f7d653fc 2023-07-09 op err = temp_file(&packfd, &tmppackpath, ".pack", repo);
340 f7d653fc 2023-07-09 op err = temp_file(&idxfd, &tmpidxpath, ".idx", repo);
344 f7d653fc 2023-07-09 op err = copypack(in, packfd, &packsiz, &id, &rl,
345 f7d653fc 2023-07-09 op progress_cb, progress_arg, cancel_cb, cancel_arg);
349 f7d653fc 2023-07-09 op if (lseek(packfd, 0, SEEK_SET) == -1) {
350 f7d653fc 2023-07-09 op err = got_error_from_errno("lseek");
354 f7d653fc 2023-07-09 op /* Safety checks on the pack' content. */
355 f7d653fc 2023-07-09 op if (packsiz <= ssizeof(pack_hdr) + SHA1_DIGEST_LENGTH) {
356 f7d653fc 2023-07-09 op err = got_error_msg(GOT_ERR_BAD_PACKFILE, "short pack file");
360 f7d653fc 2023-07-09 op n = read(packfd, &pack_hdr, ssizeof(pack_hdr));
361 f7d653fc 2023-07-09 op if (n == -1) {
362 f7d653fc 2023-07-09 op err = got_error_from_errno("read");
365 f7d653fc 2023-07-09 op if (n != ssizeof(pack_hdr)) {
366 f7d653fc 2023-07-09 op err = got_error(GOT_ERR_IO);
369 f7d653fc 2023-07-09 op if (pack_hdr.signature != htobe32(GOT_PACKFILE_SIGNATURE)) {
370 f7d653fc 2023-07-09 op err = got_error_msg(GOT_ERR_BAD_PACKFILE,
371 f7d653fc 2023-07-09 op "bad pack file signature");
374 f7d653fc 2023-07-09 op if (pack_hdr.version != htobe32(GOT_PACKFILE_VERSION)) {
375 f7d653fc 2023-07-09 op err = got_error_msg(GOT_ERR_BAD_PACKFILE,
376 f7d653fc 2023-07-09 op "bad pack file version");
379 f7d653fc 2023-07-09 op nobj = be32toh(pack_hdr.nobjects);
380 f7d653fc 2023-07-09 op if (nobj == 0 &&
381 f7d653fc 2023-07-09 op packsiz > ssizeof(pack_hdr) + SHA1_DIGEST_LENGTH) {
382 f7d653fc 2023-07-09 op err = got_error_msg(GOT_ERR_BAD_PACKFILE,
383 f7d653fc 2023-07-09 op "bad pack file with zero objects");
386 f7d653fc 2023-07-09 op if (nobj != 0 &&
387 f7d653fc 2023-07-09 op packsiz <= ssizeof(pack_hdr) + SHA1_DIGEST_LENGTH) {
388 f7d653fc 2023-07-09 op err = got_error_msg(GOT_ERR_BAD_PACKFILE,
389 f7d653fc 2023-07-09 op "empty pack file with non-zero object count");
393 f7d653fc 2023-07-09 op /* nothing to do if there are no objects. */
394 f7d653fc 2023-07-09 op if (nobj == 0)
397 f7d653fc 2023-07-09 op for (i = 0; i < nitems(tmpfds); i++) {
398 f7d653fc 2023-07-09 op tmpfds[i] = got_opentempfd();
399 f7d653fc 2023-07-09 op if (tmpfds[i] == -1) {
400 f7d653fc 2023-07-09 op err = got_error_from_errno("got_opentempfd");
405 f7d653fc 2023-07-09 op if (lseek(packfd, 0, SEEK_SET) == -1) {
406 f7d653fc 2023-07-09 op err = got_error_from_errno("lseek");
410 f7d653fc 2023-07-09 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_idxfds) == -1) {
411 f7d653fc 2023-07-09 op err = got_error_from_errno("socketpair");
414 f7d653fc 2023-07-09 op idxpid = fork();
415 f7d653fc 2023-07-09 op if (idxpid == -1) {
416 f7d653fc 2023-07-09 op err= got_error_from_errno("fork");
418 f7d653fc 2023-07-09 op } else if (idxpid == 0)
419 f7d653fc 2023-07-09 op got_privsep_exec_child(imsg_idxfds,
420 f7d653fc 2023-07-09 op GOT_PATH_PROG_INDEX_PACK, tmppackpath);
421 f7d653fc 2023-07-09 op if (close(imsg_idxfds[1]) == -1) {
422 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
425 f7d653fc 2023-07-09 op imsg_idxfds[1] = -1;
426 f7d653fc 2023-07-09 op imsg_init(&idxibuf, imsg_idxfds[0]);
428 f7d653fc 2023-07-09 op err = got_privsep_send_index_pack_req(&idxibuf, id.sha1, packfd);
433 f7d653fc 2023-07-09 op err = got_privsep_send_index_pack_outfd(&idxibuf, idxfd);
438 f7d653fc 2023-07-09 op for (i = 0; i < nitems(tmpfds); i++) {
439 f7d653fc 2023-07-09 op err = got_privsep_send_tmpfd(&idxibuf, tmpfds[i]);
440 f7d653fc 2023-07-09 op if (err != NULL)
442 f7d653fc 2023-07-09 op tmpfds[i] = -1;
446 f7d653fc 2023-07-09 op while (!done) {
447 f7d653fc 2023-07-09 op int nobj_total, nobj_indexed, nobj_loose, nobj_resolved;
449 f7d653fc 2023-07-09 op err = got_privsep_recv_index_progress(&done, &nobj_total,
450 f7d653fc 2023-07-09 op &nobj_indexed, &nobj_loose, &nobj_resolved, &idxibuf);
453 f7d653fc 2023-07-09 op if (nobj_indexed != 0) {
454 f7d653fc 2023-07-09 op err = load_report_progress(progress_cb, progress_arg,
455 f7d653fc 2023-07-09 op &rl, packsiz, nobj_total, nobj_indexed,
456 f7d653fc 2023-07-09 op nobj_loose, nobj_resolved);
461 f7d653fc 2023-07-09 op if (close(imsg_idxfds[0]) == -1) {
462 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
465 f7d653fc 2023-07-09 op imsg_idxfds[0] = -1;
466 f7d653fc 2023-07-09 op if (waitpid(idxpid, &idxstatus, 0) == -1) {
467 f7d653fc 2023-07-09 op err = got_error_from_errno("waitpid");
474 f7d653fc 2023-07-09 op err = got_object_id_str(&id_str, &id);
478 f7d653fc 2023-07-09 op if (asprintf(&packpath, "%s/%s/pack-%s.pack", repo_path,
479 f7d653fc 2023-07-09 op GOT_OBJECTS_PACK_DIR, id_str) == -1) {
480 f7d653fc 2023-07-09 op err = got_error_from_errno("asprintf");
484 f7d653fc 2023-07-09 op if (asprintf(&idxpath, "%s/%s/pack-%s.idx", repo_path,
485 f7d653fc 2023-07-09 op GOT_OBJECTS_PACK_DIR, id_str) == -1) {
486 f7d653fc 2023-07-09 op err = got_error_from_errno("asprintf");
490 f7d653fc 2023-07-09 op if (rename(tmppackpath, packpath) == -1) {
491 f7d653fc 2023-07-09 op err = got_error_from_errno3("rename", tmppackpath, packpath);
494 f7d653fc 2023-07-09 op free(tmppackpath);
495 f7d653fc 2023-07-09 op tmppackpath = NULL;
497 f7d653fc 2023-07-09 op if (rename(tmpidxpath, idxpath) == -1) {
498 f7d653fc 2023-07-09 op err = got_error_from_errno3("rename", tmpidxpath, idxpath);
501 f7d653fc 2023-07-09 op free(tmpidxpath);
502 f7d653fc 2023-07-09 op tmpidxpath = NULL;
506 f7d653fc 2023-07-09 op free(packpath);
507 f7d653fc 2023-07-09 op free(idxpath);
508 f7d653fc 2023-07-09 op free(id_str);
510 f7d653fc 2023-07-09 op if (tmppackpath && unlink(tmppackpath) == -1 && err == NULL)
511 f7d653fc 2023-07-09 op err = got_error_from_errno2("unlink", tmppackpath);
512 f7d653fc 2023-07-09 op if (packfd != -1 && close(packfd) == -1 && err == NULL)
513 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
514 f7d653fc 2023-07-09 op free(tmppackpath);
516 f7d653fc 2023-07-09 op if (tmpidxpath && unlink(tmpidxpath) == -1 && err == NULL)
517 f7d653fc 2023-07-09 op err = got_error_from_errno2("unlink", tmpidxpath);
518 f7d653fc 2023-07-09 op if (idxfd != -1 && close(idxfd) == -1 && err == NULL)
519 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
520 f7d653fc 2023-07-09 op free(tmpidxpath);
522 f7d653fc 2023-07-09 op if (imsg_idxfds[0] != -1 && close(imsg_idxfds[0]) == -1 && err == NULL)
523 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
524 f7d653fc 2023-07-09 op if (imsg_idxfds[1] != -1 && close(imsg_idxfds[1]) == -1 && err == NULL)
525 f7d653fc 2023-07-09 op err = got_error_from_errno("close");
527 f7d653fc 2023-07-09 op for (i = 0; i < nitems(tmpfds); ++i)
528 f7d653fc 2023-07-09 op if (tmpfds[i] != -1 && close(tmpfds[i]) == -1 && err == NULL)
529 f7d653fc 2023-07-09 op err = got_error_from_errno("close");