2 * Copyright (c) 2018, 2019 Ori Bernstein <ori@eigenstate.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <sys/socket.h>
23 #include <sys/syslimits.h>
24 #include <sys/resource.h>
40 #include "got_error.h"
41 #include "got_reference.h"
42 #include "got_repository.h"
44 #include "got_cancel.h"
45 #include "got_worktree.h"
46 #include "got_object.h"
48 #include "got_lib_delta.h"
49 #include "got_lib_inflate.h"
50 #include "got_lib_object.h"
51 #include "got_lib_object_parse.h"
52 #include "got_lib_object_create.h"
53 #include "got_lib_pack.h"
54 #include "got_lib_sha1.h"
55 #include "got_lib_privsep.h"
56 #include "got_lib_object_cache.h"
57 #include "got_lib_repository.h"
60 hassuffix(char *base, char *suf)
66 if(ns <= nb && strcmp(base + (nb - ns), suf) == 0)
72 got_make_index_path(char *idxpath, size_t idxpathsz, char *path)
77 if(hassuffix(path, ".pack"))
78 len -= strlen(".pack");
79 if (strlcpy(idxpath, path, idxpathsz) >= idxpathsz)
81 if (strlcpy(idxpath + len, ".idx", idxpathsz - len) >= idxpathsz - len)
86 const struct got_error*
87 got_index_pack(char *path)
90 char idxpath[PATH_MAX];
92 got_make_index_path(idxpath, sizeof(idxpath), path);
93 printf("index path %s\n", idxpath);
94 if ((fd = open(path)) == -1)
95 return got_error_from_errno("open pack");
99 return got_error_from_errno("fork");
101 got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_INDEX_PACK, ".");
103 if (close(imsg_fds[1]) != 0)
104 return got_error_from_errno("close");
105 err = got_privsep_send_index_pack_req(&ibuf, fetchfd);