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
This commit is contained in:
Nick Craig-Wood 2024-06-15 10:04:28 +01:00
parent ff0ded8f11
commit 0e7c495395
1 changed files with 4 additions and 5 deletions

View File

@ -4,7 +4,6 @@ package size
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"strconv" "strconv"
@ -72,13 +71,13 @@ of the size command.
count := strconv.FormatInt(results.Count, 10) count := strconv.FormatInt(results.Count, 10)
countSuffix := fs.CountSuffix(results.Count).String() countSuffix := fs.CountSuffix(results.Count).String()
if count == countSuffix { if count == countSuffix {
fmt.Printf("Total objects: %s\n", count) operations.SyncPrintf("Total objects: %s\n", count)
} else { } 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 { 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 return nil
}) })