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>
Junio C Hamano committed
Sep 30, 2005 at 00:07 UTC
271421cd345a9b5e2fc7e30e672d2c998f50e1dc
1 file changed
+11
-4
http-fetch.c
+11
-4
@@ -1,6 +1,6 @@
1
#include "cache.h"
2
#include "commit.h"
3
-
3
+#include "pack.h"
4
#include "fetch.h"
5
6
#include <curl/curl.h>
@@ -431,6 +431,8 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
431
lst = &((*lst)->next);
432
*lst = (*lst)->next;
433
434
+ if (verify_pack(target, 0))
435
+ return -1;
436
install_packed_git(target);
437
438
return 0;
@@ -456,9 +458,13 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
458
459
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
460
snprintf(prevfile, sizeof(prevfile), "%s.prev", filename);
459
- unlink(prevfile);
460
- rename(tmpfile, prevfile);
461
- unlink(tmpfile);
461
+
462
+ if (unlink(prevfile) && (errno != ENOENT))
463
+ return error("Failed to unlink %s (%s)",
464
+ prevfile, strerror(errno));
465
+ if (rename(tmpfile, prevfile) && (errno != ENOENT))
466
+ return error("Failed to rename %s to %s (%s)",
467
+ tmpfile, prevfile, strerror(errno));
468
469
local = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
470
@@ -523,6 +529,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
529
if (prev_posn>0) {
530
prev_posn = 0;
531
lseek(local, SEEK_SET, 0);
532
+ ftruncate(local, 0);
533
}
534
}
535