git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] reftable: ignore file-in-use errors when unlink(3p) fails on Windows

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 25, 2025, 08:32 UTC
Message-ID
<Z5ShoLCWREAsWZVh@pks.im>
In-Reply-To
<6acb9e8a-7014-4605-b8af-59c4584e9fe6@kdbg.org>
On Sat, Jan 25, 2025 at 09:19:57AM +0100, Johannes Sixt wrote:
Show 20 quoted lines
> Am 25.01.25 um 06:41 schrieb Patrick Steinhardt:
> > While this logic might be sensible in many callsites throughout Git, it
> > is less when used in the reftable library. We only use unlink(3) there
> > to delete tables which aren't referenced anymore, and the code is very
> > aware of the limitations on Windows. As such, all calls to unlink(3p)
> > don't perform any error checking at all and are fine with the call
> > failing.
> > 
> > Instead, the library provides the `reftable_stack_clean()` function,
> > which Git knows to execute in git-pack-refs(1) after compacting a stack.
> > The effect of this function is that all stale tables will eventually get
> > deleted once they aren't kept open anymore.
> > 
> > So while we're fine with unlink(3p) failing, the Windows-emulation of
> > that function will still perform several sleeps and ultimately end up
> > asking the user:
> 
> Why don't the changes that your commits ending at 391bceae4350
> ("compat/mingw: support POSIX semantics for atomic renames", 2024-10-27)
> help in this case, too?

The user report was explicitly about compatibility with JGit, which still had these files open. We don't have control over third-party clients and how exactly they open files, so it is expected that we may still see failures with the deletion of in-use files.

> Since the reftable layer is aware of the problem, why don't we just fix
> it there and instead sweep it under the rug in the compat layer?

I didn't really have a good idea for _how_ to do that. We automatically pull in the compat version of `unlink()` via "git-compat-util.h", and we cannot easily change that. So the reftable library is basically unable to handle it there, because the assumed POSIX-behavior of `unlink()` is different. I also don't want to reimplement the "compat/" layer for Windows, because it brings us a couple of features for free, like wide-character handling and handling the deletion of read-only files.

Another alternative would be to provide `reftable_unlink()` in the reftable system layer, implement it via `mingw_unlink()` with that second argument I'm introducing and then convert all callsites of unlink to use that function instead. But that felt unnecessarily complex to me.

I'd be happy to hear about alternative ideas that didn't came to my mind.

Patrick
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 16 in “reftable: ignore file-in-use errors when unlink(3p) fails on Windows”
  1. reftable: ignore file-in-use errors when unlink(3p) fails on WindowsPatrick Steinhardt, Jan 25, 2025
  2. Johannes SixtJan 25, 2025
  3. Patrick SteinhardtJan 25, 2025
  4. Johannes SixtJan 25, 2025
  5. Patrick SteinhardtJan 27, 2025
  6. Johannes SixtJan 28, 2025
  7. Patrick SteinhardtJan 28, 2025
  8. Johannes SixtJan 29, 2025
  9. Christian ReichJan 25, 2025
  10. Patrick SteinhardtJan 27, 2025
  11. Junio C HamanoJan 26, 2025
  12. Patrick SteinhardtJan 27, 2025
  13. reftable: ignore file-in-use errors when unlink(3p) fails on WindowsPatrick Steinhardt, Feb 6, 2025
  14. Christian ReichMar 14, 2025
  15. Patrick SteinhardtMar 14, 2025
  16. Johannes SchindelinMar 15, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.