Skip to content

Commit 50edd5f

Browse files
committed
Added helper functions to handle concurrent writes to ctx.Stdout/Stderr
1 parent efd89c5 commit 50edd5f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: legacy/builder/container_find_includes.go

+1-1
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

Diff for: legacy/builder/types/context.go

+18
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,21 @@ func (ctx *Context) Warn(msg string) {
252252
}
253253
ctx.stdLock.Unlock()
254254
}
255+
256+
func (ctx *Context) WriteStdout(data []byte) (int, error) {
257+
ctx.stdLock.Lock()
258+
defer ctx.stdLock.Unlock()
259+
if ctx.Stdout == nil {
260+
return os.Stdout.Write(data)
261+
}
262+
return ctx.Stdout.Write(data)
263+
}
264+
265+
func (ctx *Context) WriteStderr(data []byte) (int, error) {
266+
ctx.stdLock.Lock()
267+
defer ctx.stdLock.Unlock()
268+
if ctx.Stderr == nil {
269+
return os.Stderr.Write(data)
270+
}
271+
return ctx.Stderr.Write(data)
272+
}

0 commit comments

Comments
 (0)