Update utilities to use new btcutil.AppDataDir.

Closes #30.
This commit is contained in:
Dave Collins 2013-11-11 10:48:21 -06:00
parent 72c186f9a9
commit 89eae6f590
4 changed files with 22 additions and 62 deletions

View file

@ -31,13 +31,17 @@ type config struct {
InFile string `short:"i" long:"infile" description:"File containing the block(s)" required:"true"` InFile string `short:"i" long:"infile" description:"File containing the block(s)" required:"true"`
} }
var log seelog.LoggerInterface
const ( const (
ArgSha = iota ArgSha = iota
ArgHeight ArgHeight
) )
var (
btcdHomeDir = btcutil.AppDataDir("btcd", false)
defaultDataDir = filepath.Join(btcdHomeDir, "data")
log seelog.LoggerInterface
)
type bufQueue struct { type bufQueue struct {
height int64 height int64
blkbuf []byte blkbuf []byte
@ -52,7 +56,7 @@ type blkQueue struct {
func main() { func main() {
cfg := config{ cfg := config{
DbType: "leveldb", DbType: "leveldb",
DataDir: filepath.Join(btcdHomeDir(), "data"), DataDir: defaultDataDir,
} }
parser := flags.NewParser(&cfg, flags.Default) parser := flags.NewParser(&cfg, flags.Default)
_, err := parser.Parse() _, err := parser.Parse()
@ -246,21 +250,3 @@ func newLogger(level string, prefix string) seelog.LoggerInterface {
return logger 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 "."
}

View file

@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"github.com/conformal/go-flags" "github.com/conformal/go-flags"
"github.com/conformal/seelog" "github.com/conformal/seelog"
@ -26,7 +27,11 @@ type config struct {
ShaString string `short:"s" description:"Block SHA to process" required:"true"` 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 ( const (
ArgSha = iota ArgSha = iota
@ -36,7 +41,7 @@ const (
func main() { func main() {
cfg := config{ cfg := config{
DbType: "leveldb", DbType: "leveldb",
DataDir: filepath.Join(btcdHomeDir(), "data"), DataDir: defaultDataDir,
} }
parser := flags.NewParser(&cfg, flags.Default) parser := flags.NewParser(&cfg, flags.Default)
_, err := parser.Parse() _, err := parser.Parse()
@ -185,21 +190,3 @@ func parsesha(argstr string) (argtype int, height int64, psha *btcwire.ShaHash,
psha = &sha psha = &sha
return 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 "."
}

View file

@ -23,7 +23,8 @@ const (
) )
var ( var (
defaultDataDir = filepath.Join(btcdHomeDir(), "data") btcdHomeDir = btcutil.AppDataDir("btcd", false)
defaultDataDir = filepath.Join(btcdHomeDir, "data")
knownDbTypes = btcdb.SupportedDBs() knownDbTypes = btcdb.SupportedDBs()
activeNetwork = btcwire.MainNet 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"` 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. // validDbType returns whether or not dbType is a supported database type.
func validDbType(dbType string) bool { func validDbType(dbType string) bool {
for _, knownType := range knownDbTypes { for _, knownType := range knownDbTypes {

View file

@ -36,7 +36,11 @@ type config struct {
ShowTx bool `short:"t" description:"Show transaction"` 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 ( const (
ArgSha = iota ArgSha = iota
@ -48,7 +52,7 @@ func main() {
cfg := config{ cfg := config{
DbType: "leveldb", DbType: "leveldb",
DataDir: filepath.Join(btcdHomeDir(), "data"), DataDir: defaultDataDir,
} }
parser := flags.NewParser(&cfg, flags.Default) parser := flags.NewParser(&cfg, flags.Default)
_, err := parser.Parse() _, err := parser.Parse()