Skip to content

Commit 271421c

Browse files
author
Junio C Hamano
committed
Update partial HTTP transfers.
Add the sanity checks discussed on the list with Nick Hengeveld in <[email protected]>. * 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 <[email protected]>
1 parent 49a0f24 commit 271421c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

http-fetch.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cache.h"
22
#include "commit.h"
3-
3+
#include "pack.h"
44
#include "fetch.h"
55

66
#include <curl/curl.h>
@@ -431,6 +431,8 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
431431
lst = &((*lst)->next);
432432
*lst = (*lst)->next;
433433

434+
if (verify_pack(target, 0))
435+
return -1;
434436
install_packed_git(target);
435437

436438
return 0;
@@ -456,9 +458,13 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
456458

457459
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
458460
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));
462468

463469
local = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
464470

@@ -523,6 +529,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
523529
if (prev_posn>0) {
524530
prev_posn = 0;
525531
lseek(local, SEEK_SET, 0);
532+
ftruncate(local, 0);
526533
}
527534
}
528535

0 commit comments

Comments
 (0)