From 0e7c495395acacf484fbf9e98dbff0bab01c518b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 15 Jun 2024 10:04:28 +0100 Subject: [PATCH] size: make output compatible with -P Before this change the output of `rclone size -P` would get corrupted by the progress printing. This is fixed by using operations.SyncPrintf instead of fmt.Printf. Fixes #7912 --- cmd/size/size.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/size/size.go b/cmd/size/size.go index 74414f574..05e570c4e 100644 --- a/cmd/size/size.go +++ b/cmd/size/size.go @@ -4,7 +4,6 @@ package size import ( "context" "encoding/json" - "fmt" "os" "strconv" @@ -72,13 +71,13 @@ of the size command. count := strconv.FormatInt(results.Count, 10) countSuffix := fs.CountSuffix(results.Count).String() if count == countSuffix { - fmt.Printf("Total objects: %s\n", count) + operations.SyncPrintf("Total objects: %s\n", count) } else { - fmt.Printf("Total objects: %s (%s)\n", countSuffix, count) + operations.SyncPrintf("Total objects: %s (%s)\n", countSuffix, count) } - fmt.Printf("Total size: %s (%d Byte)\n", fs.SizeSuffix(results.Bytes).ByteUnit(), results.Bytes) + operations.SyncPrintf("Total size: %s (%d Byte)\n", fs.SizeSuffix(results.Bytes).ByteUnit(), results.Bytes) if results.Sizeless > 0 { - fmt.Printf("Total objects with unknown size: %s (%d)\n", fs.CountSuffix(results.Sizeless), results.Sizeless) + operations.SyncPrintf("Total objects with unknown size: %s (%d)\n", fs.CountSuffix(results.Sizeless), results.Sizeless) } return nil })