summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-09-09 19:25:00 -0400
committerJunio C Hamano <gitster@pobox.com>2021-09-09 18:23:11 -0700
commit4bc1fd6e3941be74027594efad3d2358a93702df (patch)
tree0040b5935a3b0df9bf0c0cbef6b4a3e93f32751c
parent2ec02dd5a8261bc837b961ef36788081ded5c2bc (diff)
pack-objects: rename .idx files into place after .bitmap files
In preceding commits the race of renaming .idx files in place before .rev files and other auxiliary files was fixed in pack-write.c's finish_tmp_packfile(), builtin/repack.c's "struct exts", and builtin/index-pack.c's final(). As noted in the change to pack-write.c we left in place the issue of writing *.bitmap files after the *.idx, let's fix that issue. See 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21) for commentary at the time when *.bitmap was implemented about how those files are written out, nothing in that commit contradicts what's being done here. Note that this commit and preceding ones only close any race condition with *.idx files being written before their auxiliary files if we're optimistic about our lack of fsync()-ing in this are not tripping us over. See the thread at [1] for a rabbit hole of various discussions about filesystem races in the face of doing and not doing fsync() (and if doing fsync(), not doing it properly). We may want to fsync the containing directory once after renaming the *.idx file into place, but that is outside the scope of this series. 1. https://lore.kernel.org/git/8735qgkvv1.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/pack-objects.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 0a46584922..7a3632828c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1250,7 +1250,6 @@ static void write_pack_file(void)
stage_tmp_packfiles(&tmpname, pack_tmp_name,
written_list, nr_written,
&pack_idx_opts, hash, &idx_tmp_name);
- rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
if (write_bitmap_index) {
size_t tmpname_len = tmpname.len;
@@ -1267,6 +1266,8 @@ static void write_pack_file(void)
strbuf_setlen(&tmpname, tmpname_len);
}
+ rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
+
free(idx_tmp_name);
strbuf_release(&tmpname);
free(pack_tmp_name);