From c9511001dbb510e8a82bcad707ee3dab912eec8b Mon Sep 17 00:00:00 2001 From: s7v7nislands Date: Sun, 24 Apr 2022 16:49:50 +0800 Subject: [PATCH] all: use common package --- build/ci.go | 5 +++-- cmd/geth/consolecmd.go | 4 ++-- cmd/utils/flags.go | 2 +- core/state/pruner/pruner.go | 2 +- core/tx_journal.go | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build/ci.go b/build/ci.go index 5c7269925b7..11245563176 100644 --- a/build/ci.go +++ b/build/ci.go @@ -59,6 +59,7 @@ import ( "time" "github.com/cespare/cp" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto/signify" "github.com/ethereum/go-ethereum/internal/build" "github.com/ethereum/go-ethereum/params" @@ -163,7 +164,7 @@ func executablePath(name string) string { func main() { log.SetFlags(log.Lshortfile) - if _, err := os.Stat(filepath.Join("build", "ci.go")); os.IsNotExist(err) { + if !common.FileExist(filepath.Join("build", "ci.go")) { log.Fatal("this script must be run from the root of the repository") } if len(os.Args) < 2 { @@ -733,7 +734,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) { var idfile string if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 { idfile = filepath.Join(workdir, "sshkey") - if _, err := os.Stat(idfile); os.IsNotExist(err) { + if !common.FileExist(idfile) { ioutil.WriteFile(idfile, sshkey, 0600) } } diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 7a0135b9a19..efe3e2110b4 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -18,11 +18,11 @@ package main import ( "fmt" - "os" "path/filepath" "strings" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" @@ -130,7 +130,7 @@ func remoteConsole(ctx *cli.Context) error { // Maintain compatibility with older Geth configurations storing the // Ropsten database in `testnet` instead of `ropsten`. legacyPath := filepath.Join(path, "testnet") - if _, err := os.Stat(legacyPath); !os.IsNotExist(err) { + if common.FileExist(legacyPath) { path = legacyPath } else { path = filepath.Join(path, "ropsten") diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1fb48973244..f6e7a215d85 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1338,7 +1338,7 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) { // Maintain compatibility with older Geth configurations storing the // Ropsten database in `testnet` instead of `ropsten`. legacyPath := filepath.Join(node.DefaultDataDir(), "testnet") - if _, err := os.Stat(legacyPath); !os.IsNotExist(err) { + if common.FileExist(legacyPath) { log.Warn("Using the deprecated `testnet` datadir. Future versions will store the Ropsten chain in `ropsten`.") cfg.DataDir = legacyPath } else { diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index 4e3daac669b..a2f8afc90e3 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -497,7 +497,7 @@ Check the command description "geth snapshot prune-state --help" for more detail ` func deleteCleanTrieCache(path string) { - if _, err := os.Stat(path); os.IsNotExist(err) { + if !common.FileExist(path) { log.Warn(warningLog) return } diff --git a/core/tx_journal.go b/core/tx_journal.go index d282126a083..5453ee19165 100644 --- a/core/tx_journal.go +++ b/core/tx_journal.go @@ -58,7 +58,7 @@ func newTxJournal(path string) *txJournal { // the specified pool. func (journal *txJournal) load(add func([]*types.Transaction) []error) error { // Skip the parsing if the journal file doesn't exist at all - if _, err := os.Stat(journal.path); os.IsNotExist(err) { + if !common.FileExist(journal.path) { return nil } // Open the journal for loading any past transactions