Skip to content

Commit c4595f6

Browse files
committed
Added helper functions to handle concurrent writes to ctx.Stdout/Stderr
1 parent 057516d commit c4595f6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

legacy/builder/container_find_includes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
408408
return errors.New(tr("Internal error in cache"))
409409
}
410410
}
411-
ctx.Stderr.Write(preproc_stderr)
411+
ctx.WriteStderr(preproc_stderr)
412412
return errors.WithStack(preproc_err)
413413
}
414414

legacy/builder/types/context.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,21 @@ func (ctx *Context) Warn(msg string) {
249249
}
250250
ctx.stdLock.Unlock()
251251
}
252+
253+
func (ctx *Context) WriteStdout(data []byte) (int, error) {
254+
ctx.stdLock.Lock()
255+
defer ctx.stdLock.Unlock()
256+
if ctx.Stdout == nil {
257+
return os.Stdout.Write(data)
258+
}
259+
return ctx.Stdout.Write(data)
260+
}
261+
262+
func (ctx *Context) WriteStderr(data []byte) (int, error) {
263+
ctx.stdLock.Lock()
264+
defer ctx.stdLock.Unlock()
265+
if ctx.Stderr == nil {
266+
return os.Stderr.Write(data)
267+
}
268+
return ctx.Stderr.Write(data)
269+
}

0 commit comments

Comments
 (0)