Skip to content

Commit

Permalink
Add an option to set config
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Sep 30, 2020
1 parent e250429 commit acc5a2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 8 additions & 0 deletions cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ var DaemonCmd = &cli.Command{
Usage: "manage open file limit",
Value: true,
},
&cli.StringFlag{
Name: "config",
Usage: "specify path of config file to use",
},
},
Action: func(cctx *cli.Context) error {
err := runmetrics.Enable(runmetrics.RunMetricOptions{
Expand Down Expand Up @@ -184,6 +188,10 @@ var DaemonCmd = &cli.Command{
return xerrors.Errorf("repo init error: %w", err)
}

if cctx.String("config") != "" {
r.SetConfigPath(cctx.String("config"))
}

if err := paramfetch.GetParams(lcli.ReqContext(cctx), build.ParametersJSON(), 0); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
Expand Down
34 changes: 20 additions & 14 deletions node/repo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ var ErrRepoExists = xerrors.New("repo exists")

// FsRepo is struct for repo, use NewFS to create
type FsRepo struct {
path string
path string
configPath string
}

var _ Repo = &FsRepo{}
Expand All @@ -78,10 +79,15 @@ func NewFS(path string) (*FsRepo, error) {
}

return &FsRepo{
path: path,
path: path,
configPath: filepath.Join(path, fsConfig),
}, nil
}

func (fsr *FsRepo) SetConfigPath(cfgPath string) {
fsr.configPath = cfgPath
}

func (fsr *FsRepo) Exists() (bool, error) {
_, err := os.Stat(filepath.Join(fsr.path, fsDatastore))
notexist := os.IsNotExist(err)
Expand Down Expand Up @@ -115,17 +121,15 @@ func (fsr *FsRepo) Init(t RepoType) error {
}

func (fsr *FsRepo) initConfig(t RepoType) error {
cfgP := filepath.Join(fsr.path, fsConfig)

_, err := os.Stat(cfgP)
_, err := os.Stat(fsr.configPath)
if err == nil {
// exists
return nil
} else if !os.IsNotExist(err) {
return err
}

c, err := os.Create(cfgP)
c, err := os.Create(fsr.configPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -215,16 +219,18 @@ func (fsr *FsRepo) Lock(repoType RepoType) (LockedRepo, error) {
return nil, xerrors.Errorf("could not lock the repo: %w", err)
}
return &fsLockedRepo{
path: fsr.path,
repoType: repoType,
closer: closer,
path: fsr.path,
configPath: fsr.configPath,
repoType: repoType,
closer: closer,
}, nil
}

type fsLockedRepo struct {
path string
repoType RepoType
closer io.Closer
path string
configPath string
repoType RepoType
closer io.Closer

ds map[string]datastore.Batching
dsErr error
Expand Down Expand Up @@ -277,7 +283,7 @@ func (fsr *fsLockedRepo) Config() (interface{}, error) {
}

func (fsr *fsLockedRepo) loadConfigFromDisk() (interface{}, error) {
return config.FromFile(fsr.join(fsConfig), defConfForType(fsr.repoType))
return config.FromFile(fsr.configPath, defConfForType(fsr.repoType))
}

func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error {
Expand Down Expand Up @@ -306,7 +312,7 @@ func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error {
}

// write buffer of TOML bytes to config file
err = ioutil.WriteFile(fsr.join(fsConfig), buf.Bytes(), 0644)
err = ioutil.WriteFile(fsr.configPath, buf.Bytes(), 0644)
if err != nil {
return err
}
Expand Down

0 comments on commit acc5a2d

Please sign in to comment.