Skip to content

Commit 58d6ec6

Browse files
committed
Merge pull request ethereum#933 from bas-vk/issue928
replaced path with platform aware filepath module
2 parents f87094b + 899df30 commit 58d6ec6

File tree

18 files changed

+58
-64
lines changed

18 files changed

+58
-64
lines changed

cmd/geth/js.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"fmt"
2323
"math/big"
2424
"os"
25-
"path"
25+
"path/filepath"
2626
"strings"
2727

2828
"github.com/ethereum/go-ethereum/cmd/utils"
@@ -209,7 +209,7 @@ func (self *jsre) interactive() {
209209
}
210210

211211
func (self *jsre) withHistory(op func(*os.File)) {
212-
hist, err := os.OpenFile(path.Join(self.ethereum.DataDir, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
212+
hist, err := os.OpenFile(filepath.Join(self.ethereum.DataDir, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
213213
if err != nil {
214214
fmt.Printf("unable to open history file: %v\n", err)
215215
return

cmd/geth/js_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7-
"path"
87
"path/filepath"
98
"regexp"
109
"runtime"
@@ -96,7 +95,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
9695
t.Fatal(err)
9796
}
9897

99-
assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
98+
assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
10099
ds, err := docserver.New("/")
101100
if err != nil {
102101
t.Errorf("Error creating DocServer: %v", err)
@@ -362,7 +361,7 @@ func checkEvalJSON(t *testing.T, re *testjethre, expr, want string) error {
362361
}
363362
if err != nil {
364363
_, file, line, _ := runtime.Caller(1)
365-
file = path.Base(file)
364+
file = filepath.Base(file)
366365
fmt.Printf("\t%s:%d: %v\n", file, line, err)
367366
t.Fail()
368367
}

cmd/geth/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"io"
2727
"io/ioutil"
2828
"os"
29-
"path"
3029
"path/filepath"
3130
"runtime"
3231
"strconv"
@@ -565,7 +564,7 @@ func upgradeDb(ctx *cli.Context) {
565564
}
566565

567566
filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("2006-01-02_15:04:05"))
568-
exportFile := path.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
567+
exportFile := filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
569568

570569
err = utils.ExportChain(ethereum.ChainManager(), exportFile)
571570
if err != nil {
@@ -576,7 +575,7 @@ func upgradeDb(ctx *cli.Context) {
576575
ethereum.StateDb().Close()
577576
ethereum.ExtraDb().Close()
578577

579-
os.RemoveAll(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
578+
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
580579

581580
ethereum, err = eth.New(cfg)
582581
if err != nil {

cmd/mist/gui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"fmt"
2828
"io/ioutil"
2929
"math/big"
30-
"path"
30+
"path/filepath"
3131
"runtime"
3232
"sort"
3333
"time"
@@ -79,7 +79,7 @@ type Gui struct {
7979

8080
// Create GUI, but doesn't start it
8181
func NewWindow(ethereum *eth.Ethereum) *Gui {
82-
db, err := ethdb.NewLDBDatabase(path.Join(ethereum.DataDir, "tx_database"))
82+
db, err := ethdb.NewLDBDatabase(filepath.Join(ethereum.DataDir, "tx_database"))
8383
if err != nil {
8484
panic(err)
8585
}
@@ -92,7 +92,7 @@ func NewWindow(ethereum *eth.Ethereum) *Gui {
9292
plugins: make(map[string]plugin),
9393
serviceEvents: make(chan ServEv, 1),
9494
}
95-
data, _ := ioutil.ReadFile(path.Join(ethereum.DataDir, "plugins.json"))
95+
data, _ := ioutil.ReadFile(filepath.Join(ethereum.DataDir, "plugins.json"))
9696
json.Unmarshal(data, &gui.plugins)
9797

9898
return gui

cmd/mist/html_container.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"io/ioutil"
2727
"net/url"
2828
"os"
29-
"path"
3029
"path/filepath"
3130

3231
"github.com/ethereum/go-ethereum/common"
@@ -80,7 +79,7 @@ func (app *HtmlApplication) RootFolder() string {
8079
if err != nil {
8180
return ""
8281
}
83-
return path.Dir(common.WindonizePath(folder.RequestURI()))
82+
return filepath.Dir(common.WindonizePath(folder.RequestURI()))
8483
}
8584
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
8685
files, _ := ioutil.ReadDir(app.RootFolder())

cmd/mist/ui_lib.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package main
2222

2323
import (
2424
"io/ioutil"
25-
"path"
25+
"path/filepath"
2626

2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/core/types"
@@ -110,7 +110,7 @@ func (ui *UiLib) ConnectToPeer(nodeURL string) {
110110
}
111111

112112
func (ui *UiLib) AssetPath(p string) string {
113-
return path.Join(ui.assetPath, p)
113+
return filepath.Join(ui.assetPath, p)
114114
}
115115

116116
func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
@@ -218,7 +218,7 @@ func (self *UiLib) Messages(id int) *common.List {
218218
}
219219

220220
func (self *UiLib) ReadFile(p string) string {
221-
content, err := ioutil.ReadFile(self.AssetPath(path.Join("ext", p)))
221+
content, err := ioutil.ReadFile(self.AssetPath(filepath.Join("ext", p)))
222222
if err != nil {
223223
guilogger.Infoln("error reading file", p, ":", err)
224224
}

cmd/utils/flags.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"math/big"
88
"net/http"
99
"os"
10-
"path"
10+
"path/filepath"
1111
"runtime"
1212

1313
"github.com/codegangsta/cli"
@@ -55,7 +55,7 @@ OPTIONS:
5555
// NewApp creates an app with sane defaults.
5656
func NewApp(version, usage string) *cli.App {
5757
app := cli.NewApp()
58-
app.Name = path.Base(os.Args[0])
58+
app.Name = filepath.Base(os.Args[0])
5959
app.Author = ""
6060
//app.Authors = nil
6161
app.Email = ""
@@ -319,17 +319,17 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
319319
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
320320
dataDir := ctx.GlobalString(DataDirFlag.Name)
321321

322-
blockDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "blockchain"))
322+
blockDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "blockchain"))
323323
if err != nil {
324324
Fatalf("Could not open database: %v", err)
325325
}
326326

327-
stateDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "state"))
327+
stateDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "state"))
328328
if err != nil {
329329
Fatalf("Could not open database: %v", err)
330330
}
331331

332-
extraDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "extra"))
332+
extraDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "extra"))
333333
if err != nil {
334334
Fatalf("Could not open database: %v", err)
335335
}
@@ -346,7 +346,7 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Dat
346346

347347
func GetAccountManager(ctx *cli.Context) *accounts.Manager {
348348
dataDir := ctx.GlobalString(DataDirFlag.Name)
349-
ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
349+
ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keys"))
350350
return accounts.NewManager(ks)
351351
}
352352

common/compiler/solidity.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io/ioutil"
88
"os"
99
"os/exec"
10-
"path"
1110
"path/filepath"
1211
"regexp"
1312
"strings"
@@ -130,10 +129,10 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) {
130129
_, file := filepath.Split(matches[0])
131130
base := strings.Split(file, ".")[0]
132131

133-
codeFile := path.Join(wd, base+".binary")
134-
abiDefinitionFile := path.Join(wd, base+".abi")
135-
userDocFile := path.Join(wd, base+".docuser")
136-
developerDocFile := path.Join(wd, base+".docdev")
132+
codeFile := filepath.Join(wd, base+".binary")
133+
abiDefinitionFile := filepath.Join(wd, base+".abi")
134+
userDocFile := filepath.Join(wd, base+".docuser")
135+
developerDocFile := filepath.Join(wd, base+".docdev")
137136

138137
code, err := ioutil.ReadFile(codeFile)
139138
if err != nil {

common/path.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"os/user"
7-
"path"
87
"path/filepath"
98
"runtime"
109
"strings"
@@ -44,32 +43,32 @@ func FileExist(filePath string) bool {
4443
}
4544

4645
func AbsolutePath(Datadir string, filename string) string {
47-
if path.IsAbs(filename) {
46+
if filepath.IsAbs(filename) {
4847
return filename
4948
}
50-
return path.Join(Datadir, filename)
49+
return filepath.Join(Datadir, filename)
5150
}
5251

5352
func DefaultAssetPath() string {
5453
var assetPath string
5554
pwd, _ := os.Getwd()
56-
srcdir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist")
55+
srcdir := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist")
5756

5857
// If the current working directory is the go-ethereum dir
5958
// assume a debug build and use the source directory as
6059
// asset directory.
6160
if pwd == srcdir {
62-
assetPath = path.Join(pwd, "assets")
61+
assetPath = filepath.Join(pwd, "assets")
6362
} else {
6463
switch runtime.GOOS {
6564
case "darwin":
6665
// Get Binary Directory
6766
exedir, _ := osext.ExecutableFolder()
6867
assetPath = filepath.Join(exedir, "..", "Resources")
6968
case "linux":
70-
assetPath = path.Join("usr", "share", "mist")
69+
assetPath = filepath.Join("usr", "share", "mist")
7170
case "windows":
72-
assetPath = path.Join(".", "assets")
71+
assetPath = filepath.Join(".", "assets")
7372
default:
7473
assetPath = "."
7574
}
@@ -78,7 +77,7 @@ func DefaultAssetPath() string {
7877
// Check if the assetPath exists. If not, try the source directory
7978
// This happens when binary is run from outside cmd/mist directory
8079
if _, err := os.Stat(assetPath); os.IsNotExist(err) {
81-
assetPath = path.Join(srcdir, "assets")
80+
assetPath = filepath.Join(srcdir, "assets")
8281
}
8382

8483
return assetPath
@@ -87,11 +86,11 @@ func DefaultAssetPath() string {
8786
func DefaultDataDir() string {
8887
usr, _ := user.Current()
8988
if runtime.GOOS == "darwin" {
90-
return path.Join(usr.HomeDir, "Library", "Ethereum")
89+
return filepath.Join(usr.HomeDir, "Library", "Ethereum")
9190
} else if runtime.GOOS == "windows" {
92-
return path.Join(usr.HomeDir, "AppData", "Roaming", "Ethereum")
91+
return filepath.Join(usr.HomeDir, "AppData", "Roaming", "Ethereum")
9392
} else {
94-
return path.Join(usr.HomeDir, ".ethereum")
93+
return filepath.Join(usr.HomeDir, ".ethereum")
9594
}
9695
}
9796

core/chain_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"math/big"
66
"os"
7-
"path"
7+
"path/filepath"
88
"runtime"
99
"strconv"
1010
"testing"
@@ -94,7 +94,7 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
9494
}
9595

9696
func loadChain(fn string, t *testing.T) (types.Blocks, error) {
97-
fh, err := os.OpenFile(path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
97+
fh, err := os.OpenFile(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
9898
if err != nil {
9999
return nil, err
100100
}

crypto/key_store_passphrase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import (
7272
"errors"
7373
"io"
7474
"os"
75-
"path"
75+
"path/filepath"
7676

7777
"code.google.com/p/go-uuid/uuid"
7878
"github.com/ethereum/go-ethereum/crypto/randentropy"
@@ -163,7 +163,7 @@ func (ks keyStorePassphrase) DeleteKey(keyAddr []byte, auth string) (err error)
163163
return err
164164
}
165165

166-
keyDirPath := path.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
166+
keyDirPath := filepath.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
167167
return os.RemoveAll(keyDirPath)
168168
}
169169

crypto/key_store_plain.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"io"
3131
"io/ioutil"
3232
"os"
33-
"path"
33+
"path/filepath"
3434
)
3535

3636
// TODO: rename to KeyStore when replacing existing KeyStore
@@ -91,20 +91,20 @@ func (ks keyStorePlain) StoreKey(key *Key, auth string) (err error) {
9191
}
9292

9393
func (ks keyStorePlain) DeleteKey(keyAddr []byte, auth string) (err error) {
94-
keyDirPath := path.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
94+
keyDirPath := filepath.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
9595
err = os.RemoveAll(keyDirPath)
9696
return err
9797
}
9898

9999
func GetKeyFile(keysDirPath string, keyAddr []byte) (fileContent []byte, err error) {
100100
fileName := hex.EncodeToString(keyAddr)
101-
return ioutil.ReadFile(path.Join(keysDirPath, fileName, fileName))
101+
return ioutil.ReadFile(filepath.Join(keysDirPath, fileName, fileName))
102102
}
103103

104104
func WriteKeyFile(addr []byte, keysDirPath string, content []byte) (err error) {
105105
addrHex := hex.EncodeToString(addr)
106-
keyDirPath := path.Join(keysDirPath, addrHex)
107-
keyFilePath := path.Join(keyDirPath, addrHex)
106+
keyDirPath := filepath.Join(keysDirPath, addrHex)
107+
keyFilePath := filepath.Join(keyDirPath, addrHex)
108108
err = os.MkdirAll(keyDirPath, 0700) // read, write and dir search for user
109109
if err != nil {
110110
return err

0 commit comments

Comments
 (0)