mirror of https://github.com/restic/restic.git
archiver: Refuse to save an empty snapshot
This commit is contained in:
parent
9a02f17cc2
commit
1e9744c9a4
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue