Move some funcs for better file organization.

This commit is contained in:
Josh Rickmar 2013-12-04 20:55:56 -05:00
parent ce23523ed7
commit ae4bf50f7a
2 changed files with 34 additions and 32 deletions

View file

@ -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
}

View file

@ -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.