diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index c4fa580bf..858db9720 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -84,6 +84,10 @@ func PreSeal(maddr address.Address, ssize uint64, sectors int, sbroot string, pr return nil, xerrors.Errorf("commit: %w", err) } + if err := sb.TrimCache(sid); err != nil { + return nil, xerrors.Errorf("trim cache: %w", err) + } + log.Warn("PreCommitOutput: ", sid, pco) sealedSectors = append(sealedSectors, &genesis.PreSeal{ CommR: pco.CommR, diff --git a/lib/sectorbuilder/files.go b/lib/sectorbuilder/files.go index c19fb3861..373741cc8 100644 --- a/lib/sectorbuilder/files.go +++ b/lib/sectorbuilder/files.go @@ -3,8 +3,10 @@ package sectorbuilder import ( "fmt" "io" + "io/ioutil" "os" "path/filepath" + "strings" "sync" "golang.org/x/xerrors" @@ -61,6 +63,33 @@ func (sb *SectorBuilder) GetPath(typ string, sectorName string) (string, error) } } +func (sb *SectorBuilder) TrimCache(sectorID uint64) error { + dir, err := sb.sectorCacheDir(sectorID) + if err != nil { + return xerrors.Errorf("getting cache dir: %w", err) + } + + files, err := ioutil.ReadDir(dir) + if err != nil { + return xerrors.Errorf("readdir: %w", err) + } + + for _, file := range files { + if !strings.HasSuffix(file.Name(), ".dat") { // _aux probably + continue + } + if strings.HasSuffix(file.Name(), "-data-tree-r-last.dat") { // Want to keep + continue + } + + if err := os.Remove(filepath.Join(dir, file.Name())); err != nil { + return xerrors.Errorf("rm %s: %w", file.Name(), err) + } + } + + return nil +} + func toReadableFile(r io.Reader, n int64) (*os.File, func() error, error) { f, ok := r.(*os.File) if ok { diff --git a/lib/sectorbuilder/sectorbuilder_test.go b/lib/sectorbuilder/sectorbuilder_test.go index cc8cb9563..36520374e 100644 --- a/lib/sectorbuilder/sectorbuilder_test.go +++ b/lib/sectorbuilder/sectorbuilder_test.go @@ -240,6 +240,10 @@ func TestSealPoStNoCommit(t *testing.T) { t.Fatalf("%+v", err) } + if err := sb.TrimCache(1); err != nil { + t.Fatal(err) + } + genCandidiates := post(t, sb, s) epost := time.Now()