rpctest: Store logs and data in same path.

logs and data directories are subdirs
of the harness dir, the node dcrd
process is also run in the working dir
which is the harness dir
This commit is contained in:
Donald Adu-Poku 2017-08-02 02:50:16 +00:00 committed by Dave Collins
parent fdb25c2f43
commit 18ca7bb19d
2 changed files with 6 additions and 29 deletions

View File

@ -70,16 +70,8 @@ func newConfig(prefix, certFile, keyFile string, extra []string) (*nodeConfig, e
// temporary data, and log directories which must be cleaned up with a call to
// cleanup().
func (n *nodeConfig) setDefaults() error {
datadir, err := ioutil.TempDir("", n.prefix+"-data")
if err != nil {
return err
}
n.dataDir = datadir
logdir, err := ioutil.TempDir("", n.prefix+"-logs")
if err != nil {
return err
}
n.logDir = logdir
n.dataDir = filepath.Join(n.prefix, "data")
n.logDir = filepath.Join(n.prefix, "logs")
cert, err := ioutil.ReadFile(n.certFile)
if err != nil {
return err
@ -165,21 +157,6 @@ func (n *nodeConfig) String() string {
return n.prefix
}
// cleanup removes the tmp data and log directories.
func (n *nodeConfig) cleanup() error {
dirs := []string{
n.logDir,
n.dataDir,
}
var err error
for _, dir := range dirs {
if err = os.RemoveAll(dir); err != nil {
log.Printf("Cannot remove dir %s: %v", dir, err)
}
}
return err
}
// node houses the necessary state required to configure, launch, and manage a
// dcrd process.
type node struct {
@ -212,8 +189,7 @@ func (n *node) start() error {
return err
}
pid, err := os.Create(filepath.Join(n.dataDir,
fmt.Sprintf("%s.pid", n.config)))
pid, err := os.Create(filepath.Join(n.config.String(), "dcrd.pid"))
if err != nil {
return err
}
@ -254,10 +230,11 @@ func (n *node) cleanup() error {
if err := os.Remove(n.pidFile); err != nil {
log.Printf("unable to remove file %s: %v", n.pidFile,
err)
return err
}
}
return n.config.cleanup()
return nil
}
// shutdown terminates the running dcrd process, and cleans up all

View File

@ -124,7 +124,7 @@ func New(activeNet *chaincfg.Params, handlers *dcrrpcclient.NotificationHandlers
miningAddr := fmt.Sprintf("--miningaddr=%s", wallet.coinbaseAddr)
extraArgs = append(extraArgs, miningAddr)
config, err := newConfig("rpctest", certFile, keyFile, extraArgs)
config, err := newConfig(nodeTestData, certFile, keyFile, extraArgs)
if err != nil {
return nil, err
}