On Mon, Oct 17, 2022 at 08:50:07PM +0200, Ævar Arnfjörð Bjarmason wrote: > On Mon, Oct 17 2022, Jeff King wrote: > > > On Wed, Oct 12, 2022 at 03:05:33PM -0400, Taylor Blau wrote: > > [...] > >> [...] > >> + for_each_string_list_item(item, include) { > >> + strbuf_addstr(&path, item->string); > >> + strbuf_strip_suffix(&path, ".idx"); > >> + strbuf_addstr(&path, ".bitmap"); > >> + > >> + if (unlink(path.buf) && errno != ENOENT) > >> + die_errno(_("could not remove stale bitmap: %s"), > >> + path.buf); > > > > We could downgrade this to a warning, since there is no downside to > > retaining those files (aside from wasted space). In > > remove_redundant_pack(), we call into unlink_pack_path(), which just > > ignores unlink errors (though arguably it should at least warn). > > An ENOENT would indicate a race with a concurrent process. In the code above, I don't think it is. We included some packs in the midx, and we know that their bitmaps (if any) are now redundant. So we remove them by calling unlink() speculatively, rather than asking "do we have this file? If so, unlink". Likewise in remove_redundant_pack(). We are not just removing the packfiles, but speculatively removing their .rev, .bitmap, .promisor, etc. If they don't exist, that's perfectly normal. Arguably we could notice and complain if the .pack or .idx went away in the interim, since those would indicate a race. So I think the code above is right to ignore ENOENT. The one in remove_redundant_pack() does so, too, but it also ignores everything else. > But at that point should we be ignoring other unlink() errors? Maybe we > should additionally be ignoring EBUSY. For most errors besides ENOENT, I think a warning is the right thing. It is OK that we failed to remove the file (it does not make the overall operation a failure). But it may be helpful for the user to let them know that the cruft was left (e.g., for EPERM or EIO). And that applies here and in remove_redundant_pack(). Really, both here and remove_redundant_pack() should probably be using unlink_or_warn(). Though if you did want to notice the race on deleting the actual .pack file, it would need to be hand-coded. -Peff