Artifact 3e84c0372f731d8be4964aa226c4cee5b7d2c0c534e1208e75896b1791c1f85f:
- File
internal/verify/check_structure.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 2040) [annotate] [blame] [check-ins using]
package verify import ( "fmt" libfossil "github.com/danmestas/libfossil/internal/fsltype" "github.com/danmestas/libfossil/internal/repo" ) // checkDeltaChains verifies delta relationships are valid. // Detects dangling references: delta rows pointing to nonexistent blobs. func checkDeltaChains(r *repo.Repo, report *Report) error { if r == nil { panic("checkDeltaChains: nil *repo.Repo") } if report == nil { panic("checkDeltaChains: nil *Report") } rows, err := r.DB().Query(` SELECT d.rid, d.srcid FROM delta d WHERE NOT EXISTS (SELECT 1 FROM blob WHERE rid = d.rid) OR NOT EXISTS (SELECT 1 FROM blob WHERE rid = d.srcid) `) if err != nil { return fmt.Errorf("checkDeltaChains: query: %w", err) } defer rows.Close() for rows.Next() { var rid, srcid int64 if err := rows.Scan(&rid, &srcid); err != nil { return fmt.Errorf("checkDeltaChains: scan: %w", err) } report.addIssue(Issue{ Kind: IssueDeltaDangling, RID: libfossil.FslID(rid), UUID: "", Table: "delta", Message: fmt.Sprintf("delta rid=%d srcid=%d: one or both blobs missing", rid, srcid), }) } return rows.Err() } // checkPhantoms verifies phantom records are properly tracked. // Detects orphan phantoms: phantom rows with no corresponding blob. func checkPhantoms(r *repo.Repo, report *Report) error { if r == nil { panic("checkPhantoms: nil *repo.Repo") } if report == nil { panic("checkPhantoms: nil *Report") } rows, err := r.DB().Query(` SELECT p.rid FROM phantom p WHERE NOT EXISTS (SELECT 1 FROM blob WHERE rid = p.rid) `) if err != nil { return fmt.Errorf("checkPhantoms: query: %w", err) } defer rows.Close() for rows.Next() { var rid int64 if err := rows.Scan(&rid); err != nil { return fmt.Errorf("checkPhantoms: scan: %w", err) } report.addIssue(Issue{ Kind: IssuePhantomOrphan, RID: libfossil.FslID(rid), UUID: "", Table: "phantom", Message: fmt.Sprintf("phantom rid=%d: no corresponding blob", rid), }) } return rows.Err() }