internal/pkg: populate substitute status
All checks were successful
Test / Hakurei (push) Successful in 58s
Test / Sandbox (push) Successful in 53s
Test / Sandbox (race detector) (push) Successful in 51s
Test / Hakurei (race detector) (push) Successful in 57s
Test / ShareFS (push) Successful in 42s
Test / Create distribution (push) Successful in 1m9s
Test / Flake checks (push) Successful in 1m36s

These are not created when taking the fast path, but should be inherited from the alternative.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-13 16:16:37 +09:00
parent 19555c7670
commit f63203cb0a
2 changed files with 44 additions and 21 deletions

View File

@@ -509,36 +509,32 @@ const (
) )
const ( const (
// fileLock is the file name appended to Cache.base for guaranteeing // fileLock is the lock file for exclusive access to the cache directory.
// exclusive access to the cache directory.
fileLock = "lock" fileLock = "lock"
// fileVariant is the file name appended to Cache.base holding the variant // fileVariant is a file holding the variant identification string set by a
// identification string set by a prior call to [SetExtension]. // prior call to [SetExtension].
fileVariant = "variant" fileVariant = "variant"
// dirSubstitute is the directory name appended to Cache.base for linking // dirSubstitute holds symlinks to artifacts by checksum, named after their
// artifacts named after their substitute identifier. // substitute identifier.
dirSubstitute = "substitute" dirSubstitute = "substitute"
// dirIdentifier is the directory name appended to Cache.base for storing // dirIdentifier holds symlinks to artifacts by checksum, named after their
// artifacts named after their [ID]. // IR-based identifier.
dirIdentifier = "identifier" dirIdentifier = "identifier"
// dirChecksum is the directory name appended to Cache.base for storing // dirChecksum holds artifacts named after their [Checksum].
// artifacts named after their [Checksum].
dirChecksum = "checksum" dirChecksum = "checksum"
// dirStatus is the directory name appended to Cache.base for storing // dirStatus holds artifact metadata and logs named after their IR-based
// artifact metadata and logs named after their [ID]. // identifier. For [FloodArtifact], the same file is also available under
// its substitute identifier.
dirStatus = "status" dirStatus = "status"
// dirWork is the directory name appended to Cache.base for working // dirWork holds working pathnames set up during [Cache.Cure].
// pathnames set up during [Cache.Cure].
dirWork = "work" dirWork = "work"
// dirTemp is the directory name appended to Cache.base for scratch space // dirTemp holds scratch space allocated during [Cache.Cure].
// pathnames allocated during [Cache.Cure].
dirTemp = "temp" dirTemp = "temp"
// dirExecScratch is the directory name appended to Cache.base for scratch // dirExecScratch is scratch space set up for the container started by
// space setting up the container started by [Cache.EnterExec]. Exclusivity // [Cache.EnterExec]. Exclusivity via Cache.inExec.
// via Cache.inExec.
dirExecScratch = "scratch" dirExecScratch = "scratch"
// checksumLinknamePrefix is prepended to the encoded [Checksum] value // checksumLinknamePrefix is prepended to the encoded [Checksum] value
@@ -1995,10 +1991,11 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
buf := c.getIdentBuf() buf := c.getIdentBuf()
sh.Sum(buf[wordSize:wordSize]) sh.Sum(buf[wordSize:wordSize])
substitute = unique.Make(ID(buf[wordSize:])) substitute = unique.Make(ID(buf[wordSize:]))
substitutes := Encode(substitute.Value())
c.putIdentBuf(buf) c.putIdentBuf(buf)
alternative = c.base.Append( alternative = c.base.Append(
dirSubstitute, dirSubstitute,
Encode(substitute.Value()), substitutes,
) )
if c.flags&CIgnoreSubstitutes == 0 { if c.flags&CIgnoreSubstitutes == 0 {
@@ -2014,6 +2011,17 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
dirChecksum, dirChecksum,
checksums, checksums,
) )
if _, err = os.Lstat(c.base.Append(
dirStatus,
substitutes,
).String()); err == nil {
err = os.Symlink(substitutes, c.base.Append(
dirStatus,
ids,
).String())
} else if errors.Is(err, os.ErrNotExist) {
err = nil
}
return return
} }
} }
@@ -2023,6 +2031,15 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
return return
} }
err = ca.Cure(&f) err = ca.Cure(&f)
if err == nil && f.status != nil {
err = os.Link(c.base.Append(
dirStatus,
ids,
).String(), c.base.Append(
dirStatus,
substitutes,
).String())
}
c.exitCure(a, curesExempt) c.exitCure(a, curesExempt)
if err != nil { if err != nil {
return return

View File

@@ -1059,8 +1059,14 @@ func TestCache(t *testing.T) {
"_EmV5nsYZ2UWHgRmLDMU8i-rJWDx-kv5_1pFrzQI7vMMCM5mAXivO8UZtVfOqMR_", "_EmV5nsYZ2UWHgRmLDMU8i-rJWDx-kv5_1pFrzQI7vMMCM5mAXivO8UZtVfOqMR_",
), want, nil}, ), want, nil},
}) })
} }
if dents, err := os.ReadDir(base.Append("status").String()); err != nil {
t.Fatal(err)
} else if len(dents) > 0 {
t.Errorf("ReadDir: %v", dents)
}
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},