Skip to content

Commit 504b978

Browse files
s7v7nislandssadoci
authored andcommitted
all: use common.FileExist for checking file existence (ethereum#24748)
1 parent 1e15ffd commit 504b978

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

build/ci.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import (
5858
"time"
5959

6060
"github.com/cespare/cp"
61+
"github.com/ethereum/go-ethereum/common"
6162
"github.com/ethereum/go-ethereum/crypto/signify"
6263
"github.com/ethereum/go-ethereum/internal/build"
6364
"github.com/ethereum/go-ethereum/params"
@@ -162,7 +163,7 @@ func executablePath(name string) string {
162163
func main() {
163164
log.SetFlags(log.Lshortfile)
164165

165-
if _, err := os.Stat(filepath.Join("build", "ci.go")); os.IsNotExist(err) {
166+
if !common.FileExist(filepath.Join("build", "ci.go")) {
166167
log.Fatal("this script must be run from the root of the repository")
167168
}
168169
if len(os.Args) < 2 {
@@ -743,7 +744,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) {
743744
var idfile string
744745
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
745746
idfile = filepath.Join(workdir, "sshkey")
746-
if _, err := os.Stat(idfile); os.IsNotExist(err) {
747+
if !common.FileExist(idfile) {
747748
ioutil.WriteFile(idfile, sshkey, 0600)
748749
}
749750
}

cmd/geth/consolecmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ package main
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path/filepath"
2322
"strings"
2423

2524
"github.com/ethereum/go-ethereum/cmd/utils"
25+
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/console"
2727
"github.com/ethereum/go-ethereum/node"
2828
"github.com/ethereum/go-ethereum/rpc"
@@ -130,7 +130,7 @@ func remoteConsole(ctx *cli.Context) error {
130130
// Maintain compatibility with older Geth configurations storing the
131131
// Ropsten database in `testnet` instead of `ropsten`.
132132
legacyPath := filepath.Join(path, "testnet")
133-
if _, err := os.Stat(legacyPath); !os.IsNotExist(err) {
133+
if common.FileExist(legacyPath) {
134134
path = legacyPath
135135
} else {
136136
path = filepath.Join(path, "ropsten")

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
14251425
// Maintain compatibility with older Geth configurations storing the
14261426
// Ropsten database in `testnet` instead of `ropsten`.
14271427
legacyPath := filepath.Join(node.DefaultDataDir(), "testnet")
1428-
if _, err := os.Stat(legacyPath); !os.IsNotExist(err) {
1428+
if common.FileExist(legacyPath) {
14291429
log.Warn("Using the deprecated `testnet` datadir. Future versions will store the Ropsten chain in `ropsten`.")
14301430
cfg.DataDir = legacyPath
14311431
} else {

core/state/pruner/pruner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ Check the command description "geth snapshot prune-state --help" for more detail
497497
`
498498

499499
func deleteCleanTrieCache(path string) {
500-
if _, err := os.Stat(path); os.IsNotExist(err) {
500+
if !common.FileExist(path) {
501501
log.Warn(warningLog)
502502
return
503503
}

core/tx_journal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func newTxJournal(path string) *txJournal {
5858
// the specified pool.
5959
func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
6060
// Skip the parsing if the journal file doesn't exist at all
61-
if _, err := os.Stat(journal.path); os.IsNotExist(err) {
61+
if !common.FileExist(journal.path) {
6262
return nil
6363
}
6464
// Open the journal for loading any past transactions

0 commit comments

Comments
 (0)