|
19 | 19 | #include "string-list.h" |
20 | 20 | #include "object-file.h" |
21 | 21 | #include "object-store-ll.h" |
| 22 | +#include "tempfile.h" |
22 | 23 |
|
23 | 24 | static struct trace_key trace_curl = TRACE_KEY_INIT(CURL); |
24 | 25 | static int trace_curl_data = 1; |
@@ -2388,8 +2389,24 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url) |
2388 | 2389 | strbuf_addf(&buf, "objects/pack/pack-%s.idx", hash_to_hex(hash)); |
2389 | 2390 | url = strbuf_detach(&buf, NULL); |
2390 | 2391 |
|
2391 | | - strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(hash)); |
2392 | | - tmp = strbuf_detach(&buf, NULL); |
| 2392 | + /* |
| 2393 | + * Don't put this into packs/, since it's just temporary and we don't |
| 2394 | + * want to confuse it with our local .idx files. We'll generate our |
| 2395 | + * own index if we choose to download the matching packfile. |
| 2396 | + * |
| 2397 | + * It's tempting to use xmks_tempfile() here, but it's important that |
| 2398 | + * the file not exist, otherwise http_get_file() complains. So we |
| 2399 | + * create a filename that should be unique, and then just register it |
| 2400 | + * as a tempfile so that it will get cleaned up on exit. |
| 2401 | + * |
| 2402 | + * In theory we could hold on to the tempfile and delete these as soon |
| 2403 | + * as we download the matching pack, but it would take a bit of |
| 2404 | + * refactoring. Leaving them until the process ends is probably OK. |
| 2405 | + */ |
| 2406 | + tmp = xstrfmt("%s/tmp_pack_%s.idx", |
| 2407 | + repo_get_object_directory(the_repository), |
| 2408 | + hash_to_hex(hash)); |
| 2409 | + register_tempfile(tmp); |
2393 | 2410 |
|
2394 | 2411 | if (http_get_file(url, tmp, NULL) != HTTP_OK) { |
2395 | 2412 | error("Unable to get pack index %s", url); |
@@ -2427,10 +2444,8 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head, |
2427 | 2444 | } |
2428 | 2445 |
|
2429 | 2446 | ret = verify_pack_index(new_pack); |
2430 | | - if (!ret) { |
| 2447 | + if (!ret) |
2431 | 2448 | close_pack_index(new_pack); |
2432 | | - ret = finalize_object_file(tmp_idx, sha1_pack_index_name(sha1)); |
2433 | | - } |
2434 | 2449 | free(tmp_idx); |
2435 | 2450 | if (ret) |
2436 | 2451 | return -1; |
|
0 commit comments