cmd/cue/cmd: fix data race in import
determining filename uniqueness within directory has
to be done in critical section, of course.
Change-Id: I88ca126d6b5f58d5c1300cb0ad2190864e5cbf23
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1803
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cmd/cue/cmd/import.go b/cmd/cue/cmd/import.go
index feb9670..bc4bf2d 100644
--- a/cmd/cue/cmd/import.go
+++ b/cmd/cue/cmd/import.go
@@ -26,6 +26,7 @@
"regexp"
"strconv"
"strings"
+ "sync"
"unicode"
"cuelang.org/go/cue"
@@ -347,7 +348,13 @@
return combineExpressions(cmd, pkg, newName(filename, 0), objs...)
}
+// TODO: implement a more fine-grained approach.
+var mutex sync.Mutex
+
func combineExpressions(cmd *cobra.Command, pkg, cueFile string, objs ...ast.Expr) error {
+ mutex.Lock()
+ defer mutex.Unlock()
+
if *out != "" {
cueFile = *out
}