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

refactor: remove use of tmos "github.com/tendermint/tendermint/libs/os" #13113

Merged
merged 11 commits into from
Sep 1, 2022
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.Printfln(err.Error())
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
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.Printf(err.Error() + "\n")
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.Printf(err.Error() + "\n")
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.Printf(err.Error() + "\n")
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