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:
parent
cfaf8ab8a6
commit
675f341b6d
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user