Store each hash as its raw 32 bytes in a BLOB column (closes #134)
check / check (push) Waiting to run
check / check (push) Waiting to run
The head, tail and content columns of the files table are BLOB NOT NULL and hold the raw 32-byte SHA-256, half the size of the hex text, in the table and in the files_signature index. The hash phase, the records, report and trees carry each hash as a [sha256.Size]byte and compare it with ==; nothing is hex-encoded. Reading a record whose hash column is not 32 bytes is an error naming its path. In the tests, testHash is a stand-in hash: a string's bytes padded with zeros, so fixtures keep the sort order their strings give. Judgement call: a hash of the wrong length is refused on reading, not copied silently. Model: opus-5-5
This commit is contained in:
+17
-22
@@ -10,16 +10,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Signature hashes shared by the smoke-test records.
|
||||
const (
|
||||
f1Head = "f1h"
|
||||
f1Tail = "f1t"
|
||||
f1Content = "f1c"
|
||||
f2Head = "f2h"
|
||||
f2Tail = "f2t"
|
||||
f2Content = "f2c"
|
||||
)
|
||||
|
||||
// treesOpenLine is the plain line of trees' open phase when it opens
|
||||
// the database at once; it prints it as the phase starts and as it ends.
|
||||
const treesOpenLine = "[1/4] open: opening the database, elapsed 0s, " +
|
||||
@@ -28,6 +18,9 @@ const treesOpenLine = "[1/4] open: opening the database, elapsed 0s, " +
|
||||
// smokeTreeRecs mirrors the README smoke-test tree layout: /d/t1 and
|
||||
// /d/t2 are identical, /d/t3 differs from them only by one filename.
|
||||
func smokeTreeRecs() []scanRec {
|
||||
f1Head, f1Tail, f1Content := testHash("f1h"), testHash("f1t"), testHash("f1c")
|
||||
f2Head, f2Tail, f2Content := testHash("f2h"), testHash("f2t"), testHash("f2c")
|
||||
|
||||
return []scanRec{
|
||||
{size: 3000, head: f1Head, tail: f1Tail, content: f1Content, path: "/d/t1/f1"},
|
||||
{size: 100, head: f2Head, tail: f2Tail, content: f2Content, path: "/d/t1/sub/f2"},
|
||||
@@ -153,13 +146,14 @@ func TestTreeNamesSortingBeforeSlash(t *testing.T) {
|
||||
|
||||
for _, top := range []string{"/a", "/c"} {
|
||||
for _, p := range []string{"/b", "/b-x/f", "/b.txt", "/b/f"} {
|
||||
content := "c"
|
||||
content := testHash("c")
|
||||
if p == "/b-x/f" {
|
||||
content = "other"
|
||||
content = testHash("other")
|
||||
}
|
||||
|
||||
recs = append(recs, scanRec{
|
||||
size: 1, head: "h", tail: "t", content: content, path: top + p,
|
||||
size: 1, head: testHash("h"), tail: testHash("t"),
|
||||
content: content, path: top + p,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -332,11 +326,10 @@ func TestTreeDigests(t *testing.T) {
|
||||
func TestTreeDigestContentSensitivity(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const sharedTail = "same"
|
||||
|
||||
same, c := testHash("same"), testHash("c")
|
||||
recs := []scanRec{
|
||||
{size: 10, head: sharedTail, tail: sharedTail, content: "c", path: "/r/a/f"},
|
||||
{size: 10, head: "DIFF", tail: sharedTail, content: "c", path: "/r/b/f"},
|
||||
{size: 10, head: same, tail: same, content: c, path: "/r/a/f"},
|
||||
{size: 10, head: testHash("DIFF"), tail: same, content: c, path: "/r/b/f"},
|
||||
}
|
||||
|
||||
_, dirs := treeOf(t, recs)
|
||||
@@ -397,9 +390,10 @@ func TestCollectTreeGroupsSiblings(t *testing.T) {
|
||||
|
||||
// Identical sibling dirs share a parent, so their group cannot be
|
||||
// implied by a parent group and must be reported.
|
||||
h, tl, c := testHash("h"), testHash("t"), testHash("c")
|
||||
recs := []scanRec{
|
||||
{size: 10, head: "h", tail: "t", content: "c", path: "/p/x1/f"},
|
||||
{size: 10, head: "h", tail: "t", content: "c", path: "/p/x2/f"},
|
||||
{size: 10, head: h, tail: tl, content: c, path: "/p/x1/f"},
|
||||
{size: 10, head: h, tail: tl, content: c, path: "/p/x2/f"},
|
||||
}
|
||||
|
||||
super, dirs := treeOf(t, recs)
|
||||
@@ -418,10 +412,11 @@ func TestCollectTreeGroupsDifferingParents(t *testing.T) {
|
||||
// /p/a and /q/b contain identical x subtrees, but /p/a has an
|
||||
// extra file, so the parents' digests differ and the x group must
|
||||
// be reported.
|
||||
h, tl, c, e := testHash("h"), testHash("t"), testHash("c"), testHash("e")
|
||||
recs := []scanRec{
|
||||
{size: 10, head: "h", tail: "t", content: "c", path: "/p/a/x/f"},
|
||||
{size: 99, head: "e", tail: "e", content: "e", path: "/p/a/extra"},
|
||||
{size: 10, head: "h", tail: "t", content: "c", path: "/q/b/x/f"},
|
||||
{size: 10, head: h, tail: tl, content: c, path: "/p/a/x/f"},
|
||||
{size: 99, head: e, tail: e, content: e, path: "/p/a/extra"},
|
||||
{size: 10, head: h, tail: tl, content: c, path: "/q/b/x/f"},
|
||||
}
|
||||
|
||||
super, dirs := treeOf(t, recs)
|
||||
|
||||
Reference in New Issue
Block a user