Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/add repo compatibility for cli #350

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ ifdef PRIVATE_REGISTRY
endif

docker-push: docker
ifdef PRIVATE_REGISTRY
docker push $(PRIVATE_REGISTRY)/filvenus/sophon-messager:$(TAG)
else
docker push filvenus/sophon-messager:$(TAG)
docker tag filvenus/sophon-messager:$(TAG) filvenus/sophon-messager:latest
docker push filvenus/sophon-messager:latest
endif
51 changes: 50 additions & 1 deletion cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package cli

import (
"context"
"errors"
"fmt"
"os"

"github.com/filecoin-project/go-jsonrpc"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
Expand All @@ -15,6 +18,11 @@ import (
"github.com/filecoin-project/venus/venus-shared/api/messager"
)

const (
OldRepoPath = "~/.venus-messager"
DefRepoPath = "~/.sophon-messager"
)

func getAPI(ctx *cli.Context) (messager.IMessager, jsonrpc.ClientCloser, error) {
repo, err := getRepo(ctx)
if err != nil {
Expand Down Expand Up @@ -61,7 +69,7 @@ func LoadBuiltinActors(ctx context.Context, nodeAPI v1.FullNode) error {
}

func getRepo(ctx *cli.Context) (filestore.FSRepo, error) {
repoPath, err := homedir.Expand(ctx.String("repo"))
repoPath, err := GetRepoPath(ctx)
if err != nil {
return nil, err
}
Expand All @@ -71,3 +79,44 @@ func getRepo(ctx *cli.Context) (filestore.FSRepo, error) {
}
return repo, nil
}

func GetRepoPath(cctx *cli.Context) (string, error) {
repoPath, err := homedir.Expand(cctx.String("repo"))
if err != nil {
return "", err
}
has, err := hasFSRepo(repoPath)
if err != nil {
return "", err
}
if !has {
// check old repo path
rPath, err := homedir.Expand(OldRepoPath)
if err != nil {
return "", err
}
has, err = hasFSRepo(rPath)
if err != nil {
return "", err
}
if has {
return rPath, nil
}
}
return repoPath, nil
}

func hasFSRepo(repoPath string) (bool, error) {
fi, err := os.Stat(repoPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
return false, err
}
if !fi.IsDir() {
return false, fmt.Errorf("%s is not a folder", repoPath)
}

return true, nil
}
36 changes: 2 additions & 34 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/ipfs-force-community/sophon-messager/publisher"
"github.com/ipfs-force-community/sophon-messager/publisher/pubsub"
"github.com/mitchellh/go-homedir"

"github.com/filecoin-project/venus/fixtures/networks"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
Expand All @@ -38,11 +37,6 @@ import (
"github.com/ipfs-force-community/sophon-messager/version"
)

const (
oldRepoPath = "~/.venus-messager"
defRepoPath = "~/.sophon-messager"
)

var log = logging.Logger("main")

func main() {
Expand All @@ -52,7 +46,7 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Value: defRepoPath,
Value: ccli.DefRepoPath,
},
},
Commands: []*cli.Command{
Expand Down