2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-10 15:21:03 +00:00

Output warnings/errors to configurable writer

This commit is contained in:
Alexander Neumann 2015-06-21 15:20:54 +02:00
parent cfaf8ab8a6
commit 675f341b6d
3 changed files with 6 additions and 7 deletions

View File

@ -262,7 +262,7 @@ func (cmd CmdBackup) Execute(args []string) error {
arch.Error = func(dir string, fi os.FileInfo, err error) error { arch.Error = func(dir string, fi os.FileInfo, err error) error {
// TODO: make ignoring errors configurable // TODO: make ignoring errors configurable
fmt.Fprintf(os.Stderr, "\x1b[2K\rerror for %s: %v\n", dir, err) cmd.global.Warnf("\x1b[2K\rerror for %s: %v\n", dir, err)
return nil return nil
} }

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"github.com/restic/restic" "github.com/restic/restic"
@ -51,12 +50,11 @@ func (cmd CmdRestore) Execute(args []string) error {
// create restorer // create restorer
res, err := restic.NewRestorer(s, id) res, err := restic.NewRestorer(s, id)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "creating restorer failed: %v\n", err) cmd.global.Exitf(2, "creating restorer failed: %v\n", err)
os.Exit(2)
} }
res.Error = func(dir string, node *restic.Node, err error) error { res.Error = func(dir string, node *restic.Node, err error) error {
fmt.Fprintf(os.Stderr, "error for %s: %+v\n", dir, err) cmd.global.Warnf("error for %s: %+v\n", dir, err)
// if node.Type == "dir" { // if node.Type == "dir" {
// if e, ok := err.(*os.PathError); ok { // if e, ok := err.(*os.PathError); ok {

View File

@ -24,9 +24,10 @@ type GlobalOptions struct {
password string password string
stdout io.Writer stdout io.Writer
stderr io.Writer
} }
var globalOpts = GlobalOptions{stdout: os.Stdout} var globalOpts = GlobalOptions{stdout: os.Stdout, stderr: os.Stderr}
var parser = flags.NewParser(&globalOpts, flags.Default) var parser = flags.NewParser(&globalOpts, flags.Default)
func (o GlobalOptions) Printf(format string, args ...interface{}) { func (o GlobalOptions) Printf(format string, args ...interface{}) {
@ -58,7 +59,7 @@ func (o GlobalOptions) ShowProgress() bool {
} }
func (o GlobalOptions) Warnf(format string, args ...interface{}) { func (o GlobalOptions) Warnf(format string, args ...interface{}) {
_, err := fmt.Fprintf(os.Stderr, format, args...) _, err := fmt.Fprintf(o.stderr, format, args...)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stderr: %v\n", err) fmt.Fprintf(os.Stderr, "unable to write to stderr: %v\n", err)
os.Exit(100) os.Exit(100)