archiver: Refuse to save an empty snapshot

This commit is contained in:
Alexander Neumann 2018-05-20 15:58:55 +02:00
parent 9a02f17cc2
commit 1e9744c9a4
2 changed files with 18 additions and 1 deletions

View file

@ -762,6 +762,10 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
return restic.ID{}, ItemStats{}, err
}
if len(tree.Nodes) == 0 {
return restic.ID{}, ItemStats{}, errors.New("snapshot is empty")
}
return arch.saveTree(wctx, tree)
}()
debug.Log("saved tree, error: %v", err)

View file

@ -1343,6 +1343,7 @@ func TestArchiverSnapshotSelect(t *testing.T) {
src TestDir
want TestDir
selFn SelectFunc
err string
}{
{
name: "include-all",
@ -1377,7 +1378,7 @@ func TestArchiverSnapshotSelect(t *testing.T) {
selFn: func(item string, fi os.FileInfo) bool {
return false
},
want: TestDir{},
err: "snapshot is empty",
},
{
name: "exclude-txt-files",
@ -1462,6 +1463,18 @@ func TestArchiverSnapshotSelect(t *testing.T) {
targets := []string{"."}
_, snapshotID, err := arch.Snapshot(ctx, targets, SnapshotOptions{Time: time.Now()})
if test.err != "" {
if err == nil {
t.Fatalf("expected error not found, got %v, wanted %q", err, test.err)
}
if err.Error() != test.err {
t.Fatalf("unexpected error, want %q, got %q", test.err, err)
}
return
}
if err != nil {
t.Fatal(err)
}