Return error form Repo.Exists

This commit is contained in:
Łukasz Magiera 2019-07-23 23:54:54 +02:00
parent 4f1946d5a2
commit 4c8b028887
3 changed files with 16 additions and 4 deletions

View File

@ -21,7 +21,11 @@ var initCmd = &cli.Command{
return err return err
} }
if r.Exists() { ok, err := r.Exists()
if err != nil {
return err
}
if ok {
return xerrors.Errorf("repo at '%s' is already initialized", cctx.String(FlagStorageRepo)) return xerrors.Errorf("repo at '%s' is already initialized", cctx.String(FlagStorageRepo))
} }

View File

@ -36,7 +36,11 @@ var runCmd = &cli.Command{
return err return err
} }
if !r.Exists() { ok, err := r.Exists()
if err != nil {
return err
}
if !ok {
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String(FlagStorageRepo)) return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String(FlagStorageRepo))
} }

View File

@ -58,9 +58,13 @@ func NewFS(path string) (*FsRepo, error) {
}, nil }, nil
} }
func (fsr *FsRepo) Exists() bool { func (fsr *FsRepo) Exists() (bool, error) {
_, err := os.Stat(fsr.path) _, err := os.Stat(fsr.path)
return err == nil notexist := os.IsNotExist(err)
if notexist {
err = nil
}
return !notexist, err
} }
func (fsr *FsRepo) Init() error { func (fsr *FsRepo) Init() error {