diff --git a/realize/notify.go b/realize/notify.go index 03c6006..3e2ead9 100644 --- a/realize/notify.go +++ b/realize/notify.go @@ -137,6 +137,13 @@ func (w *filePoller) Add(name string) error { return errPollerClosed } + + if w.watches == nil { + w.watches = make(map[string]chan struct{}) + } else if _, exists := w.watches[name]; exists { + return fmt.Errorf("watch exists") + } + f, err := os.Open(name) if err != nil { return err @@ -146,12 +153,6 @@ func (w *filePoller) Add(name string) error { return err } - if w.watches == nil { - w.watches = make(map[string]chan struct{}) - } - if _, exists := w.watches[name]; exists { - return fmt.Errorf("watch exists") - } chClose := make(chan struct{}) w.watches[name] = chClose go w.watch(f, fi, chClose) diff --git a/realize/projects.go b/realize/projects.go index 0490e31..253e3ee 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -562,10 +562,25 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { }() } +// buildEnvs returns a copy of strings representing the environment, +// in the form "key=value". func (p Project) buildEnvs() (envs []string) { + envMap := make(map[string]string) + + for _, env := range os.Environ() { + e := strings.SplitN(env, "=", 2) + + envMap[e[0]] = e[1] + } + for k, v := range p.Env { - envs = append(envs, fmt.Sprintf("%s=%s", strings.Replace(k, "=", "", -1), v)) + envMap[strings.Replace(k, "=", "", -1)] = v } + + for k, v := range envMap { + envs = append(envs, fmt.Sprintf("%s=%s", k, v)) + } + return }