internal/pkg: create work directory
All checks were successful
Test / Sandbox (race detector) (push) Successful in 4m50s
Test / Flake checks (push) Successful in 1m43s
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m39s
Test / Hakurei (push) Successful in 3m35s
Test / ShareFS (push) Successful in 3m38s
Test / Hpkg (push) Successful in 4m15s
Test / Hakurei (race detector) (push) Successful in 5m50s

This is used for artifacts that cure into directories.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-03 20:56:11 +09:00
parent 55465c6e72
commit deda16da38
4 changed files with 22 additions and 7 deletions

View File

@@ -23,11 +23,13 @@ func TestFlatten(t *testing.T) {
".": {Mode: 020000000700},
"checksum": {Mode: 020000000700},
"identifier": {Mode: 020000000700},
"work": {Mode: 020000000700},
}, []pkg.FlatEntry{
{Mode: 020000000700, Path: "."},
{Mode: 020000000700, Path: "checksum"},
{Mode: 020000000700, Path: "identifier"},
}, pkg.MustDecode("ANVz3GwS4oTcFTOjbc-n_N6MtycCtkELMBJB0ohuRz02PtmWZEJF8v3I51DtM0CY")},
{Mode: 020000000700, Path: "work"},
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
{"sample cache file", fstest.MapFS{
".": {Mode: 020000000700},
@@ -41,6 +43,8 @@ func TestFlatten(t *testing.T) {
"identifier/0bSFPu5Tnd-2Jj0Mv6co23PW2t3BmHc7eLFj9TgY3eIBg8zislo7xZYNBqovVLcq": {Mode: 0400, Data: []byte{0, 0, 0, 0, 0xad, 0xb, 0, 4, 0xfe, 0xfe, 0, 0, 0xfe, 0xca, 0, 0}},
"identifier/cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe": {Mode: 0400, Data: []byte{0, 0, 0, 0, 0xad, 0xb, 0, 4, 0xfe, 0xfe, 0, 0, 0xfe, 0xca, 0, 0}},
"identifier/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef": {Mode: 0400, Data: []byte{0, 0, 0, 0, 0xad, 0xb, 0, 4, 0xfe, 0xfe, 0, 0, 0xfe, 0xca, 0, 0}},
"work": {Mode: 020000000700},
}, []pkg.FlatEntry{
{Mode: 020000000700, Path: "."},
@@ -53,7 +57,9 @@ func TestFlatten(t *testing.T) {
{Mode: 0400, Path: "identifier/cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe", Data: []byte{0, 0, 0, 0, 0xad, 0xb, 0, 4, 0xfe, 0xfe, 0, 0, 0xfe, 0xca, 0, 0}},
{Mode: 0400, Path: "identifier/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", Data: []byte{0, 0, 0, 0, 0xad, 0xb, 0, 4, 0xfe, 0xfe, 0, 0, 0xfe, 0xca, 0, 0}},
{Mode: 0400, Path: "identifier/vsAhtPNo4waRNOASwrQwcIPTqb3SBuJOXw2G4T1mNmVZM-wrQTRllmgXqcIIoRcX", Data: []byte{0}},
}, pkg.MustDecode("ZNSQH-mjhtIbFvi51lQ0UjatjoS8_5ILrBPNWlO2LWTq9P6MJEnekYzP0esUJnVr")},
{Mode: 020000000700, Path: "work"},
}, pkg.MustDecode("G4u4W77C3u46oSAzwPTERKbS9h76iIvcd7Zl8p8Y6hTMb4_QGpH0Glg_DIJg-Usa")},
{"sample load or store", fstest.MapFS{
".": {Mode: 020000000700},
@@ -63,6 +69,8 @@ func TestFlatten(t *testing.T) {
"identifier": {Mode: 020000000700},
"identifier/fLYGIMHgN1louE-JzITJZJo2SDniPu-IHBXubtvQWFO-hXnDVKNuscV7-zlyr5fU": {Mode: 0400, Data: []byte("\x7f\xe1\x69\xa2\xdd\x63\x96\x26\x83\x79\x61\x8b\xf0\x3f\xd5\x16\x9a\x39\x3a\xdb\xcf\xb1\xbc\x8d\x33\xff\x75\xee\x62\x56\xa9\xf0\x27\xac\x13\x94\x69")},
"work": {Mode: 020000000700},
}, []pkg.FlatEntry{
{Mode: 020000000700, Path: "."},
@@ -71,7 +79,9 @@ func TestFlatten(t *testing.T) {
{Mode: 020000000700, Path: "identifier"},
{Mode: 0400, Path: "identifier/fLYGIMHgN1louE-JzITJZJo2SDniPu-IHBXubtvQWFO-hXnDVKNuscV7-zlyr5fU", Data: []byte("\x7f\xe1\x69\xa2\xdd\x63\x96\x26\x83\x79\x61\x8b\xf0\x3f\xd5\x16\x9a\x39\x3a\xdb\xcf\xb1\xbc\x8d\x33\xff\x75\xee\x62\x56\xa9\xf0\x27\xac\x13\x94\x69")},
}, pkg.MustDecode("5ns3Ky8-n_pETpwO3UYA88FKKLins6kxtgRQBEfSiGIpZXu6QCBOW2ukm-nWnUwC")},
{Mode: 020000000700, Path: "work"},
}, pkg.MustDecode("bAJdeuI2cITlff5uIDbMKIiaW6zB-_XGinOMOMjNmltL3YAanXLiV64_jsXeQMXn")},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

View File

@@ -65,7 +65,7 @@ func TestHTTP(t *testing.T) {
} else if gotIdent := f.ID(); gotIdent != (pkg.Checksum{}) {
t.Fatalf("ID: %x, want %x", gotIdent, pkg.Checksum{})
}
}, pkg.MustDecode("ANVz3GwS4oTcFTOjbc-n_N6MtycCtkELMBJB0ohuRz02PtmWZEJF8v3I51DtM0CY")},
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
{"load or store", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
f, err := c.NewHTTPGet(&client, "file:///testdata", testdataChecksum)
@@ -120,7 +120,7 @@ func TestHTTP(t *testing.T) {
} else if gotIdent := f.ID(); gotIdent != (pkg.Checksum{}) {
t.Fatalf("ID: %x, want %x", gotIdent, pkg.Checksum{})
}
}, pkg.MustDecode("5ns3Ky8-n_pETpwO3UYA88FKKLins6kxtgRQBEfSiGIpZXu6QCBOW2ukm-nWnUwC")},
}, pkg.MustDecode("bAJdeuI2cITlff5uIDbMKIiaW6zB-_XGinOMOMjNmltL3YAanXLiV64_jsXeQMXn")},
{"store", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
var (
@@ -149,6 +149,6 @@ func TestHTTP(t *testing.T) {
} else if checksum != testdataChecksum {
t.Fatalf("Hash: %x, want %x", checksum, testdataChecksum)
}
}, pkg.MustDecode("5ns3Ky8-n_pETpwO3UYA88FKKLins6kxtgRQBEfSiGIpZXu6QCBOW2ukm-nWnUwC")},
}, pkg.MustDecode("bAJdeuI2cITlff5uIDbMKIiaW6zB-_XGinOMOMjNmltL3YAanXLiV64_jsXeQMXn")},
})
}

View File

@@ -78,6 +78,10 @@ const (
// dirChecksum is the directory name appended to Cache.base for storing
// artifacts named after their [Checksum].
dirChecksum = "checksum"
// dirWork is the directory name appended to Cache.base for working
// directories created for [Cache.Store].
dirWork = "work"
)
// Cache is a support layer that implementations of [Artifact] can use to store
@@ -235,6 +239,7 @@ func New(base *check.Absolute) (*Cache, error) {
for _, name := range []string{
dirIdentifier,
dirChecksum,
dirWork,
} {
if err := os.MkdirAll(base.Append(name).String(), 0700); err != nil &&
!errors.Is(err, os.ErrExist) {

View File

@@ -263,7 +263,7 @@ func TestCache(t *testing.T) {
if _, _, err := c.LoadFile(zeroIdent); !reflect.DeepEqual(err, wantErrNonexistentZero) {
t.Fatalf("LoadFile: error = %#v, want %#v", err, wantErrNonexistentZero)
}
}, pkg.MustDecode("ZNSQH-mjhtIbFvi51lQ0UjatjoS8_5ILrBPNWlO2LWTq9P6MJEnekYzP0esUJnVr")},
}, pkg.MustDecode("G4u4W77C3u46oSAzwPTERKbS9h76iIvcd7Zl8p8Y6hTMb4_QGpH0Glg_DIJg-Usa")},
}
checkWithCache(t, testCases)
}