Skip to content

Commit

Permalink
refactor: remove use of tmos "github.com/tendermint/tendermint/libs/o…
Browse files Browse the repository at this point in the history
…s" (#13113)
  • Loading branch information
facundomedica committed Sep 1, 2022
1 parent bf8f015 commit db8714d
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
7 changes: 4 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/abci/server"
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
Expand Down Expand Up @@ -229,12 +228,14 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {

err = svr.Start()
if err != nil {
tmos.Exit(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}

defer func() {
if err = svr.Stop(); err != nil {
tmos.Exit(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}
}()

Expand Down
5 changes: 3 additions & 2 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package simapp

import (
_ "embed"
"fmt"
"io"
"os"
"path/filepath"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"cosmossdk.io/depinject"
Expand Down Expand Up @@ -234,7 +234,8 @@ func NewSimApp(
// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, app.keys); err != nil {
tmos.Exit(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}

/**** Module Options ****/
Expand Down
8 changes: 5 additions & 3 deletions simapp/app_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package simapp

import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"

"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -238,7 +238,8 @@ func NewSimApp(
// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, keys); err != nil {
tmos.Exit(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}

app := &SimApp{
Expand Down Expand Up @@ -481,7 +482,8 @@ func NewSimApp(

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}
}

Expand Down
9 changes: 3 additions & 6 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"cosmossdk.io/math"
"github.com/spf13/cobra"
tmconfig "github.com/tendermint/tendermint/config"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
Expand Down Expand Up @@ -469,13 +468,11 @@ func calculateIP(ip string, i int) (string, error) {
func writeFile(name string, dir string, contents []byte) error {
file := filepath.Join(dir, name)

err := tmos.EnsureDir(dir, 0o755)
if err != nil {
return err
if err := os.MkdirAll(dir, 0o755); err != nil {
return fmt.Errorf("could not create directory %q: %w", dir, err)
}

err = os.WriteFile(file, contents, 0o644) //nolint: gosec
if err != nil {
if err := os.WriteFile(file, contents, 0o644); err != nil { //nolint: gosec
return err
}

Expand Down
10 changes: 4 additions & 6 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package network

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
Expand Down Expand Up @@ -194,13 +194,11 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance
func writeFile(name string, dir string, contents []byte) error {
file := filepath.Join(dir, name)

err := tmos.EnsureDir(dir, 0o755)
if err != nil {
return err
if err := os.MkdirAll(dir, 0o755); err != nil {
return fmt.Errorf("could not create directory %q: %w", dir, err)
}

err = os.WriteFile(file, contents, 0o644) //nolint: gosec
if err != nil {
if err := os.WriteFile(file, contents, 0o644); err != nil { //nolint: gosec
return err
}

Expand Down
5 changes: 2 additions & 3 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
tmos "github.com/tendermint/tendermint/libs/os"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -217,8 +216,8 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o

func makeOutputFilepath(rootDir, nodeID string) (string, error) {
writePath := filepath.Join(rootDir, "config", "gentx")
if err := tmos.EnsureDir(writePath, 0o700); err != nil {
return "", err
if err := os.MkdirAll(writePath, 0o700); err != nil {
return "", fmt.Errorf("could not create directory %q: %w", writePath, err)
}

return filepath.Join(writePath, fmt.Sprintf("gentx-%v.json", nodeID)), nil
Expand Down
5 changes: 3 additions & 2 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"

Expand Down Expand Up @@ -118,7 +117,9 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)
stakingBondDenom, _ := cmd.Flags().GetString(FlagStakingBondDenom)

if !overwrite && tmos.FileExists(genFile) {
// use os.Stat to check if the file exists
_, err = os.Stat(genFile)
if !overwrite && !os.IsNotExist(err) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}

Expand Down
4 changes: 2 additions & 2 deletions x/genutil/types/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package types
import (
"encoding/json"
"fmt"
"os"

tmos "github.com/tendermint/tendermint/libs/os"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -78,7 +78,7 @@ func GenesisStateFromGenDoc(genDoc tmtypes.GenesisDoc) (genesisState map[string]
//
// NOTE: The pubkey input is this machines pubkey.
func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genDoc *tmtypes.GenesisDoc, err error) {
if !tmos.FileExists(genFile) {
if _, err := os.Stat(genFile); os.IsNotExist(err) {
return genesisState, genDoc,
fmt.Errorf("%s does not exist, run `init` first", genFile)
}
Expand Down
10 changes: 5 additions & 5 deletions x/genutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package genutil
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

"github.com/cosmos/go-bip39"
cfg "github.com/tendermint/tendermint/config"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -67,13 +67,13 @@ func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic strin
nodeID = string(nodeKey.ID())

pvKeyFile := config.PrivValidatorKeyFile()
if err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0o777); err != nil {
return "", nil, err
if err := os.MkdirAll(filepath.Dir(pvKeyFile), 0o777); err != nil {
return "", nil, fmt.Errorf("could not create directory %q: %w", filepath.Dir(pvKeyFile), err)
}

pvStateFile := config.PrivValidatorStateFile()
if err := tmos.EnsureDir(filepath.Dir(pvStateFile), 0o777); err != nil {
return "", nil, err
if err := os.MkdirAll(filepath.Dir(pvStateFile), 0o777); err != nil {
return "", nil, fmt.Errorf("could not create directory %q: %w", filepath.Dir(pvStateFile), err)
}

var filePV *privval.FilePV
Expand Down
7 changes: 3 additions & 4 deletions x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package keeper
import (
"encoding/binary"
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"sort"

"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"

storetypes "github.com/cosmos/cosmos-sdk/store/types"

Expand Down Expand Up @@ -393,9 +393,8 @@ func (k Keeper) DumpUpgradeInfoToDisk(height int64, p types.Plan) error {
// GetUpgradeInfoPath returns the upgrade info file path
func (k Keeper) GetUpgradeInfoPath() (string, error) {
upgradeInfoFileDir := path.Join(k.getHomeDir(), "data")
err := tmos.EnsureDir(upgradeInfoFileDir, os.ModePerm)
if err != nil {
return "", err
if err := os.MkdirAll(upgradeInfoFileDir, os.ModePerm); err != nil {
return "", fmt.Errorf("could not create directory %q: %w", upgradeInfoFileDir, err)
}

return filepath.Join(upgradeInfoFileDir, types.UpgradeInfoFilename), nil
Expand Down

0 comments on commit db8714d

Please sign in to comment.