diff --git a/util/addblock/addblock.go b/util/addblock/addblock.go index 68713674..a1d68432 100644 --- a/util/addblock/addblock.go +++ b/util/addblock/addblock.go @@ -31,13 +31,17 @@ type config struct { InFile string `short:"i" long:"infile" description:"File containing the block(s)" required:"true"` } -var log seelog.LoggerInterface - const ( ArgSha = iota ArgHeight ) +var ( + btcdHomeDir = btcutil.AppDataDir("btcd", false) + defaultDataDir = filepath.Join(btcdHomeDir, "data") + log seelog.LoggerInterface +) + type bufQueue struct { height int64 blkbuf []byte @@ -52,7 +56,7 @@ type blkQueue struct { func main() { cfg := config{ DbType: "leveldb", - DataDir: filepath.Join(btcdHomeDir(), "data"), + DataDir: defaultDataDir, } parser := flags.NewParser(&cfg, flags.Default) _, err := parser.Parse() @@ -246,21 +250,3 @@ func newLogger(level string, prefix string) seelog.LoggerInterface { return logger } - -// btcdHomeDir returns an OS appropriate home directory for btcd. -func btcdHomeDir() string { - // Search for Windows APPDATA first. This won't exist on POSIX OSes. - appData := os.Getenv("APPDATA") - if appData != "" { - return filepath.Join(appData, "btcd") - } - - // Fall back to standard HOME directory that works for most POSIX OSes. - home := os.Getenv("HOME") - if home != "" { - return filepath.Join(home, ".btcd") - } - - // In the worst case, use the current directory. - return "." -} diff --git a/util/dropafter/dropafter.go b/util/dropafter/dropafter.go index 41bd04a5..5beb733c 100644 --- a/util/dropafter/dropafter.go +++ b/util/dropafter/dropafter.go @@ -9,6 +9,7 @@ import ( "fmt" "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" + "github.com/conformal/btcutil" "github.com/conformal/btcwire" "github.com/conformal/go-flags" "github.com/conformal/seelog" @@ -26,7 +27,11 @@ type config struct { ShaString string `short:"s" description:"Block SHA to process" required:"true"` } -var log seelog.LoggerInterface +var ( + btcdHomeDir = btcutil.AppDataDir("btcd", false) + defaultDataDir = filepath.Join(btcdHomeDir, "data") + log seelog.LoggerInterface +) const ( ArgSha = iota @@ -36,7 +41,7 @@ const ( func main() { cfg := config{ DbType: "leveldb", - DataDir: filepath.Join(btcdHomeDir(), "data"), + DataDir: defaultDataDir, } parser := flags.NewParser(&cfg, flags.Default) _, err := parser.Parse() @@ -185,21 +190,3 @@ func parsesha(argstr string) (argtype int, height int64, psha *btcwire.ShaHash, psha = &sha return } - -// btcdHomeDir returns an OS appropriate home directory for btcd. -func btcdHomeDir() string { - // Search for Windows APPDATA first. This won't exist on POSIX OSes. - appData := os.Getenv("APPDATA") - if appData != "" { - return filepath.Join(appData, "btcd") - } - - // Fall back to standard HOME directory that works for most POSIX OSes. - home := os.Getenv("HOME") - if home != "" { - return filepath.Join(home, ".btcd") - } - - // In the worst case, use the current directory. - return "." -} diff --git a/util/findcheckpoint/config.go b/util/findcheckpoint/config.go index 543c857d..c4bd8c25 100644 --- a/util/findcheckpoint/config.go +++ b/util/findcheckpoint/config.go @@ -23,7 +23,8 @@ const ( ) var ( - defaultDataDir = filepath.Join(btcdHomeDir(), "data") + btcdHomeDir = btcutil.AppDataDir("btcd", false) + defaultDataDir = filepath.Join(btcdHomeDir, "data") knownDbTypes = btcdb.SupportedDBs() activeNetwork = btcwire.MainNet ) @@ -39,24 +40,6 @@ type config struct { UseGoOutput bool `short:"g" long:"gooutput" description:"Display the candidates using Go syntax that is ready to insert into the btcchain checkpoint list"` } -// btcdHomeDir returns an OS appropriate home directory for btcd. -func btcdHomeDir() string { - // Search for Windows APPDATA first. This won't exist on POSIX OSes. - appData := os.Getenv("APPDATA") - if appData != "" { - return filepath.Join(appData, "btcd") - } - - // Fall back to standard HOME directory that works for most POSIX OSes. - home := os.Getenv("HOME") - if home != "" { - return filepath.Join(home, ".btcd") - } - - // In the worst case, use the current directory. - return "." -} - // validDbType returns whether or not dbType is a supported database type. func validDbType(dbType string) bool { for _, knownType := range knownDbTypes { diff --git a/util/showblock/showblock.go b/util/showblock/showblock.go index 806cb141..b6b64543 100644 --- a/util/showblock/showblock.go +++ b/util/showblock/showblock.go @@ -36,7 +36,11 @@ type config struct { ShowTx bool `short:"t" description:"Show transaction"` } -var log seelog.LoggerInterface +var ( + btcdHomeDir = btcutil.AppDataDir("btcd", false) + defaultDataDir = filepath.Join(btcdHomeDir, "data") + log seelog.LoggerInterface +) const ( ArgSha = iota @@ -48,7 +52,7 @@ func main() { cfg := config{ DbType: "leveldb", - DataDir: filepath.Join(btcdHomeDir(), "data"), + DataDir: defaultDataDir, } parser := flags.NewParser(&cfg, flags.Default) _, err := parser.Parse()