diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 02935b85f..9c7d8c0f4 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -65,15 +65,6 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { return errors.Fatal("Invalid arguments, either give one or more snapshot IDs or set filters.") } - repo, err := OpenRepository(gopts) - if err != nil { - return err - } - - if err = repo.LoadIndex(gopts.ctx); err != nil { - return err - } - // extract any specific directories to walk var dirs []string if len(args) > 1 { @@ -85,6 +76,15 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { } } + repo, err := OpenRepository(gopts) + if err != nil { + return err + } + + if err = repo.LoadIndex(gopts.ctx); err != nil { + return err + } + ctx, cancel := context.WithCancel(gopts.ctx) defer cancel() for sn := range FindFilteredSnapshots(ctx, repo, opts.Host, opts.Tags, opts.Paths, args[:1]) {