Skip to content

Commit

Permalink
range-export: write files to lotus repo path
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Feb 14, 2023
1 parent 1cb7072 commit dda703d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 1 addition & 5 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ var ChainExportCmd = &cli.Command{
var ChainExportRangeCmd = &cli.Command{
Name: "export-range",
Usage: "export chain to a car file",
ArgsUsage: "[outputPath]",
ArgsUsage: "",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "head",
Expand Down Expand Up @@ -1202,10 +1202,6 @@ var ChainExportRangeCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)

if !cctx.Args().Present() {
return fmt.Errorf("must specify filename to export chain to")
}

head, tail := &types.TipSet{}, &types.TipSet{}
headstr := cctx.String("head")
if headstr == "@head" {
Expand Down
8 changes: 5 additions & 3 deletions node/impl/full/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/filecoin-project/lotus/lib/oldpath"
"github.com/filecoin-project/lotus/lib/oldpath/oldresolver"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo"
)

var log = logging.Logger("fullnode")
Expand Down Expand Up @@ -93,6 +94,8 @@ type ChainAPI struct {

// BaseBlockstore is the underlying blockstore
BaseBlockstore dtypes.BaseBlockstore

Repo repo.LockedRepo
}

func (m *ChainModule) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) {
Expand Down Expand Up @@ -606,8 +609,7 @@ func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types
return xerrors.Errorf("Height of head-tipset (%d) must be greater or equal to the height of the tail-tipset (%d)", headTs.Height(), tailTs.Height())
}

fileName := fmt.Sprintf("./snapshot_%d_%d_%d.car", tailTs.Height(), headTs.Height(), time.Now().Unix())
absFileName, err := filepath.Abs(fileName)
fileName := filepath.Join(a.Repo.Path(), fmt.Sprintf("snapshot_%d_%d_%d.car", tailTs.Height(), headTs.Height(), time.Now().Unix()))
if err != nil {
return err
}
Expand All @@ -617,7 +619,7 @@ func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types
return err
}

log.Infow("Exporting chain range", "path", absFileName)
log.Infow("Exporting chain range", "path", fileName)
// buffer writes to the chain export file.
bw := bufio.NewWriterSize(f, cfg.WriteBufferSize)

Expand Down

0 comments on commit dda703d

Please sign in to comment.