commit - 83b416ed85ff1da32806572f7263afa693b85ac6
commit + fe4e150152f6808ae87ac1507402947703c40870
blob - be04a7dc049d95312f53007d313519f18f5699f5
blob + d1b0036db1f8b8af9c1d3bc185673c5347920b19
--- lib/fetch.c
+++ lib/fetch.c
#include "got_cancel.h"
#include "got_worktree.h"
#include "got_object.h"
+#include "got_opentemp.h"
#include "got_lib_delta.h"
#include "got_lib_inflate.h"
char proto[GOT_PROTOMAX], host[GOT_HOSTMAX], port[GOT_PORTMAX];
char repo[GOT_REPOMAX], path[GOT_PATHMAX];
int imsg_fetchfds[2], imsg_idxfds[2], fetchfd;
- int packfd, npackfd, idxfd, nidxfd, status;
+ int packfd = -1, npackfd, idxfd = -1, nidxfd, status;
struct got_object_id packhash;
const struct got_error *err;
struct imsgbuf ibuf;
pid_t pid;
+ char *packpath = NULL, *idxpath = NULL;
fetchfd = -1;
if (got_parse_uri(uri, proto, host, port, path, repo) == -1)
return got_error_from_errno("enter new repo");
if (mkpath(".git/objects/pack") == -1)
return got_error_from_errno("mkpath");
- packfd = open(".git/objects/pack/fetching.pack", O_CREAT|O_RDWR, 0644);
- if (packfd == -1)
- return got_error_from_errno("open pack");
+ err = got_opentemp_named_fd(&packpath, &packfd,
+ ".git/objects/pack/fetching.pack");
+ if (err)
+ return err;
npackfd = dup(packfd);
if (npackfd == -1)
return got_error_from_errno("dup");
- idxfd = open(".git/objects/pack/fetching.idx", O_CREAT|O_RDWR, 0644);
- if (idxfd == -1)
- return got_error_from_errno("open pack");
+ err = got_opentemp_named_fd(&idxpath, &idxfd,
+ ".git/objects/pack/fetching.idx");
+ if (err)
+ return err;
nidxfd = dup(idxfd);
if (nidxfd == -1)
return got_error_from_errno("dup");
return got_error_from_errno("child exit");
+ free(packpath);
+ free(idxpath);
+
return NULL;
}