refactor: remove use of tmos "github.com/tendermint/tendermint/libs/os" (#13113)
This commit is contained in:
parent
bf8f015797
commit
db8714da9e
@ -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"
|
||||
@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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 ****/
|
||||
|
||||
@ -4,6 +4,7 @@ package simapp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -11,7 +12,6 @@ import (
|
||||
"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"
|
||||
@ -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{
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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"
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user