From c133065a9fa418a2fcb8cb21149f8bd6308ce508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Thu, 16 Mar 2023 08:13:15 +0100 Subject: [PATCH] Check command result before snapshotting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return with an error containing the stderr of the given command in case it fails. No new snapshot will be created and future prune operations on the repository will remove the unreferenced data. Signed-off-by: Sebastian Hoß --- internal/archiver/archiver.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index ed1eb62bd..91f991e7d 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -796,6 +796,15 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps return nil, restic.ID{}, err } + if opts.Command != nil { + errBytes, _ := io.ReadAll(opts.CommandStderr) + cmdErr := opts.Command.Wait() + if cmdErr != nil { + debug.Log("error while executing command: %v", cmdErr) + return nil, restic.ID{}, errors.New(string(errBytes)) + } + } + sn, err := restic.NewSnapshot(targets, opts.Tags, opts.Hostname, opts.Time) if err != nil { return nil, restic.ID{}, err