From 14d2799b44b08587ab1695ae42a5e602ec7dae04 Mon Sep 17 00:00:00 2001 From: Srigovind Nayak Date: Sat, 1 Jun 2024 18:04:14 +0530 Subject: [PATCH] fix: move include and exclude pattern validations to top --- cmd/restic/cmd_restore.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index e833f7c83..44394769c 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -73,6 +73,16 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, hasExcludes := len(opts.Excludes) > 0 || len(opts.InsensitiveExcludes) > 0 hasIncludes := len(opts.Includes) > 0 || len(opts.InsensitiveIncludes) > 0 + excludePatterns, err := opts.excludePatternOptions.CollectPatterns() + if err != nil { + return err + } + + includePatterns, err := opts.includePatternOptions.CollectPatterns() + if err != nil { + return err + } + switch { case len(args) == 0: return errors.Fatal("no snapshot ID specified") @@ -139,11 +149,6 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, msg.E("Warning: %s\n", message) } - excludePatterns, err := opts.excludePatternOptions.CollectPatterns() - if err != nil { - return err - } - selectExcludeFilter := func(item string, _ string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { for _, rejectFn := range excludePatterns { matched := rejectFn(item) @@ -160,11 +165,6 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, return selectedForRestore, childMayBeSelected } - includePatterns, err := opts.includePatternOptions.CollectPatterns() - if err != nil { - return err - } - selectIncludeFilter := func(item string, _ string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { for _, includeFn := range includePatterns { selectedForRestore, childMayBeSelected = includeFn(item)