]> git.ipfire.org Git - thirdparty/git.git/commit
packed-backend: check whether the "packed-refs" is regular file
authorshejialuo <shejialuo@gmail.com>
Thu, 27 Feb 2025 16:06:24 +0000 (00:06 +0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Feb 2025 22:03:07 +0000 (14:03 -0800)
commitcfea2f2da8d418edd7984e5b5073825834099a27
treea74f59ca10fe5127a07b1cf192ffd00883dae788
parentfdf3820b7ef69dcf887bd86565e2442f89edc7c0
packed-backend: check whether the "packed-refs" is regular file

Although "git-fsck(1)" and "packed-backend.c" will check some
consistency and correctness of "packed-refs" file, they never check the
filetype of the "packed-refs". Let's verify that the "packed-refs" has
the expected filetype, confirming it is created by "git pack-refs"
command.

We could use "open_nofollow" wrapper to open the raw "packed-refs" file.
If the returned "fd" value is less than 0, we could check whether the
"errno" is "ELOOP" to report an error to the user. And then we use
"fstat" to check whether the "packed-refs" file is a regular file.

Reuse "FSCK_MSG_BAD_REF_FILETYPE" fsck message id to report the error to
the user if "packed-refs" is not a regular file.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/packed-backend.c
t/t0602-reffiles-fsck.sh