Skip to content

Commit

Permalink
replaced several path.* with filepath.* which is platform independent
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas van Kervel committed May 12, 2015
1 parent d82caa5 commit b79dd18
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 64 deletions.
5 changes: 3 additions & 2 deletions cmd/geth/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"fmt"
"math/big"
"os"
"path"
"strings"

"path/filepath"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common/docserver"
"github.com/ethereum/go-ethereum/common/natspec"
Expand Down Expand Up @@ -209,7 +210,7 @@ func (self *jsre) interactive() {
}

func (self *jsre) withHistory(op func(*os.File)) {
hist, err := os.OpenFile(path.Join(self.ethereum.DataDir, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
hist, err := os.OpenFile(filepath.Join(self.ethereum.DataDir, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
fmt.Printf("unable to open history file: %v\n", err)
return
Expand Down
5 changes: 2 additions & 3 deletions cmd/geth/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -96,7 +95,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
t.Fatal(err)
}

assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
ds, err := docserver.New("/")
if err != nil {
t.Errorf("Error creating DocServer: %v", err)
Expand Down Expand Up @@ -361,7 +360,7 @@ func checkEvalJSON(t *testing.T, re *testjethre, expr, want string) error {
}
if err != nil {
_, file, line, _ := runtime.Caller(1)
file = path.Base(file)
file = filepath.Base(file)
fmt.Printf("\t%s:%d: %v\n", file, line, err)
t.Fail()
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -565,7 +564,7 @@ func upgradeDb(ctx *cli.Context) {
}

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

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

os.RemoveAll(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))

ethereum, err = eth.New(cfg)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/mist/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (
"fmt"
"io/ioutil"
"math/big"
"path"
"runtime"
"sort"
"time"

"path/filepath"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -79,7 +80,7 @@ type Gui struct {

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

return gui
Expand Down
3 changes: 1 addition & 2 deletions cmd/mist/html_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (app *HtmlApplication) RootFolder() string {
if err != nil {
return ""
}
return path.Dir(common.WindonizePath(folder.RequestURI()))
return filepath.Dir(common.WindonizePath(folder.RequestURI()))
}
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
files, _ := ioutil.ReadDir(app.RootFolder())
Expand Down
7 changes: 4 additions & 3 deletions cmd/mist/ui_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ package main

import (
"io/ioutil"
"path"

"path/filepath"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (ui *UiLib) ConnectToPeer(nodeURL string) {
}

func (ui *UiLib) AssetPath(p string) string {
return path.Join(ui.assetPath, p)
return filepath.Join(ui.assetPath, p)
}

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

func (self *UiLib) ReadFile(p string) string {
content, err := ioutil.ReadFile(self.AssetPath(path.Join("ext", p)))
content, err := ioutil.ReadFile(self.AssetPath(filepath.Join("ext", p)))
if err != nil {
guilogger.Infoln("error reading file", p, ":", err)
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"math/big"
"net/http"
"os"
"path"
"runtime"

"path/filepath"

"github.com/codegangsta/cli"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -55,7 +56,7 @@ OPTIONS:
// NewApp creates an app with sane defaults.
func NewApp(version, usage string) *cli.App {
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Name = filepath.Base(os.Args[0])
app.Author = ""
//app.Authors = nil
app.Email = ""
Expand Down Expand Up @@ -319,17 +320,17 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
dataDir := ctx.GlobalString(DataDirFlag.Name)

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

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

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

func GetAccountManager(ctx *cli.Context) *accounts.Manager {
dataDir := ctx.GlobalString(DataDirFlag.Name)
ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keys"))
return accounts.NewManager(ks)
}

Expand Down
9 changes: 4 additions & 5 deletions common/compiler/solidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -130,10 +129,10 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) {
_, file := filepath.Split(matches[0])
base := strings.Split(file, ".")[0]

codeFile := path.Join(wd, base+".binary")
abiDefinitionFile := path.Join(wd, base+".abi")
userDocFile := path.Join(wd, base+".docuser")
developerDocFile := path.Join(wd, base+".docdev")
codeFile := filepath.Join(wd, base+".binary")
abiDefinitionFile := filepath.Join(wd, base+".abi")
userDocFile := filepath.Join(wd, base+".docuser")
developerDocFile := filepath.Join(wd, base+".docdev")

code, err := ioutil.ReadFile(codeFile)
if err != nil {
Expand Down
21 changes: 10 additions & 11 deletions common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/user"
"path"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -44,32 +43,32 @@ func FileExist(filePath string) bool {
}

func AbsolutePath(Datadir string, filename string) string {
if path.IsAbs(filename) {
if filepath.IsAbs(filename) {
return filename
}
return path.Join(Datadir, filename)
return filepath.Join(Datadir, filename)
}

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

// If the current working directory is the go-ethereum dir
// assume a debug build and use the source directory as
// asset directory.
if pwd == srcdir {
assetPath = path.Join(pwd, "assets")
assetPath = filepath.Join(pwd, "assets")
} else {
switch runtime.GOOS {
case "darwin":
// Get Binary Directory
exedir, _ := osext.ExecutableFolder()
assetPath = filepath.Join(exedir, "..", "Resources")
case "linux":
assetPath = path.Join("usr", "share", "mist")
assetPath = filepath.Join("usr", "share", "mist")
case "windows":
assetPath = path.Join(".", "assets")
assetPath = filepath.Join(".", "assets")
default:
assetPath = "."
}
Expand All @@ -78,7 +77,7 @@ func DefaultAssetPath() string {
// Check if the assetPath exists. If not, try the source directory
// This happens when binary is run from outside cmd/mist directory
if _, err := os.Stat(assetPath); os.IsNotExist(err) {
assetPath = path.Join(srcdir, "assets")
assetPath = filepath.Join(srcdir, "assets")
}

return assetPath
Expand All @@ -87,11 +86,11 @@ func DefaultAssetPath() string {
func DefaultDataDir() string {
usr, _ := user.Current()
if runtime.GOOS == "darwin" {
return path.Join(usr.HomeDir, "Library", "Ethereum")
return filepath.Join(usr.HomeDir, "Library", "Ethereum")
} else if runtime.GOOS == "windows" {
return path.Join(usr.HomeDir, "AppData", "Roaming", "Ethereum")
return filepath.Join(usr.HomeDir, "AppData", "Roaming", "Ethereum")
} else {
return path.Join(usr.HomeDir, ".ethereum")
return filepath.Join(usr.HomeDir, ".ethereum")
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/chain_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"math/big"
"os"
"path"
"runtime"
"strconv"
"testing"

"path/filepath"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -94,7 +95,7 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
}

func loadChain(fn string, t *testing.T) (types.Blocks, error) {
fh, err := os.OpenFile(path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
fh, err := os.OpenFile(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/key_store_passphrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import (
"errors"
"io"
"os"
"path"
"path/filepath"

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

keyDirPath := path.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
keyDirPath := filepath.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
return os.RemoveAll(keyDirPath)
}

Expand Down
10 changes: 5 additions & 5 deletions crypto/key_store_plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
)

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

func (ks keyStorePlain) DeleteKey(keyAddr []byte, auth string) (err error) {
keyDirPath := path.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
keyDirPath := filepath.Join(ks.keysDirPath, hex.EncodeToString(keyAddr))
err = os.RemoveAll(keyDirPath)
return err
}

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

func WriteKeyFile(addr []byte, keysDirPath string, content []byte) (err error) {
addrHex := hex.EncodeToString(addr)
keyDirPath := path.Join(keysDirPath, addrHex)
keyFilePath := path.Join(keyDirPath, addrHex)
keyDirPath := filepath.Join(keysDirPath, addrHex)
keyFilePath := filepath.Join(keyDirPath, addrHex)
err = os.MkdirAll(keyDirPath, 0700) // read, write and dir search for user
if err != nil {
return err
Expand Down
Loading

0 comments on commit b79dd18

Please sign in to comment.