commit 359751d62115e29bad878f9b7b9711242ce4683e
parent d12cea97cfff7cfaf6d90318c9b143c5eb05bd41
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 2 Oct 2024 19:01:37 +0200
Add the fsck subcommand
It checks locally stored WAD files and can remove corrupted ones. This
subcommand is essential to avoid having to manually determine what
happened when a file was corrupted during transfer. And even more so
since the removal, for compatibility reasons, of the --remove-on-error
option from the curl command used to transfer WAD files via
http[s]/gopher[s] (commit d12cea9): there are even more situations where
data can be erroneous.
Diffstat:
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/git-wad b/git-wad
@@ -64,6 +64,7 @@ synopsis()
{
>&2 printf "usage: git-wad checkout\n"
>&2 printf " git-wad fetch [-1a]\n"
+ >&2 printf " git-wad fsck [-r]\n"
>&2 printf " git-wad init\n"
>&2 printf " git-wad prune [-1a]\n"
>&2 printf " git-wad pull [-1a]\n"
@@ -400,6 +401,36 @@ fetch() # [-1a]
fi
}
+# Check the integrity of the stored WAD content
+fsck()
+{
+ remove=0
+
+ OPTIND=1
+ while getopts ":r" opt; do
+ case "${opt}" in
+ r) remove=1 ;;
+ *)
+ >&2 printf "Invalid option -- %s\n" "${OPTARG}"
+ return 1
+ ;;
+ esac
+ done
+
+ wads="${git_wad_tmpdir}/wads"
+ all_objects > "${wads}"
+
+ xargs -I {} sh -c \
+ "printf '%s %s/%s' \"{}\" \"${GIT_WAD_OBJDIR}\" \"{}\" \
+ | sha256sum -c || { \
+ if [ ! ${remove} -eq 0 ]; then \
+ printf '\e[0;31mremove\e[0m %s\n' \"{}\"; \
+ rm -f \"${GIT_WAD_OBJDIR}/{}\"; \
+ fi
+ }" \
+ < "${wads}"
+}
+
# Restore the content of WAD files
checkout()
{
@@ -531,6 +562,7 @@ case "${sub_cmd}" in
"fetch") shift 1; fetch "$@" ;;
"filter-clean") shift 1; clean "$@" ;;
"filter-smudge") shift 1; smudge "$@" ;;
+ "fsck") shift 1; fsck "$@" ;;
"init") shift 1; init ;;
"prune") shift 1; prune "$@" ;;
"push") shift 1; push "$@" ;;
diff --git a/git-wad.1 b/git-wad.1
@@ -12,7 +12,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
-.Dd May 1, 2024
+.Dd October 2, 2024
.Dt GIT-WAD 1
.Os
.Sh NAME
@@ -24,6 +24,8 @@
.Nm
.Cm fetch Op Fl 1a
.Nm
+.Cm fsck Op Fl r
+.Nm
.Cm init
.Nm
.Cm prune Op Fl 1a
@@ -88,6 +90,11 @@ that are no longer referenced.
Transfers all versions of WAD files referenced in the complete
repository history, i.e. in all commits of all branches.
.El
+.It Cm fsck
+Checks locally stored WAD files.
+If the
+.Fl r
+option is set, corrupted files are deleted.
.It Cm init
Configures the git repository for WAD file management.
Must be called in the working tree before any other
@@ -262,6 +269,13 @@ git pull origin
git wad pull
.Ed
.Pp
+Check locally stored WAD files and delete corrupted ones before
+retransferring missing files:
+.Bd -literal -offset Ds
+git wad fsck -r
+git wad pull
+.Ed
+.Pp
Make space on disk by deleting the contents of WAD files that are not
referenced by HEAD:
.Bd -literal -offset Ds