Content Sureness
This commit is contained in:
@@ -777,7 +777,7 @@ func chunksFromManifest(assets []assetResource, entries []BuildManifestHAK) ([]h
|
||||
}
|
||||
chunkAssets = append(chunkAssets, asset)
|
||||
}
|
||||
chunks = append(chunks, hakChunk{
|
||||
chunk := hakChunk{
|
||||
Config: project.HAKConfig{
|
||||
Name: entry.Group,
|
||||
Priority: entry.Priority,
|
||||
@@ -788,7 +788,14 @@ func chunksFromManifest(assets []assetResource, entries []BuildManifestHAK) ([]h
|
||||
Name: entry.Name,
|
||||
Assets: chunkAssets,
|
||||
Size: erf.ArchiveSize(resourceSlice(chunkAssets)),
|
||||
})
|
||||
}
|
||||
// A manifest can name two distinct source paths that collapse to the same
|
||||
// resref+type (e.g. creature/foo.mdl and placeable/foo.mdl); without this
|
||||
// guard the second would silently shadow the first in the ERF.
|
||||
if err := ensureUniqueChunkResources(chunk); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chunks = append(chunks, chunk)
|
||||
}
|
||||
return chunks, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/buildinfo"
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/erf"
|
||||
)
|
||||
|
||||
const validAsset = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
@@ -141,6 +142,32 @@ func TestValidateDirectSourceManifestRejectsBuilderMismatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Two distinct source paths can collapse to the same resref+type; the chunker
|
||||
// must reject that rather than let one silently shadow the other in the ERF.
|
||||
func TestChunksFromManifestRejectsResrefCollision(t *testing.T) {
|
||||
tga, ok := erf.HAKResourceTypeForExtension("tga")
|
||||
if !ok {
|
||||
t.Fatal("tga is not a hak resource type")
|
||||
}
|
||||
mk := func(rel, resref string) assetResource {
|
||||
r := erf.Resource{Name: resref, Type: tga}
|
||||
return assetResource{Rel: rel, Resource: r, Size: erf.ArchiveSize([]erf.Resource{r})}
|
||||
}
|
||||
entry := BuildManifestHAK{Name: "core_01", Group: "core"}
|
||||
|
||||
collide := []assetResource{mk("creature/foo.tga", "foo"), mk("placeable/foo.tga", "foo")}
|
||||
entry.Assets = []string{"creature/foo.tga", "placeable/foo.tga"}
|
||||
if _, err := chunksFromManifest(collide, []BuildManifestHAK{entry}); err == nil {
|
||||
t.Fatal("expected resref+type collision rejection")
|
||||
}
|
||||
|
||||
distinct := []assetResource{mk("creature/foo.tga", "foo"), mk("placeable/bar.tga", "bar")}
|
||||
entry.Assets = []string{"creature/foo.tga", "placeable/bar.tga"}
|
||||
if _, err := chunksFromManifest(distinct, []BuildManifestHAK{entry}); err != nil {
|
||||
t.Fatalf("distinct resrefs should pack cleanly: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentAddressedBlobPath(t *testing.T) {
|
||||
root := "/var/cache/blobs"
|
||||
got, err := contentAddressedBlobPath(root, validAsset)
|
||||
|
||||
Reference in New Issue
Block a user