Unverified Commit 5a584c21 authored by s7v7nislands's avatar s7v7nislands Committed by GitHub

all: use common.FileExist for checking file existence (#24748)

parent c3a5054c
...@@ -59,6 +59,7 @@ import ( ...@@ -59,6 +59,7 @@ import (
"time" "time"
"github.com/cespare/cp" "github.com/cespare/cp"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/signify" "github.com/ethereum/go-ethereum/crypto/signify"
"github.com/ethereum/go-ethereum/internal/build" "github.com/ethereum/go-ethereum/internal/build"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
...@@ -163,7 +164,7 @@ func executablePath(name string) string { ...@@ -163,7 +164,7 @@ func executablePath(name string) string {
func main() { func main() {
log.SetFlags(log.Lshortfile) 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") log.Fatal("this script must be run from the root of the repository")
} }
if len(os.Args) < 2 { if len(os.Args) < 2 {
...@@ -733,7 +734,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) { ...@@ -733,7 +734,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) {
var idfile string var idfile string
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 { if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
idfile = filepath.Join(workdir, "sshkey") idfile = filepath.Join(workdir, "sshkey")
if _, err := os.Stat(idfile); os.IsNotExist(err) { if !common.FileExist(idfile) {
ioutil.WriteFile(idfile, sshkey, 0600) ioutil.WriteFile(idfile, sshkey, 0600)
} }
} }
......
...@@ -18,11 +18,11 @@ package main ...@@ -18,11 +18,11 @@ package main
import ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -130,7 +130,7 @@ func remoteConsole(ctx *cli.Context) error { ...@@ -130,7 +130,7 @@ func remoteConsole(ctx *cli.Context) error {
// Maintain compatibility with older Geth configurations storing the // Maintain compatibility with older Geth configurations storing the
// Ropsten database in `testnet` instead of `ropsten`. // Ropsten database in `testnet` instead of `ropsten`.
legacyPath := filepath.Join(path, "testnet") legacyPath := filepath.Join(path, "testnet")
if _, err := os.Stat(legacyPath); !os.IsNotExist(err) { if common.FileExist(legacyPath) {
path = legacyPath path = legacyPath
} else { } else {
path = filepath.Join(path, "ropsten") path = filepath.Join(path, "ropsten")
......
...@@ -1337,7 +1337,7 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) { ...@@ -1337,7 +1337,7 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
// Maintain compatibility with older Geth configurations storing the // Maintain compatibility with older Geth configurations storing the
// Ropsten database in `testnet` instead of `ropsten`. // Ropsten database in `testnet` instead of `ropsten`.
legacyPath := filepath.Join(node.DefaultDataDir(), "testnet") 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`.") log.Warn("Using the deprecated `testnet` datadir. Future versions will store the Ropsten chain in `ropsten`.")
cfg.DataDir = legacyPath cfg.DataDir = legacyPath
} else { } else {
......
...@@ -497,7 +497,7 @@ Check the command description "geth snapshot prune-state --help" for more detail ...@@ -497,7 +497,7 @@ Check the command description "geth snapshot prune-state --help" for more detail
` `
func deleteCleanTrieCache(path string) { func deleteCleanTrieCache(path string) {
if _, err := os.Stat(path); os.IsNotExist(err) { if !common.FileExist(path) {
log.Warn(warningLog) log.Warn(warningLog)
return return
} }
......
...@@ -58,7 +58,7 @@ func newTxJournal(path string) *txJournal { ...@@ -58,7 +58,7 @@ func newTxJournal(path string) *txJournal {
// the specified pool. // the specified pool.
func (journal *txJournal) load(add func([]*types.Transaction) []error) error { func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
// Skip the parsing if the journal file doesn't exist at all // 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 return nil
} }
// Open the journal for loading any past transactions // Open the journal for loading any past transactions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment