add option to symlink to presealed sectors

This commit is contained in:
whyrusleeping 2019-12-10 18:11:59 +01:00
parent 29db00269c
commit 08cc689293
2 changed files with 68 additions and 2 deletions

View File

@ -76,12 +76,21 @@ var initCmd = &cli.Command{
Name: "nosync",
Usage: "don't check full-node sync status",
},
&cli.BoolFlag{
Name: "symlink-imported-sectors",
Usage: "attempt to symlink to presealed sectors instead of copying them into place",
},
},
Action: func(cctx *cli.Context) error {
log.Info("Initializing lotus storage miner")
ssize := cctx.Uint64("sector-size")
symlink := cctx.Bool("symlink-imported-sectors")
if symlink {
log.Info("will attempt to symlink to imported sectors")
}
log.Info("Checking proof parameters")
if err := build.GetParams(ssize); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
@ -184,7 +193,7 @@ var initCmd = &cli.Command{
return xerrors.Errorf("failed to open up sectorbuilder: %w", err)
}
if err := nsb.ImportFrom(oldsb); err != nil {
if err := nsb.ImportFrom(oldsb, symlink); err != nil {
return err
}
if err := lr.Close(); err != nil {

View File

@ -3,7 +3,9 @@ package sectorbuilder
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
@ -681,7 +683,7 @@ func fallbackPostChallengeCount(sectors uint64) uint64 {
return challengeCount
}
func (sb *SectorBuilder) ImportFrom(osb *SectorBuilder) error {
func (sb *SectorBuilder) ImportFrom(osb *SectorBuilder, symlink bool) error {
if err := dcopy.Copy(osb.cacheDir, sb.cacheDir); err != nil {
return err
}
@ -716,3 +718,58 @@ func (sb *SectorBuilder) SetLastSectorID(id uint64) error {
sb.lastID = id
return nil
}
func migrate(from, to string, symlink bool) error {
st, err := os.Stat(from)
if err != nil {
return err
}
if st.IsDir() {
return migrateDir(from, to, symlink)
}
return migrateFile(from, to, symlink)
}
func migrateDir(from, to string, symlink bool) error {
tost, err := os.Stat(to)
if err != nil {
if !os.IsNotExist(err) {
return err
}
if err := os.MkdirAll(to, 0755); err != nil {
return err
}
} else if !tost.IsDir() {
return xerrors.Errorf("target %q already exists and is a file (expected directory)")
}
dirents, err := ioutil.ReadDir(from)
if err != nil {
return err
}
for _, inf := range dirents {
n := inf.Name()
if inf.IsDir() {
if err := migrate(filepath.Join(from, n), filepath.Join(to, n), symlink); err != nil {
return err
}
} else {
if err := migrate(filepath.Join(from, n), filepath.Join(to, n), symlink); err != nil {
return err
}
}
}
return nil
}
func migrateFile(from, to string, symlink bool) error {
if symlink {
return os.Symlink(from, to)
}
return dcopy.Copy(from, to)
}