From: Royce Remer <royceremer@gmail.com>
To: git@vger.kernel.org
Cc: Royce Remer <royceremer@gmail.com>, Taylor Blau <me@ttaylorr.com>,
Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>
Subject: [PATCH 1/1] pack-write, pack-bitmap-write: register tmp pack files for cleanup
Date: Fri, 25 Sep 2026 13:56:33 -0700 [thread overview]
Message-ID: <20260925205633.530651-2-royceremer@gmail.com> (raw)
In-Reply-To: <20260925205633.530651-1-royceremer@gmail.com>
`git repack` correctly uses `register_tempfile()` via
`collect_pack_filenames()` for the `.tmp-<pid>-pack-*` files it
creates, so they are removed when the process exits gracefully.
The lower-level pack-writing functions invoked by `git gc` and
`git maintenance` do not. They call `odb_mkstemp()` which wraps
`mkstemp(2)` directly, bypassing the tempfile subsystem entirely.
A SIGTERM leaves these files stranded on disk where they accumulate
and can exhaust available space:
objects/pack/tmp_pack_XXXXXX (create_tmp_packfile)
objects/pack/tmp_idx_XXXXXX (write_idx_file)
objects/pack/tmp_rev_XXXXXX (write_rev_file_order)
objects/pack/tmp_mtimes_XXXXXX (write_mtimes_file)
objects/pack/tmp_bitmap_XXXXXX (bitmap_writer_finish)
Call `register_tempfile()` immediately after each `odb_mkstemp()` so
that the atexit(3) and signal handlers unlink the file on abnormal
exit.
Signed-off-by: Royce Remer <royceremer@gmail.com>
---
pack-bitmap-write.c | 3 +++
pack-write.c | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 1bcb3f98a4..c566419690 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -23,6 +23,7 @@
#include "oid-array.h"
#include "config.h"
#include "alloc.h"
+#include "tempfile.h"
#include "refs.h"
#include "strmap.h"
#include "midx.h"
@@ -1378,6 +1379,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
"pack/tmp_bitmap_XXXXXX");
+ struct tempfile *tmp = register_tempfile(tmp_file.buf);
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
@@ -1435,6 +1437,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
if (rename(tmp_file.buf, filename))
die_errno("unable to rename temporary bitmap file to '%s'", filename);
+ delete_tempfile(&tmp);
strbuf_release(&tmp_file);
free(offsets);
diff --git a/pack-write.c b/pack-write.c
index 83eaf88541..fa6b532230 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -13,6 +13,7 @@
#include "path.h"
#include "repository.h"
#include "strbuf.h"
+#include "tempfile.h"
void reset_pack_idx_option(struct pack_idx_option *opts)
{
@@ -87,6 +88,7 @@ const char *write_idx_file(struct repository *repo,
fd = odb_mkstemp(repo->objects, &tmp_file,
"pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
+ (void)register_tempfile(index_name);
} else {
unlink(index_name);
fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
@@ -263,6 +265,7 @@ char *write_rev_file_order(struct repository *repo,
fd = odb_mkstemp(repo->objects, &tmp_file,
"pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
+ (void)register_tempfile(path);
} else {
unlink(rev_name);
fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
@@ -346,6 +349,7 @@ static char *write_mtimes_file(struct repository *repo,
fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
+ (void)register_tempfile(mtimes_name);
f = hashfd(repo->hash_algo, fd, mtimes_name);
write_mtimes_header(repo->hash_algo, f);
@@ -535,6 +539,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
+ (void)register_tempfile(*pack_tmp_name);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.55.0.1.ga30d533ec0
next prev parent reply other threads:[~2026-09-25 20:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 20:56 [PATCH 0/1] pack-write, pack-bitmap-write: register tmp pack files for cleanup Royce Remer
2026-09-25 20:56 ` Royce Remer [this message]
2026-09-28 7:58 ` [PATCH 1/1] " Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260925205633.530651-2-royceremer@gmail.com \
--to=royceremer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
--cc=newren@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox