internal/pkg: tar optional file
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m49s
Test / ShareFS (push) Successful in 4m46s
Test / Sandbox (race detector) (push) Successful in 5m17s
Test / Hpkg (push) Successful in 5m19s
Test / Hakurei (push) Successful in 5m31s
Test / Hakurei (race detector) (push) Successful in 7m27s
Test / Flake checks (push) Successful in 1m39s

This allows tar to take a single-file directory Artifact as input.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-07 22:15:55 +09:00
parent e8dda70c41
commit c86ff02d8d
5 changed files with 187 additions and 55 deletions

View File

@@ -117,6 +117,59 @@ func newStubFile(
}
}
// destroyArtifact removes all traces of an [Artifact] from the on-disk cache.
// Do not use this in a test case without a very good reason to do so.
func destroyArtifact(
t *testing.T,
base *check.Absolute,
c *pkg.Cache,
a pkg.Artifact,
) {
if pathname, checksum, err := c.Cure(a); err != nil {
t.Fatalf("Cure: error = %v", err)
} else if err = os.Remove(pathname.String()); err != nil {
t.Fatal(err)
} else {
p := base.Append(
"checksum",
pkg.Encode(checksum),
)
if err = filepath.WalkDir(p.String(), func(
path string,
d fs.DirEntry,
err error,
) error {
if err != nil {
return err
}
if d.IsDir() {
return os.Chmod(path, 0700)
}
return nil
}); err != nil && !errors.Is(err, os.ErrNotExist) {
t.Fatal(err)
}
if err = os.RemoveAll(p.String()); err != nil {
t.Fatal(err)
}
}
}
// newDestroyArtifactFunc returns a function that calls destroyArtifact.
func newDestroyArtifactFunc(a pkg.Artifact) func(
t *testing.T,
base *check.Absolute,
c *pkg.Cache,
) {
return func(
t *testing.T,
base *check.Absolute,
c *pkg.Cache,
) {
destroyArtifact(t, base, c, a)
}
}
func TestIdent(t *testing.T) {
t.Parallel()