Add verify command to check blob store integrity.

Verify iterates manifest file entries, confirms each blob exists in the
store, and re-hashes the content to detect corruption. Includes unit
tests for the ok, hash-mismatch, and blob-missing cases, plus a thin
CLI wrapper that exits non-zero on any failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 21:50:17 -07:00
parent 0d53ca34aa
commit 1471cf0ebc
3 changed files with 230 additions and 0 deletions

43
cmd/sgard/verify.go Normal file
View File

@@ -0,0 +1,43 @@
package main
import (
"errors"
"fmt"
"github.com/kisom/sgard/garden"
"github.com/spf13/cobra"
)
var verifyCmd = &cobra.Command{
Use: "verify",
Short: "Check all blobs against manifest hashes",
RunE: func(cmd *cobra.Command, args []string) error {
g, err := garden.Open(repoFlag)
if err != nil {
return err
}
results, err := g.Verify()
if err != nil {
return err
}
allOK := true
for _, r := range results {
fmt.Printf("%-14s %s\n", r.Detail, r.Path)
if !r.OK {
allOK = false
}
}
if !allOK {
return errors.New("verification failed: one or more blobs are corrupt or missing")
}
return nil
},
}
func init() {
rootCmd.AddCommand(verifyCmd)
}