@@ -486,6 +486,9 @@ func (r *buildEventReporter) Stop() error {
486
486
r .cancelBackgroundFlush ()
487
487
r .cancelBackgroundFlush = nil
488
488
}
489
+ if err := r .log .Flush (); err != nil {
490
+ return err
491
+ }
489
492
r .FlushProgress ()
490
493
491
494
elapsedTimeSeconds := float64 (time .Since (r .startTime )) / float64 (time .Second )
@@ -938,6 +941,9 @@ type invocationLog struct {
938
941
lockingbuffer.LockingBuffer
939
942
writer io.Writer
940
943
writeListener func (s string )
944
+
945
+ mu sync.Mutex
946
+ partialLine bytes.Buffer
941
947
}
942
948
943
949
func newInvocationLog () * invocationLog {
@@ -947,16 +953,69 @@ func newInvocationLog() *invocationLog {
947
953
}
948
954
949
955
func (invLog * invocationLog ) Write (b []byte ) (int , error ) {
950
- output := string (b )
956
+ invLog .mu .Lock ()
957
+ defer invLog .mu .Unlock ()
958
+
959
+ if _ , err := invLog .partialLine .Write (b ); err != nil {
960
+ return len (b ), err
961
+ }
951
962
952
- redacted := redact . RedactText ( output )
963
+ var writeErr error
953
964
954
- invLog .writeListener (redacted )
955
- _ , err := invLog .writer .Write ([]byte (redacted ))
965
+ for {
966
+ data := invLog .partialLine .Bytes ()
967
+ if len (data ) == 0 {
968
+ break
969
+ }
970
+
971
+ idx := bytes .IndexAny (data , "\n \r " )
972
+ if idx < 0 {
973
+ break
974
+ }
975
+
976
+ newlineLen := 1
977
+ newlineSuffix := data [idx : idx + newlineLen ]
978
+
979
+ if data [idx ] == '\r' && idx + 1 < len (data ) && data [idx + 1 ] == '\n' {
980
+ newlineLen = 2
981
+ newlineSuffix = data [idx : idx + newlineLen ]
982
+ }
983
+
984
+ lineContent := string (data [:idx ])
985
+ newlineStr := string (newlineSuffix )
986
+
987
+ invLog .partialLine .Next (idx + newlineLen )
988
+
989
+ redacted := redact .RedactText (lineContent )
990
+ output := redacted + newlineStr
991
+
992
+ invLog .writeListener (output )
993
+ if _ , err := invLog .writer .Write ([]byte (output )); err != nil && writeErr == nil {
994
+ writeErr = err
995
+ }
996
+ }
956
997
957
998
// Return the size of the original buffer even if a redacted size was written,
958
999
// or clients will return a short write error
959
- return len (b ), err
1000
+ return len (b ), writeErr
1001
+ }
1002
+
1003
+ func (invLog * invocationLog ) Flush () error {
1004
+ invLog .mu .Lock ()
1005
+ defer invLog .mu .Unlock ()
1006
+
1007
+ if invLog .partialLine .Len () == 0 {
1008
+ return nil
1009
+ }
1010
+
1011
+ line := invLog .partialLine .String ()
1012
+ invLog .partialLine .Reset ()
1013
+
1014
+ redacted := redact .RedactText (line )
1015
+
1016
+ invLog .writeListener (redacted )
1017
+ _ , err := invLog .writer .Write ([]byte (redacted ))
1018
+ return err
960
1019
}
961
1020
962
1021
func (invLog * invocationLog ) Println (vals ... interface {}) {
0 commit comments