Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmd: fix --progress crash under Windows Jenkins - fixes #2846

Nick Craig-Wood9012d7c6c155
diff --git a/cmd/progress.go b/cmd/progress.go
index ef21fd9a8..f6550a5bc 100644
--- a/cmd/progress.go
+++ b/cmd/progress.go
@@ -27,6 +27,11 @@ const (
//
// It returns a func which should be called to stop the stats.
func startProgress() func() {
+ err := initTerminal()
+ if err != nil {
+ fs.Errorf(nil, "Failed to start progress: %v", err)
+ return func() {}
+ }
stopStats := make(chan struct{})
oldLogPrint := fs.LogPrint
if !log.Redirected() {
diff --git a/cmd/progress_other.go b/cmd/progress_other.go
index aef00cd4b..ec1e223c7 100644
--- a/cmd/progress_other.go
+++ b/cmd/progress_other.go
@@ -4,6 +4,10 @@ package cmd
import "os"
+func initTerminal() error {
+ return nil
+}
+
func writeToTerminal(b []byte) {
_, _ = os.Stdout.Write(b)
}
diff --git a/cmd/progress_windows.go b/cmd/progress_windows.go
index e0ee6ffaf..c8943fc24 100644
--- a/cmd/progress_windows.go
+++ b/cmd/progress_windows.go
@@ -5,22 +5,31 @@ package cmd
import (
"fmt"
"os"
- "sync"
+ "syscall"
ansiterm "github.com/Azure/go-ansiterm"
"github.com/Azure/go-ansiterm/winterm"
+ "github.com/pkg/errors"
)
var (
- initAnsiParser sync.Once
- ansiParser *ansiterm.AnsiParser
+ ansiParser *ansiterm.AnsiParser
)
+func initTerminal() error {
+ winEventHandler := winterm.CreateWinEventHandler(os.Stdout.Fd(), os.Stdout)
+ if winEventHandler == nil {
+ err := syscall.GetLastError()
+ if err == nil {
+ err = errors.New("initialization failed")
+ }
+ return errors.Wrap(err, "windows terminal")
+ }
+ ansiParser = ansiterm.CreateParser("Ground", winEventHandler)
+ return nil
+}
+
func writeToTerminal(b []byte) {
- initAnsiParser.Do(func() {
- winEventHandler := winterm.CreateWinEventHandler(os.Stdout.Fd(), os.Stdout)
- ansiParser = ansiterm.CreateParser("Ground", winEventHandler)
- })
// Remove all non-ASCII characters until this is fixed
// https://github.com/Azure/go-ansiterm/issues/26
r := []rune(string(b))