Don't Printf already formatted output

Fixes #2281.
This commit is contained in:
curiousleo 2019-05-26 21:23:53 +02:00 committed by Leo R. Lundgren
parent ecdf49679e
commit f6f240573a
2 changed files with 19 additions and 3 deletions

View file

@ -156,7 +156,7 @@ func (s *statefulOutput) PrintPatternJSON(path string, node *restic.Node) {
if s.hits > 0 { if s.hits > 0 {
Printf(",") Printf(",")
} }
Printf(string(b)) Print(string(b))
s.hits++ s.hits++
} }
@ -168,7 +168,7 @@ func (s *statefulOutput) PrintPatternNormal(path string, node *restic.Node) {
s.oldsn = s.newsn s.oldsn = s.newsn
Verbosef("Found matching entries in snapshot %s from %s\n", s.oldsn.ID().Str(), s.oldsn.Time.Local().Format(TimeFormat)) Verbosef("Found matching entries in snapshot %s from %s\n", s.oldsn.ID().Str(), s.oldsn.Time.Local().Format(TimeFormat))
} }
Printf(formatNode(path, node, s.ListLong) + "\n") Println(formatNode(path, node, s.ListLong))
} }
func (s *statefulOutput) PrintPattern(path string, node *restic.Node) { func (s *statefulOutput) PrintPattern(path string, node *restic.Node) {
@ -207,7 +207,7 @@ func (s *statefulOutput) PrintObjectJSON(kind, id, nodepath, treeID string, sn *
if s.hits > 0 { if s.hits > 0 {
Printf(",") Printf(",")
} }
Printf(string(b)) Print(string(b))
s.hits++ s.hits++
} }

View file

@ -189,6 +189,22 @@ func Printf(format string, args ...interface{}) {
} }
} }
// Print writes the message to the configured stdout stream.
func Print(args ...interface{}) {
_, err := fmt.Fprint(globalOptions.stdout, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err)
}
}
// Println writes the message to the configured stdout stream.
func Println(args ...interface{}) {
_, err := fmt.Fprintln(globalOptions.stdout, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err)
}
}
// Verbosef calls Printf to write the message when the verbose flag is set. // Verbosef calls Printf to write the message when the verbose flag is set.
func Verbosef(format string, args ...interface{}) { func Verbosef(format string, args ...interface{}) {
if globalOptions.verbosity >= 1 { if globalOptions.verbosity >= 1 {