Blob


1 /*
2 * Copyright (c) 2019 Ori Bernstein <ori@openbsd.org>
3 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/time.h>
22 #include <sys/stat.h>
24 #include <stdint.h>
25 #include <errno.h>
26 #include <imsg.h>
27 #include <limits.h>
28 #include <signal.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <sha1.h>
34 #include <sha2.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <zlib.h>
38 #include <err.h>
40 #include "got_error.h"
41 #include "got_object.h"
42 #include "got_path.h"
43 #include "got_version.h"
44 #include "got_fetch.h"
45 #include "got_reference.h"
47 #include "got_lib_hash.h"
48 #include "got_lib_delta.h"
49 #include "got_lib_object.h"
50 #include "got_lib_object_parse.h"
51 #include "got_lib_privsep.h"
52 #include "got_lib_pack.h"
53 #include "got_lib_pkt.h"
54 #include "got_lib_gitproto.h"
55 #include "got_lib_ratelimit.h"
56 #include "got_lib_poll.h"
58 #ifndef nitems
59 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
60 #endif
62 struct got_object *indexed;
63 static int chattygot;
65 static const struct got_capability got_capabilities[] = {
66 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
67 { GOT_CAPA_OFS_DELTA, NULL },
68 #if 0
69 { GOT_CAPA_SIDE_BAND_64K, NULL },
70 #endif
71 { GOT_CAPA_REPORT_STATUS, NULL },
72 { GOT_CAPA_DELETE_REFS, NULL },
73 };
75 static const struct got_error *
76 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
77 struct got_ratelimit *rl)
78 {
79 const struct got_error *err = NULL;
80 int elapsed = 0;
82 if (rl) {
83 err = got_ratelimit_check(&elapsed, rl);
84 if (err || !elapsed)
85 return err;
86 }
88 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
89 &bytes, sizeof(bytes)) == -1)
90 return got_error_from_errno(
91 "imsg_compose SEND_UPLOAD_PROGRESS");
93 return got_privsep_flush_imsg(ibuf);
94 }
96 static const struct got_error *
97 send_pack_request(struct imsgbuf *ibuf)
98 {
99 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
100 NULL, 0) == -1)
101 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
102 return got_privsep_flush_imsg(ibuf);
105 static const struct got_error *
106 send_done(struct imsgbuf *ibuf)
108 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
109 return got_error_from_errno("imsg_compose SEND_DONE");
110 return got_privsep_flush_imsg(ibuf);
113 static const struct got_error *
114 recv_packfd(int *packfd, struct imsgbuf *ibuf)
116 const struct got_error *err;
117 struct imsg imsg;
119 *packfd = -1;
121 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
122 if (err)
123 return err;
125 if (imsg.hdr.type == GOT_IMSG_STOP) {
126 err = got_error(GOT_ERR_CANCELLED);
127 goto done;
130 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
131 err = got_error(GOT_ERR_PRIVSEP_MSG);
132 goto done;
135 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
136 err = got_error(GOT_ERR_PRIVSEP_LEN);
137 goto done;
140 *packfd = imsg_get_fd(&imsg);
141 done:
142 imsg_free(&imsg);
143 return err;
146 static const struct got_error *
147 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
149 const struct got_error *err;
150 unsigned char buf[8192];
151 ssize_t r;
152 off_t wtotal = 0;
153 struct got_ratelimit rl;
155 if (lseek(packfd, 0L, SEEK_SET) == -1)
156 return got_error_from_errno("lseek");
158 got_ratelimit_init(&rl, 0, 500);
160 for (;;) {
161 r = read(packfd, buf, sizeof(buf));
162 if (r == -1)
163 return got_error_from_errno("read");
164 if (r == 0)
165 break;
166 err = got_poll_write_full(sendfd, buf, r);
167 if (err)
168 return NULL;
169 wtotal += r;
170 err = send_upload_progress(ibuf, wtotal, &rl);
171 if (err)
172 return err;
175 return send_upload_progress(ibuf, wtotal, NULL);
178 static const struct got_error *
179 send_error(const char *buf, size_t len)
181 static char msg[1024];
182 size_t i;
184 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
185 if (!isprint((unsigned char)buf[i]))
186 return got_error_msg(GOT_ERR_BAD_PACKET,
187 "non-printable error message received from server");
188 msg[i] = buf[i];
190 msg[i] = '\0';
191 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
194 static const struct got_error *
195 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
196 const char *refname)
198 struct ibuf *wbuf;
199 size_t len, reflen = strlen(refname);
201 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
202 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
203 return got_error(GOT_ERR_NO_SPACE);
205 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
206 if (wbuf == NULL)
207 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
209 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
210 if (imsg_add(wbuf, refid, sizeof(*refid)) == -1)
211 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
212 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
213 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
214 if (imsg_add(wbuf, refname, reflen) == -1)
215 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
217 imsg_close(ibuf, wbuf);
218 return got_privsep_flush_imsg(ibuf);
221 static const struct got_error *
222 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
223 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
225 struct ibuf *wbuf;
226 size_t i, len, reflen, errmsglen = 0;
227 struct got_pathlist_entry *pe;
228 int ref_valid = 0;
229 char *eol, *sp;
230 const char *errmsg = "";
232 eol = strchr(refname, '\n');
233 if (eol == NULL) {
234 return got_error_msg(GOT_ERR_BAD_PACKET,
235 "unexpected message from server");
237 *eol = '\0';
239 sp = strchr(refname, ' ');
240 if (sp != NULL) {
241 *sp++ = '\0';
242 errmsg = sp;
243 errmsglen = strlen(errmsg);
245 for (i = 0; i < errmsglen; ++i) {
246 if (!isprint((unsigned char)errmsg[i])) {
247 return got_error_msg(GOT_ERR_BAD_PACKET,
248 "non-printable error message received "
249 "from the server");
254 reflen = strlen(refname);
255 if (!got_ref_name_is_valid(refname)) {
256 return got_error_msg(GOT_ERR_BAD_PACKET,
257 "unexpected message from server");
260 TAILQ_FOREACH(pe, refs, entry) {
261 if (strcmp(refname, pe->path) == 0) {
262 ref_valid = 1;
263 break;
266 if (!ref_valid) {
267 TAILQ_FOREACH(pe, delete_refs, entry) {
268 if (strcmp(refname, pe->path) == 0) {
269 ref_valid = 1;
270 break;
274 if (!ref_valid) {
275 return got_error_msg(GOT_ERR_BAD_PACKET,
276 "unexpected message from server");
279 len = sizeof(struct got_imsg_send_ref_status) + reflen + errmsglen;
280 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
281 return got_error(GOT_ERR_NO_SPACE);
283 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
284 0, 0, len);
285 if (wbuf == NULL)
286 return got_error_from_errno("imsg_create SEND_REF_STATUS");
288 /* Keep in sync with struct got_imsg_send_ref_status definition! */
289 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
290 return got_error_from_errno("imsg_add SEND_REF_STATUS");
291 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
292 return got_error_from_errno("imsg_add SEND_REF_STATUS");
293 if (imsg_add(wbuf, &errmsglen, sizeof(errmsglen)) == -1)
294 return got_error_from_errno("imsg_add SEND_REF_STATUS");
295 if (imsg_add(wbuf, refname, reflen) == -1)
296 return got_error_from_errno("imsg_add SEND_REF_STATUS");
297 if (imsg_add(wbuf, errmsg, errmsglen) == -1)
298 return got_error_from_errno("imsg_add SEND_REF_STATUS");
300 imsg_close(ibuf, wbuf);
301 return got_privsep_flush_imsg(ibuf);
304 static const struct got_error *
305 describe_refchange(int *n, int *sent_my_capabilites,
306 const char *my_capabilities, char *buf, size_t bufsize,
307 const char *refname, const char *old_hashstr, const char *new_hashstr)
309 *n = snprintf(buf, bufsize, "%s %s %s",
310 old_hashstr, new_hashstr, refname);
311 if (*n < 0 || (size_t)*n >= bufsize)
312 return got_error(GOT_ERR_NO_SPACE);
314 /*
315 * We must announce our capabilities along with the first
316 * reference. Unfortunately, the protocol requires an embedded
317 * NUL as a separator between reference name and capabilities,
318 * which we have to deal with here.
319 * It also requires a linefeed for terminating packet data.
320 */
321 if (!*sent_my_capabilites && my_capabilities != NULL) {
322 int m;
323 if (*n >= bufsize - 1)
324 return got_error(GOT_ERR_NO_SPACE);
325 m = snprintf(buf + *n + 1, /* offset after '\0' */
326 bufsize - (*n + 1), "%s\n", my_capabilities);
327 if (m < 0 || *n + m >= bufsize)
328 return got_error(GOT_ERR_NO_SPACE);
329 *n += m;
330 *sent_my_capabilites = 1;
331 } else {
332 *n = strlcat(buf, "\n", bufsize);
333 if (*n >= bufsize)
334 return got_error(GOT_ERR_NO_SPACE);
337 return NULL;
340 static const struct got_error *
341 send_pack(int fd, struct got_pathlist_head *refs,
342 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
344 const struct got_error *err = NULL;
345 char buf[GOT_PKT_MAX];
346 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
347 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
348 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
349 struct got_pathlist_head their_refs;
350 int is_firstpkt = 1;
351 int n, nsent = 0;
352 int packfd = -1;
353 char *id_str = NULL, *refname = NULL;
354 struct got_object_id *id = NULL;
355 char *server_capabilities = NULL, *my_capabilities = NULL;
356 struct got_pathlist_entry *pe;
357 int sent_my_capabilites = 0;
359 TAILQ_INIT(&their_refs);
361 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
362 return got_error(GOT_ERR_SEND_EMPTY);
364 while (1) {
365 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
366 if (err)
367 goto done;
368 if (n == 0)
369 break;
370 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
371 err = send_error(&buf[4], n - 4);
372 goto done;
374 free(id_str);
375 free(refname);
376 err = got_gitproto_parse_refline(&id_str, &refname,
377 &server_capabilities, buf, n);
378 if (err)
379 goto done;
380 if (is_firstpkt) {
381 if (server_capabilities == NULL) {
382 server_capabilities = strdup("");
383 if (server_capabilities == NULL) {
384 err = got_error_from_errno("strdup");
385 goto done;
388 if (chattygot && server_capabilities[0] != '\0')
389 fprintf(stderr, "%s: server capabilities: %s\n",
390 getprogname(), server_capabilities);
391 err = got_gitproto_match_capabilities(&my_capabilities,
392 NULL, server_capabilities, got_capabilities,
393 nitems(got_capabilities));
394 if (err)
395 goto done;
396 if (chattygot)
397 fprintf(stderr, "%s: my capabilities:%s\n",
398 getprogname(),
399 my_capabilities ? my_capabilities : "");
400 is_firstpkt = 0;
402 if (strstr(refname, "^{}")) {
403 if (chattygot) {
404 fprintf(stderr, "%s: ignoring %s\n",
405 getprogname(), refname);
407 continue;
410 id = malloc(sizeof(*id));
411 if (id == NULL) {
412 err = got_error_from_errno("malloc");
413 goto done;
415 if (!got_parse_object_id(id, id_str, GOT_HASH_SHA1)) {
416 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
417 goto done;
419 err = send_their_ref(ibuf, id, refname);
420 if (err)
421 goto done;
423 err = got_pathlist_append(&their_refs, refname, id);
424 if (err)
425 goto done;
427 if (chattygot)
428 fprintf(stderr, "%s: remote has %s %s\n",
429 getprogname(), refname, id_str);
430 free(id_str);
431 id_str = NULL;
432 refname = NULL; /* do not free; owned by their_refs */
433 id = NULL; /* do not free; owned by their_refs */
436 if (!TAILQ_EMPTY(delete_refs)) {
437 if (my_capabilities == NULL ||
438 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
439 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
440 goto done;
444 TAILQ_FOREACH(pe, delete_refs, entry) {
445 const char *refname = pe->path;
446 struct got_pathlist_entry *their_pe;
447 struct got_object_id *their_id = NULL;
449 TAILQ_FOREACH(their_pe, &their_refs, entry) {
450 const char *their_refname = their_pe->path;
451 if (got_path_cmp(refname, their_refname,
452 strlen(refname), strlen(their_refname)) == 0) {
453 their_id = their_pe->data;
454 break;
457 if (their_id == NULL) {
458 err = got_error_fmt(GOT_ERR_NOT_REF,
459 "%s does not exist in remote repository",
460 refname);
461 goto done;
464 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
465 sizeof(old_hashstr));
466 got_sha1_digest_to_str(zero_id, new_hashstr,
467 sizeof(new_hashstr));
468 err = describe_refchange(&n, &sent_my_capabilites,
469 my_capabilities, buf, sizeof(buf), refname,
470 old_hashstr, new_hashstr);
471 if (err)
472 goto done;
473 err = got_pkt_writepkt(fd, buf, n, chattygot);
474 if (err)
475 goto done;
476 if (chattygot) {
477 fprintf(stderr, "%s: deleting %s %s\n",
478 getprogname(), refname, old_hashstr);
480 nsent++;
483 TAILQ_FOREACH(pe, refs, entry) {
484 const char *refname = pe->path;
485 struct got_object_id *id = pe->data;
486 struct got_object_id *their_id = NULL;
487 struct got_pathlist_entry *their_pe;
489 TAILQ_FOREACH(their_pe, &their_refs, entry) {
490 const char *their_refname = their_pe->path;
491 if (got_path_cmp(refname, their_refname,
492 strlen(refname), strlen(their_refname)) == 0) {
493 their_id = their_pe->data;
494 break;
497 if (their_id) {
498 if (got_object_id_cmp(id, their_id) == 0) {
499 if (chattygot) {
500 fprintf(stderr,
501 "%s: no change for %s\n",
502 getprogname(), refname);
504 continue;
506 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
507 sizeof(old_hashstr));
508 } else {
509 got_sha1_digest_to_str(zero_id, old_hashstr,
510 sizeof(old_hashstr));
512 got_sha1_digest_to_str(id->sha1, new_hashstr,
513 sizeof(new_hashstr));
514 err = describe_refchange(&n, &sent_my_capabilites,
515 my_capabilities, buf, sizeof(buf), refname,
516 old_hashstr, new_hashstr);
517 if (err)
518 goto done;
519 err = got_pkt_writepkt(fd, buf, n, chattygot);
520 if (err)
521 goto done;
522 if (chattygot) {
523 if (their_id) {
524 fprintf(stderr, "%s: updating %s %s -> %s\n",
525 getprogname(), refname, old_hashstr,
526 new_hashstr);
527 } else {
528 fprintf(stderr, "%s: creating %s %s\n",
529 getprogname(), refname, new_hashstr);
532 nsent++;
534 err = got_pkt_flushpkt(fd, chattygot);
535 if (err)
536 goto done;
538 err = send_pack_request(ibuf);
539 if (err)
540 goto done;
542 err = recv_packfd(&packfd, ibuf);
543 if (err)
544 goto done;
546 if (packfd != -1) {
547 err = send_pack_file(fd, packfd, ibuf);
548 if (err)
549 goto done;
552 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
553 if (err)
554 goto done;
555 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
556 err = send_error(&buf[4], n - 4);
557 goto done;
558 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
559 err = got_error_msg(GOT_ERR_BAD_PACKET,
560 "unexpected message from server");
561 goto done;
564 while (nsent > 0) {
565 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
566 if (err)
567 goto done;
568 if (n < 3) {
569 err = got_error_msg(GOT_ERR_BAD_PACKET,
570 "unexpected message from server");
571 goto done;
572 } else if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
573 err = send_error(&buf[4], n - 4);
574 goto done;
575 } else if (strncmp(buf, "ok ", 3) == 0) {
576 err = send_ref_status(ibuf, buf + 3, 1,
577 refs, delete_refs);
578 if (err)
579 goto done;
580 } else if (strncmp(buf, "ng ", 3) == 0) {
581 err = send_ref_status(ibuf, buf + 3, 0,
582 refs, delete_refs);
583 if (err)
584 goto done;
585 } else {
586 err = got_error_msg(GOT_ERR_BAD_PACKET,
587 "unexpected message from server");
588 goto done;
590 nsent--;
593 err = send_done(ibuf);
594 done:
595 got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_ALL);
596 free(id_str);
597 free(id);
598 free(refname);
599 free(server_capabilities);
600 return err;
603 int
604 main(int argc, char **argv)
606 const struct got_error *err = NULL;
607 int sendfd = -1;
608 struct imsgbuf ibuf;
609 struct imsg imsg;
610 struct got_pathlist_head refs;
611 struct got_pathlist_head delete_refs;
612 struct got_imsg_send_request send_req;
613 struct got_imsg_send_ref href;
614 size_t datalen, i;
615 #if 0
616 static int attached;
617 while (!attached)
618 sleep (1);
619 #endif
621 TAILQ_INIT(&refs);
622 TAILQ_INIT(&delete_refs);
624 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
625 #ifndef PROFILE
626 /* revoke access to most system calls */
627 if (pledge("stdio recvfd", NULL) == -1) {
628 err = got_error_from_errno("pledge");
629 got_privsep_send_error(&ibuf, err);
630 return 1;
632 #endif
633 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
634 if (err->code == GOT_ERR_PRIVSEP_PIPE)
635 err = NULL;
636 goto done;
638 if (imsg.hdr.type == GOT_IMSG_STOP)
639 goto done;
640 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
641 err = got_error(GOT_ERR_PRIVSEP_MSG);
642 goto done;
644 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
645 if (datalen < sizeof(send_req)) {
646 err = got_error(GOT_ERR_PRIVSEP_LEN);
647 goto done;
649 memcpy(&send_req, imsg.data, sizeof(send_req));
650 sendfd = imsg_get_fd(&imsg);
651 imsg_free(&imsg);
653 if (send_req.verbosity > 0)
654 chattygot += send_req.verbosity;
656 for (i = 0; i < send_req.nrefs; i++) {
657 struct got_object_id *id;
658 char *refname;
660 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
661 if (err->code == GOT_ERR_PRIVSEP_PIPE)
662 err = NULL;
663 goto done;
665 if (imsg.hdr.type == GOT_IMSG_STOP)
666 goto done;
667 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
668 err = got_error(GOT_ERR_PRIVSEP_MSG);
669 goto done;
671 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
672 if (datalen < sizeof(href)) {
673 err = got_error(GOT_ERR_PRIVSEP_LEN);
674 goto done;
676 memcpy(&href, imsg.data, sizeof(href));
677 if (datalen - sizeof(href) < href.name_len) {
678 err = got_error(GOT_ERR_PRIVSEP_LEN);
679 goto done;
681 refname = malloc(href.name_len + 1);
682 if (refname == NULL) {
683 err = got_error_from_errno("malloc");
684 goto done;
686 memcpy(refname, imsg.data + sizeof(href), href.name_len);
687 refname[href.name_len] = '\0';
689 /*
690 * Prevent sending of references that won't make any
691 * sense outside the local repository's context.
692 */
693 if (strncmp(refname, "refs/got/", 9) == 0 ||
694 strncmp(refname, "refs/remotes/", 13) == 0) {
695 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
696 "%s", refname);
697 goto done;
700 id = malloc(sizeof(*id));
701 if (id == NULL) {
702 free(refname);
703 err = got_error_from_errno("malloc");
704 goto done;
706 memcpy(id, &href.id, sizeof(*id));
707 if (href.delete)
708 err = got_pathlist_append(&delete_refs, refname, id);
709 else
710 err = got_pathlist_append(&refs, refname, id);
711 if (err) {
712 free(refname);
713 free(id);
714 goto done;
717 imsg_free(&imsg);
720 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
721 done:
722 got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
723 got_pathlist_free(&delete_refs, GOT_PATHLIST_FREE_ALL);
724 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
725 err = got_error_from_errno("close");
726 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
727 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
728 got_privsep_send_error(&ibuf, err);
731 exit(0);