From a159f815a97d3a3b453b78dbcf2e7cac0b16ad67 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 11 May 2020 14:29:30 +0200 Subject: [PATCH 1/2] add os.environ when using env from yaml --- realize/projects.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 } From f2580d802e84a248ca844267c8780206c15b2c80 Mon Sep 17 00:00:00 2001 From: aaad <928728+aaad@users.noreply.github.com> Date: Wed, 11 Nov 2020 16:07:53 +0100 Subject: [PATCH 2/2] fix: check if the file is already watched first --- realize/notify.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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)