actually create a pack and an index in the right place
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/lib/fetch.c b/lib/fetch.c
index 5c25534..d58bd36 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -258,7 +258,8 @@ got_clone(char *uri, char *branch_filter, char *destdir)
const struct got_error *err;
struct imsgbuf ibuf;
pid_t pid;
- char *packpath = NULL, *idxpath = NULL, *default_destdir = NULL;
+ char *tmppackpath = NULL, *tmpidxpath = NULL, *default_destdir = NULL;
+ char *packpath = NULL, *idxpath = NULL, *id_str = NULL;
fetchfd = -1;
if (got_parse_uri(uri, proto, host, port, path, repo) == -1)
@@ -272,17 +273,17 @@ got_clone(char *uri, char *branch_filter, char *destdir)
return err;
if (chdir(destdir ? destdir : default_destdir))
return got_error_from_errno("enter new repo");
- if (mkpath(".git/objects/pack") == -1)
+ if (mkpath("objects/pack") == -1)
return got_error_from_errno("mkpath");
- err = got_opentemp_named_fd(&packpath, &packfd,
- ".git/objects/pack/fetching.pack");
+ err = got_opentemp_named_fd(&tmppackpath, &packfd,
+ "objects/pack/fetching.pack");
if (err)
return err;
npackfd = dup(packfd);
if (npackfd == -1)
return got_error_from_errno("dup");
- err = got_opentemp_named_fd(&idxpath, &idxfd,
- ".git/objects/pack/fetching.idx");
+ err = got_opentemp_named_fd(&tmpidxpath, &idxfd,
+ "objects/pack/fetching.idx");
if (err)
return err;
nidxfd = dup(idxfd);
@@ -354,11 +355,25 @@ got_clone(char *uri, char *branch_filter, char *destdir)
if (waitpid(pid, &status, 0) == -1)
return got_error_from_errno("child exit");
+ err = got_object_id_str(&id_str, &packhash);
+ if (err)
+ return err;
+ if (asprintf(&packpath, "objects/pack/pack-%s.pack", id_str) == -1)
+ return got_error_from_errno("asprintf");
- free(packpath);
+ if (asprintf(&idxpath, "objects/pack/pack-%s.idx", id_str) == -1)
+ return got_error_from_errno("asprintf");
+
+ if (rename(tmppackpath, packpath) == -1)
+ return got_error_from_errno3("rename", tmppackpath, packpath);
+ if (rename(tmpidxpath, idxpath) == -1)
+ return got_error_from_errno3("rename", tmpidxpath, idxpath);
+
+ free(tmppackpath);
+ free(tmpidxpath);
free(idxpath);
+ free(packpath);
free(default_destdir);
return NULL;
-
}
diff --git a/lib/privsep.c b/lib/privsep.c
index b60af9d..5885ba7 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -437,11 +437,14 @@ got_privsep_wait_fetch_done(struct imsgbuf *ibuf, struct got_object_id *hash)
if (err)
return err;
if (imsg.hdr.type == GOT_IMSG_FETCH_DONE &&
- imsg.hdr.len - sizeof(imsg.hdr) == SHA1_DIGEST_LENGTH)
+ imsg.hdr.len - sizeof(imsg.hdr) == SHA1_DIGEST_LENGTH) {
+ memcpy(hash->sha1, imsg.data, SHA1_DIGEST_LENGTH);
+ imsg_free(&imsg);
return NULL;
- else
- return got_error(GOT_ERR_PRIVSEP_MSG);
+ }
+
imsg_free(&imsg);
+ return got_error(GOT_ERR_PRIVSEP_MSG);
}