summaryrefslogtreecommitdiff
path: root/http-fetch.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-09-30 07:07:39 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-10-02 06:17:14 (GMT)
commit271421cd345a9b5e2fc7e30e672d2c998f50e1dc (patch)
tree32a6dc8ad6c68ed1d1a6f9b16a4c4971635a757c /http-fetch.c
parent49a0f240f7be05728f97903efd97ad7898ff6d08 (diff)
downloadgit-271421cd345a9b5e2fc7e30e672d2c998f50e1dc.zip
git-271421cd345a9b5e2fc7e30e672d2c998f50e1dc.tar.gz
git-271421cd345a9b5e2fc7e30e672d2c998f50e1dc.tar.bz2
Update partial HTTP transfers.
Add the sanity checks discussed on the list with Nick Hengeveld in <20050927000931.GA15615@reactrix.com>. * unlink of previous and rename from temp to previous can fail for reasons other than benign ones (missing previous and missing temp). Report these failures when we encounter them, to make diagnosing problems easier. * when rewinding the partially written result, make sure to truncate the file. Also verify the pack after downloading by calling verify_packfile(). Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'http-fetch.c')
-rw-r--r--http-fetch.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/http-fetch.c b/http-fetch.c
index 778d508..e8ac995 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,6 +1,6 @@
#include "cache.h"
#include "commit.h"
-
+#include "pack.h"
#include "fetch.h"
#include <curl/curl.h>
@@ -431,6 +431,8 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
lst = &((*lst)->next);
*lst = (*lst)->next;
+ if (verify_pack(target, 0))
+ return -1;
install_packed_git(target);
return 0;
@@ -456,9 +458,13 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
snprintf(prevfile, sizeof(prevfile), "%s.prev", filename);
- unlink(prevfile);
- rename(tmpfile, prevfile);
- unlink(tmpfile);
+
+ if (unlink(prevfile) && (errno != ENOENT))
+ return error("Failed to unlink %s (%s)",
+ prevfile, strerror(errno));
+ if (rename(tmpfile, prevfile) && (errno != ENOENT))
+ return error("Failed to rename %s to %s (%s)",
+ tmpfile, prevfile, strerror(errno));
local = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
@@ -523,6 +529,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
if (prev_posn>0) {
prev_posn = 0;
lseek(local, SEEK_SET, 0);
+ ftruncate(local, 0);
}
}