58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package conf
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
// reverse look up map
|
|
var dirToNick map[string]string = make(map[string]string)
|
|
|
|
|
|
|
|
// given a valid deployment, add it
|
|
// internal, thread unsafe
|
|
func addDeployment(d *Msg) error {
|
|
if err := validateDeployment(d); err != nil {
|
|
d.reply <- err
|
|
return err
|
|
}
|
|
conf.Deployments[d.Args["name"]] = d.Args["path"]
|
|
dirToNick[d.Args["path"]] = d.Args["name"]
|
|
saveConf()
|
|
d.reply <- nil
|
|
return nil
|
|
}
|
|
/*
|
|
func RmDeployment(string arg) error {
|
|
reply = make(chan error)
|
|
rmDeploymentChan <-
|
|
|
|
// Assume nick, check if registered
|
|
deps := GetConf().Deployments
|
|
arg := args[0]
|
|
if _,ok := deps[arg]; !ok {
|
|
// not a registered nick, try as path
|
|
absPath := absPath(path, arg)
|
|
// if _,ok := conf.
|
|
}
|
|
}
|
|
*/
|
|
// Validate a deployment is ok to insert
|
|
// internal thread unsafe
|
|
func validateDeployment(d *Msg) error {
|
|
// check if exists
|
|
if _, ok := conf.Deployments[d.Args["Name"]]; ok {
|
|
return errors.New("Deployment with that name already exists")
|
|
}
|
|
|
|
if r, ok := dirToNick[d.Args["path"]]; ok {
|
|
return errors.New("Directory with that name already registered under nick '" + r + "'")
|
|
}
|
|
|
|
// check if dir exists
|
|
if _, err := os.Stat(d.Args["path"]); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
} |