engine: Refactor state dir into a separate function
This lets us re-use it, and know the path is fixed.
This commit is contained in:
@@ -30,6 +30,12 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util/semaphore"
|
"github.com/purpleidea/mgmt/util/semaphore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// StateDir is the name of the sub directory where all the local
|
||||||
|
// resource state is stored.
|
||||||
|
StateDir = "state"
|
||||||
|
)
|
||||||
|
|
||||||
// Engine encapsulates a generic graph and manages its operations.
|
// Engine encapsulates a generic graph and manages its operations.
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
Program string
|
Program string
|
||||||
@@ -176,7 +182,8 @@ func (obj *Engine) Commit() error {
|
|||||||
|
|
||||||
// FIXME: is res.Name() sufficiently unique to use as a UID here?
|
// FIXME: is res.Name() sufficiently unique to use as a UID here?
|
||||||
pathUID := fmt.Sprintf("%s-%s", res.Kind(), res.Name())
|
pathUID := fmt.Sprintf("%s-%s", res.Kind(), res.Name())
|
||||||
statePrefix := fmt.Sprintf("%s/", path.Join(obj.Prefix, "state", pathUID))
|
statePrefix := fmt.Sprintf("%s/", path.Join(obj.statePrefix(), pathUID))
|
||||||
|
|
||||||
// don't create this unless it *will* be used
|
// don't create this unless it *will* be used
|
||||||
//if err := os.MkdirAll(statePrefix, 0770); err != nil {
|
//if err := os.MkdirAll(statePrefix, 0770); err != nil {
|
||||||
// return errwrap.Wrapf(err, "can't create state prefix")
|
// return errwrap.Wrapf(err, "can't create state prefix")
|
||||||
@@ -416,3 +423,8 @@ func (obj *Engine) Close() error {
|
|||||||
func (obj *Engine) Graph() *pgraph.Graph {
|
func (obj *Engine) Graph() *pgraph.Graph {
|
||||||
return obj.graph
|
return obj.graph
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// statePrefix returns the dir where all the resource state is stored locally.
|
||||||
|
func (obj *Engine) statePrefix() string {
|
||||||
|
return fmt.Sprintf("%s/", path.Join(obj.Prefix, StateDir))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user