commit - 279090e1480dee1b500b53c0c727ac8771e1f840
commit + afa77e037336006a71843ec8523d41f5f1638aaf
blob - 5c2553421bc50539d3a80177ddb039e4d715f2a4
blob + d58bd36e3d935934b4c9b0478cfae78c9ef08de0
--- lib/fetch.c
+++ lib/fetch.c
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)
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);
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;
-
}
blob - b60af9d2e6fe22b7f41fd7338722e30865a82684
blob + 5885ba74e308e577dc5b0e7da458e12336ffa30a
--- lib/privsep.c
+++ lib/privsep.c
if (err)
return err;
if (imsg.hdr.type == GOT_IMSG_FETCH_DONE &&
- imsg.hdr.len - sizeof(imsg.hdr) == SHA1_DIGEST_LENGTH)
- return NULL;
- else
- return got_error(GOT_ERR_PRIVSEP_MSG);
+ imsg.hdr.len - sizeof(imsg.hdr) == SHA1_DIGEST_LENGTH) {
+ memcpy(hash->sha1, imsg.data, SHA1_DIGEST_LENGTH);
+ imsg_free(&imsg);
+ return NULL;
+ }
+
imsg_free(&imsg);
+ return got_error(GOT_ERR_PRIVSEP_MSG);
}