internal/pkg: check for unclean shutdown
Test / Create distribution (push) Successful in 57s
Test / Sandbox (push) Successful in 2m53s
Test / ShareFS (push) Successful in 3m54s
Test / Hakurei (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 5m41s
Test / Hakurei (race detector) (push) Successful in 6m34s
Test / Flake checks (push) Successful in 1m13s
Test / Create distribution (push) Successful in 57s
Test / Sandbox (push) Successful in 2m53s
Test / ShareFS (push) Successful in 3m54s
Test / Hakurei (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 5m41s
Test / Hakurei (race detector) (push) Successful in 6m34s
Test / Flake checks (push) Successful in 1m13s
This avoids running into nasty surprises opening a cache that suffered unclean shutdown due to power loss. All other parts of the cache are not prone to inconsistent state. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -2443,6 +2443,37 @@ func open(
|
||||
c.unlock = func() {}
|
||||
}
|
||||
|
||||
for _, name := range []string{
|
||||
dirWork,
|
||||
dirTemp,
|
||||
} {
|
||||
dents, err := os.ReadDir(base.Append(name).String())
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
}
|
||||
c.unlock()
|
||||
return nil, err
|
||||
}
|
||||
if len(dents) != 0 {
|
||||
c.unlock()
|
||||
return nil, fmt.Errorf(
|
||||
"%s is not empty, scrub likely required",
|
||||
name,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.ReadDir(base.Append(
|
||||
dirExecScratch,
|
||||
).String()); !errors.Is(err, os.ErrNotExist) {
|
||||
c.unlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errors.New(dirExecScratch + " is present, scrub likely required")
|
||||
}
|
||||
|
||||
variantPath := base.Append(fileVariant).String()
|
||||
if p, err := os.ReadFile(variantPath); err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
|
||||
Reference in New Issue
Block a user