Artifact 6d3fdb3d467b0794508c8f93c3031c07c9e5b45b66dacbcb56b834b64de7c82b:
- File
cli/repo_status.go
— part of check-in
[670ca0e75f]
at
2026-07-19 16:00:09
on branch trunk
— fix: separate blob existence from blob availability (#43) (#52)
* fix: separate blob existence from blob availability (#43)
A phantom is a real blob row with size = -1 and NULL content, so blob.Exists — "SELECT rid FROM blob WHERE uuid=?" — answers true for it. Every guard built on Exists therefore admitted artifacts whose content cannot be read, and content.Expand aborted with "rid N is a phantom".
Canonical Fossil keeps two predicates and never substitutes one for the other: rid_from_uuid (existence, xfer.c:70) and content_is_available (availability, content.c:163). The latter is transitive — it follows delta.srcid up the chain, so a delta whose base is a phantom is unavailable even though every row in the chain exists.
Add content.IsAvailable / content.AvailableByUUID, ported from content_is_available including the chain walk, with an explicit depth bound so a cyclic delta table terminates instead of hanging. The walk lives in exactly one place; no caller touches the delta table.
blob.Exists keeps its behavior and gains a doc comment stating that it answers existence only, returns true for phantoms, and naming the availability predicate as the alternative.
manifest.blobPresent is deleted. It was a local patch at one call site that tested size >= 0 without the chain walk, so it still reported a delta-on-phantom as present — the same class of bug it was written to work around.
Every blob.Exists call site was classified as existence or availability and converted where it guards a content read. Sites that want rid identity — plink/mlink/tagxref population, cluster phantom creation, private-status bookkeeping, the post-store sanity check in handleFile, and phantom filling in storeReceivedFile — keep existence, since delta-before-base is a normal steady state during clone.
Verified against a loopback fossil 2.28 server: the 23-artifact repro that previously failed roughly half the time now clones 6 of 6.
* fix: IsAvailable must fail closed when the delta lookup errors
Only sql.ErrNoRows means the chain is grounded. Any other failure — cancelled context, closed connection, NULL srcid — says nothing about groundedness, so returning true there claims readable content that was never verified. That is the same class of bug this predicate exists to prevent, and it runs on data arriving over the wire during clone.
The blob-size lookup above already fails closed on the same pattern; this restores the symmetry. (user: [email protected], size: 2114) [annotate] [blame] [check-ins using]
package cli import ( "crypto/sha1" "encoding/hex" "fmt" "io/fs" "os" "path/filepath" "strings" "github.com/danmestas/libfossil/internal/content" ) // RepoStatusCmd shows working directory changes vs the tip version. type RepoStatusCmd struct { Dir string `short:"d" help:"Checkout directory to scan" default:"."` } func (c *RepoStatusCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() tipRid, err := resolveRID(r, "tip") if err != nil { fmt.Println("empty repository -- no checkins") return nil } manifestFiles, err := r.ListFiles(tipRid) if err != nil { return err } // Build map of manifest files: name -> UUID. expected := make(map[string]string) for _, f := range manifestFiles { expected[f.Name] = f.UUID } db := r.Inner().DB() // Scan working directory. seen := make(map[string]bool) err = filepath.WalkDir(c.Dir, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } if d.IsDir() { name := d.Name() if name == ".fslckout" || name == "_FOSSIL_" || name == ".fsl" || strings.HasPrefix(name, ".") { return filepath.SkipDir } return nil } relPath, err := filepath.Rel(c.Dir, path) if err != nil { return err } if strings.HasPrefix(filepath.Base(relPath), ".") { return nil } seen[relPath] = true uuid, inManifest := expected[relPath] if !inManifest { fmt.Printf("EXTRA %s\n", relPath) return nil } data, err := os.ReadFile(path) if err != nil { return err } h := sha1.Sum(data) diskHash := hex.EncodeToString(h[:]) if diskHash != uuid { fileRid, ok := content.AvailableByUUID(db, uuid) if ok { blobData, err := content.Expand(db, fileRid) if err == nil { bh := sha1.Sum(blobData) blobHash := hex.EncodeToString(bh[:]) if blobHash == diskHash { return nil } } } fmt.Printf("EDITED %s\n", relPath) } return nil }) if err != nil { return err } for name := range expected { if !seen[name] { fmt.Printf("MISSING %s\n", name) } } return nil }