Skip to content

Commit

Permalink
Problem: MustMakeChainDataDir func did not return absolute filepath
Browse files Browse the repository at this point in the history
Solution: ensure absolute filepath

Problem #2: common.EnsureAbsolutePath misnamed; this func ensure absolute XOR
that specified paths are joined (that filepath is relative to a given dir)

Solution: #2: rename to EnsurePathAbsoluteOrRelativeTo
  • Loading branch information
whilei committed May 26, 2017
1 parent f66b6e6 commit 68e45f1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
Binary file modified accounts/testdata/keystore/accounts.db
Binary file not shown.
20 changes: 17 additions & 3 deletions cmd/geth/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ func mustMakeDataDir(ctx *cli.Context) string {
// A subdir of the datadir is used for each chain configuration ("/mainnet", "/testnet", "/my-custom-net").
// --> <home>/<EthereumClassic>/<mainnet|testnet|custom-net>, per --chain
func MustMakeChainDataDir(ctx *cli.Context) string {
return common.EnsureAbsolutePath(mustMakeDataDir(ctx), getChainConfigIDFromContext(ctx))
rp := common.EnsurePathAbsoluteOrRelativeTo(mustMakeDataDir(ctx), getChainConfigIDFromContext(ctx))
if !filepath.IsAbs(rp) {
af, e := filepath.Abs(rp)
if e != nil {
glog.Fatalf("cannot make absolute path for chain data dir: %v: %v", rp, e)
}
rp = af
}
return rp
}

// MakeIPCPath creates an IPC path configuration from the set command line flags,
Expand Down Expand Up @@ -301,8 +309,14 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
datadir := MustMakeChainDataDir(ctx)

keydir := filepath.Join(datadir, "keystore")

if path := ctx.GlobalString(aliasableName(KeyStoreDirFlag.Name, ctx)); path != "" {
keydir = path
af, e := filepath.Abs(path)
if e != nil {
glog.V(logger.Error).Infof("keydir path could not be made absolute: %v: %v", path, e)
} else {
keydir = af
}
}

m, err := accounts.NewManager(keydir, scryptN, scryptP, ctx.GlobalBool(aliasableName(AccountsIndexFlag.Name, ctx)))
Expand Down Expand Up @@ -912,7 +926,7 @@ func MakeConsolePreloads(ctx *cli.Context) []string {

assets := ctx.GlobalString(aliasableName(JSpathFlag.Name, ctx))
for _, file := range strings.Split(ctx.GlobalString(aliasableName(PreloadJSFlag.Name, ctx)), ",") {
preloads = append(preloads, common.EnsureAbsolutePath(assets, strings.TrimSpace(file)))
preloads = append(preloads, common.EnsurePathAbsoluteOrRelativeTo(assets, strings.TrimSpace(file)))
}
return preloads
}
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func dumpChainConfig(ctx *cli.Context) error {

// pretty printy
cwd, _ := os.Getwd()
glog.V(logger.Info).Info(fmt.Sprintf("Dumping chain configuration JSON to \x1b[32m%s\x1b[39m, it may take a moment to tally genesis allocations...", common.EnsureAbsolutePath(cwd, chainConfigFilePath)))
glog.V(logger.Info).Info(fmt.Sprintf("Dumping chain configuration JSON to \x1b[32m%s\x1b[39m, it may take a moment to tally genesis allocations...", common.EnsurePathAbsoluteOrRelativeTo(cwd, chainConfigFilePath)))

db := MakeChainDatabase(ctx)

Expand Down
2 changes: 1 addition & 1 deletion common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"path/filepath"
)

func EnsureAbsolutePath(Datadir string, filename string) string {
func EnsurePathAbsoluteOrRelativeTo(Datadir string, filename string) string {
if filepath.IsAbs(filename) {
return filename
}
Expand Down
4 changes: 2 additions & 2 deletions internal/jsre/jsre.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (self *JSRE) Stop(waitForCallbacks bool) {
// Exec(file) loads and runs the contents of a file
// if a relative path is given, the jsre's assetPath is used
func (self *JSRE) Exec(file string) error {
code, err := ioutil.ReadFile(common.EnsureAbsolutePath(self.assetPath, file))
code, err := ioutil.ReadFile(common.EnsurePathAbsoluteOrRelativeTo(self.assetPath, file))
if err != nil {
return err
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
// TODO: throw exception
return otto.FalseValue()
}
file = common.EnsureAbsolutePath(self.assetPath, file)
file = common.EnsurePathAbsoluteOrRelativeTo(self.assetPath, file)
source, err := ioutil.ReadFile(file)
if err != nil {
// TODO: throw exception
Expand Down
2 changes: 1 addition & 1 deletion logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func openLogFile(datadir string, filename string) *os.File {
path := common.EnsureAbsolutePath(datadir, filename)
path := common.EnsurePathAbsoluteOrRelativeTo(datadir, filename)
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
Expand Down

1 comment on commit 68e45f1

@GitCop
Copy link

@GitCop GitCop commented on 68e45f1 May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

  • Your commit message body contains a line that is longer than 72 characters

Guidelines are available at https://github.com/whilei/go-ethereum


This message was auto-generated by https://gitcop.com

Please sign in to comment.