diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-08-07 10:23:53 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-08-18 02:34:08 +0200 |
| commit | 7284c1059fa801f3df852f6080dff73f82a8262a (patch) | |
| tree | 2ab91a26238b38d1efc46658de287e60c16eb9c3 /src | |
| parent | 441f57c2b7fe414ed50b2d13979795a69bd7bd59 (diff) | |
| download | libgit2-7284c1059fa801f3df852f6080dff73f82a8262a.tar.gz | |
Don't try to download the packfile too early
Make sure we only try to download the pack if we find the pack header
in the stream, and not if the server takes a bit longer to send us the
last NAK.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src')
| -rw-r--r-- | src/transport_git.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/transport_git.c b/src/transport_git.c index 5f03a4b20..60958c9cc 100644 --- a/src/transport_git.c +++ b/src/transport_git.c @@ -351,6 +351,10 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo) strcat(path, suff); //memcpy(path + off, suff, GIT_PATH_MAX - off - STRLEN(suff) - 1); + if (memcmp(buf->data, "PACK", STRLEN("PACK"))) { + return git__throw(GIT_ERROR, "The pack doesn't start with the signature"); + } + error = git_filebuf_open(&file, path, GIT_FILEBUF_TEMPORARY); if (error < GIT_SUCCESS) goto cleanup; @@ -387,7 +391,7 @@ cleanup: static int git_download_pack(char **out, git_transport *transport, git_repository *repo) { transport_git *t = (transport_git *) transport; - int s = t->socket, error = GIT_SUCCESS, pack = 0; + int s = t->socket, error = GIT_SUCCESS; gitno_buffer buf; char buffer[1024]; git_pkt *pkt; @@ -395,7 +399,7 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor gitno_buffer_setup(&buf, buffer, sizeof(buffer), s); /* - * First, we ignore any ACKs and wait for a NACK + * For now, we ignore everything and wait for the pack */ while (1) { error = gitno_recv(&buf); @@ -406,7 +410,7 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor ptr = buf.data; /* Whilst we're searching for the pack */ - while (!pack) { + while (1) { if (buf.offset == 0) break; error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); @@ -415,21 +419,14 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor if (error < GIT_SUCCESS) return error; - gitno_consume(&buf, line_end); - if (pkt->type == GIT_PKT_PACK) - pack = 1; + if (pkt->type == GIT_PKT_PACK) { + return store_pack(out, &buf, repo); + } /* For now we don't care about anything */ free(pkt); + gitno_consume(&buf, line_end); } - - /* - * No we have the packet, let's just put anything we get now - * into a packfile - */ - return store_pack(out, &buf, repo); } - - return error; } |
