Re: [PATCH 04/10] packed-backend: add "packed-refs" header consistency check
- From
shejialuo <shejialuo@gmail.com>
- Date
- Feb 17, 2025, 13:16 UTC
- Message-ID
- <Z7M2m0diauWW2ARQ@ArchLinux>
- In-Reply-To
- <Z4kQUb7og2Ce1iCo@pks.im>
On Thu, Jan 16, 2025 at 02:57:37PM +0100, Patrick Steinhardt wrote:
[snip]
Show 19 quoted lines
> > @@ -1779,7 +1867,24 @@ static int packed_fsck(struct ref_store *ref_store,
> > goto cleanup;
> > }
> >
> > + if (strbuf_read_file(&packed_ref_content, refs->path, 0) < 0) {
> > + /*
> > + * Although we have checked that the file exists, there is a possibility
> > + * that it has been removed between the lstat() and the read attempt by
> > + * another process. In that case, we should not report an error.
> > + */
> > + if (errno == ENOENT)
> > + goto cleanup;
>
> Unlikely, but good to guard us against that condition regardless. It's
> still not entirely race-free though because the file could meanwhile
> have changed into a symlink, and we wouldn't notice now. We could fix
> that by using open(O_NOFOLLOW), fstat the returne file descriptor and
> then use `strbuf_read()` to slurp in the file.
> I have been looking back to the original discussion. I will follow this advice which eventually avoids the race.
Thanks, Jialuo