Commit d9cc96c5 authored by Łukasz Magiera's avatar Łukasz Magiera
Browse files

More correct cache cleanup in PreCommit

parent 99304d84
...@@ -5,6 +5,7 @@ package sectorbuilder ...@@ -5,6 +5,7 @@ package sectorbuilder
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
"os" "os"
"sync/atomic" "sync/atomic"
...@@ -142,15 +143,16 @@ func (sb *SectorBuilder) SealPreCommit(ctx context.Context, sectorID uint64, tic ...@@ -142,15 +143,16 @@ func (sb *SectorBuilder) SealPreCommit(ctx context.Context, sectorID uint64, tic
return RawSealPreCommitOutput{}, xerrors.Errorf("getting cache dir: %w", err) return RawSealPreCommitOutput{}, xerrors.Errorf("getting cache dir: %w", err)
} }
if _, err := os.Stat(cacheDir); !os.IsNotExist(err) { cached, err := ioutil.ReadDir(cacheDir)
if err != nil {
return RawSealPreCommitOutput{}, xerrors.Errorf("reading cache dir: %w", err)
}
if len(cached) > 0 {
// TODO: can we read t_aux or p_aux to check if we have the correct thing sealed here already? // TODO: can we read t_aux or p_aux to check if we have the correct thing sealed here already?
// (need to check ticket) // (need to check ticket)
if err != nil { log.Warnf("precommit: cache dir %s contains files %v, cleaning up", cacheDir, cached)
return RawSealPreCommitOutput{}, xerrors.Errorf("stat cache dir: %w", err)
}
log.Warnf("precommit: found cache dir %s, cleaning up", cacheDir)
if err := os.RemoveAll(cacheDir); err != nil { if err := os.RemoveAll(cacheDir); err != nil {
return RawSealPreCommitOutput{}, xerrors.Errorf("removing cache dir %s: %w", cacheDir, err) return RawSealPreCommitOutput{}, xerrors.Errorf("removing cache dir %s: %w", cacheDir, err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment