forget: return error if no policy was specified

This commit is contained in:
Michael Eischer 2024-04-14 22:46:49 +02:00
parent c0e1f36830
commit 5b7952e426

View file

@ -222,11 +222,10 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
Tags: opts.KeepTags,
}
if policy.Empty() && len(args) == 0 {
printer.P("no policy was specified, no snapshots will be removed\n")
if policy.Empty() {
return errors.Fatal("no policy was specified, no snapshots will be removed")
}
if !policy.Empty() {
printer.P("Applying Policy: %v\n", policy)
for k, snapshotGroup := range snapshotGroups {
@ -250,9 +249,8 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
keep, remove, reasons := restic.ApplyPolicy(snapshotGroup, policy)
if !policy.Empty() && len(keep) == 0 {
return fmt.Errorf("refusing to delete last snapshot of snapshot group %v", key)
return fmt.Errorf("refusing to delete last snapshot of snapshot group \"%v\"", key.String())
}
if len(keep) != 0 && !gopts.Quiet && !gopts.JSON {
printer.P("keep %d snapshots:\n", len(keep))
PrintSnapshots(globalOptions.stdout, keep, reasons, opts.Compact)
@ -276,7 +274,6 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
}
}
}
}
if ctx.Err() != nil {
return ctx.Err()