From 4c8b0288876cfe1d02117fbe9db45aa2cf13a484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 23 Jul 2019 23:54:54 +0200 Subject: [PATCH] Return error form Repo.Exists --- cmd/lotus-storage-miner/init.go | 6 +++++- cmd/lotus-storage-miner/run.go | 6 +++++- node/repo/fsrepo.go | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index e1cc6adb9..b9a0618ab 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -21,7 +21,11 @@ var initCmd = &cli.Command{ 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)) } diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 1c6aa0a6a..16cd34515 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -36,7 +36,11 @@ var runCmd = &cli.Command{ 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)) } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 72e0e6173..a506e6e8e 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -58,9 +58,13 @@ func NewFS(path string) (*FsRepo, error) { }, nil } -func (fsr *FsRepo) Exists() bool { +func (fsr *FsRepo) Exists() (bool, error) { _, err := os.Stat(fsr.path) - return err == nil + notexist := os.IsNotExist(err) + if notexist { + err = nil + } + return !notexist, err } func (fsr *FsRepo) Init() error {