From ae4bf50f7a785866441217c22f00a4da3657c647 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 4 Dec 2013 20:55:56 -0500 Subject: [PATCH] Move some funcs for better file organization. --- account.go | 32 -------------------------------- disksync.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/account.go b/account.go index abad32a..aa854fd 100644 --- a/account.go +++ b/account.go @@ -26,7 +26,6 @@ import ( "github.com/conformal/btcwallet/wallet" "github.com/conformal/btcwire" "github.com/conformal/btcws" - "os" "path/filepath" "sync" "time" @@ -722,34 +721,3 @@ func accountdir(name string, cfg *config) string { return filepath.Join(cfg.DataDir, adir) } - -func networkDir(net btcwire.BitcoinNet) string { - var netname string - if net == btcwire.MainNet { - netname = "mainnet" - } else { - netname = "testnet" - } - return filepath.Join(cfg.DataDir, netname) -} - -// checkCreateDir checks that the path exists and is a directory. -// If path does not exist, it is created. -func checkCreateDir(path string) error { - if fi, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - // Attempt data directory creation - if err = os.MkdirAll(path, 0700); err != nil { - return fmt.Errorf("cannot create network directory: %s", err) - } - } else { - return fmt.Errorf("error checking network directory: %s", err) - } - } else { - if !fi.IsDir() { - return fmt.Errorf("path '%s' is not a directory", path) - } - } - - return nil -} diff --git a/disksync.go b/disksync.go index d00e6eb..2641028 100644 --- a/disksync.go +++ b/disksync.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "github.com/conformal/btcwire" "os" "path/filepath" "sync" @@ -34,6 +35,39 @@ var ( } ) +// networkDir returns the base directory name for the bitcoin network +// net. +func networkDir(net btcwire.BitcoinNet) string { + var netname string + if net == btcwire.MainNet { + netname = "mainnet" + } else { + netname = "testnet" + } + return filepath.Join(cfg.DataDir, netname) +} + +// checkCreateDir checks that the path exists and is a directory. +// If path does not exist, it is created. +func checkCreateDir(path string) error { + if fi, err := os.Stat(path); err != nil { + if os.IsNotExist(err) { + // Attempt data directory creation + if err = os.MkdirAll(path, 0700); err != nil { + return fmt.Errorf("cannot create directory: %s", err) + } + } else { + return fmt.Errorf("error checking directory: %s", err) + } + } else { + if !fi.IsDir() { + return fmt.Errorf("path '%s' is not a directory", path) + } + } + + return nil +} + // accountFilename returns the filepath of an account file given the // filename suffix ("wallet.bin", "tx.bin", or "utxo.bin"), account // name and the network directory holding the file.