]> git.scottworley.com Git - annex-ec/commitdiff
Start on fsck: Invoke recover if data is missing
authorScott Worley <scottworley@scottworley.com>
Wed, 18 Mar 2026 02:36:37 +0000 (19:36 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 18 Mar 2026 02:36:37 +0000 (19:36 -0700)
annex-ec-fsck [new file with mode: 0755]

diff --git a/annex-ec-fsck b/annex-ec-fsck
new file mode 100755 (executable)
index 0000000..2a6026c
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+# annex-ec: Use erasure codes for more efficient storage use in git-annex
+# Copyright (C) 2026  Scott Worley
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+set -euo pipefail
+
+die() {
+  echo "$*" >&2
+  exit 1
+}
+
+check_one_group() {
+  local where_data
+  where_data=$(set +e; git annex whereis --json "${recovery_set_files[@]}"; set -e)
+  missing_data=$(jq -r 'if .whereis == [] then .file else empty end' <<< "$where_data")
+  if [[ "$missing_data" ]];then
+    xargs -d \\n annex-ec-recover <<< "$missing_data"
+  fi
+}
+
+check_all_groups() {
+  recovery_set_name=
+  recovery_set_files=()
+  while IFS= read -r line;do
+    if [[ "$line" == ' '* ]];then
+      recovery_set_files+=( "${line# }" )
+    else
+      if [[ "$recovery_set_name" ]];then
+        check_one_group
+      fi
+      recovery_set_name=$line
+      recovery_set_files=()
+    fi
+  done < ec/.meta
+  check_one_group
+}
+
+check_all_groups