aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-02-06 14:56:44 -0800
committerJunio C Hamano <gitster@pobox.com>2025-02-06 14:56:44 -0800
commit9fad473faed7862855ced123de81a53fa27187d9 (patch)
tree40c8a8283ec074236c644c52652336246aa19021
parent2bf3c7fab19a59cde3a3dda9398075f0fe8d57c1 (diff)
parent9a84794ad8ad1bc8ec6b2c4e1592a1f63765e753 (diff)
downloadgit-9fad473faed7862855ced123de81a53fa27187d9.tar.gz
Merge branch 'js/bundle-unbundle-fd-reuse-fix'
The code path used when "git fetch" fetches from a bundle file closed the same file descriptor twice, which sometimes broke things unexpectedly when the file descriptor was reused, which has been corrected. * js/bundle-unbundle-fd-reuse-fix: bundle: avoid closing file descriptor twice
-rw-r--r--bundle.c4
-rw-r--r--bundle.h2
-rw-r--r--transport.c1
3 files changed, 6 insertions, 1 deletions
diff --git a/bundle.c b/bundle.c
index f18f98fec9..d7ad690843 100644
--- a/bundle.c
+++ b/bundle.c
@@ -607,8 +607,10 @@ int unbundle(struct repository *r, struct bundle_header *header,
if (!opts)
opts = &opts_fallback;
- if (verify_bundle(r, header, opts->flags))
+ if (verify_bundle(r, header, opts->flags)) {
+ close(bundle_fd);
return -1;
+ }
strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
diff --git a/bundle.h b/bundle.h
index a80aa8ad9b..d664b2f2d6 100644
--- a/bundle.h
+++ b/bundle.h
@@ -62,6 +62,8 @@ struct unbundle_opts {
*
* Before unbundling, this method will call verify_bundle() with 'flags'
* provided in 'opts'.
+ *
+ * Note that the `bundle_fd` will be closed as part of the operation.
*/
int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, struct strvec *extra_index_pack_args,
diff --git a/transport.c b/transport.c
index 81ae8243b9..d6851dc475 100644
--- a/transport.c
+++ b/transport.c
@@ -207,6 +207,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
ret = unbundle(the_repository, &data->header, data->fd,
&extra_index_pack_args, &opts);
+ data->fd = -1; /* `unbundle()` closes the file descriptor */
transport->hash_algo = data->header.hash_algo;
strvec_clear(&extra_index_pack_args);