From 221bef48c09c2052f21e951c53c5db096fd772dc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 7 Mar 2017 10:58:09 +0100 Subject: [PATCH] find: Add option to ignore case Closes #859 --- src/cmds/restic/cmd_find.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cmds/restic/cmd_find.go b/src/cmds/restic/cmd_find.go index ab628c414..cb9e6f594 100644 --- a/src/cmds/restic/cmd_find.go +++ b/src/cmds/restic/cmd_find.go @@ -2,6 +2,7 @@ package main import ( "path/filepath" + "strings" "time" "github.com/spf13/cobra" @@ -25,9 +26,10 @@ repo. `, // FindOptions bundle all options for the find command. type FindOptions struct { - Oldest string - Newest string - Snapshot string + Oldest string + Newest string + Snapshot string + CaseInsensitive bool } var findOptions FindOptions @@ -39,11 +41,13 @@ func init() { f.StringVarP(&findOptions.Oldest, "oldest", "o", "", "oldest modification date/time") f.StringVarP(&findOptions.Newest, "newest", "n", "", "newest modification date/time") f.StringVarP(&findOptions.Snapshot, "snapshot", "s", "", "snapshot ID to search in") + f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern") } type findPattern struct { oldest, newest time.Time pattern string + ignoreCase bool } type findResult struct { @@ -86,7 +90,12 @@ func findInTree(repo *repository.Repository, pat findPattern, id restic.ID, path for _, node := range tree.Nodes { debug.Log(" testing entry %q\n", node.Name) - m, err := filepath.Match(pat.pattern, node.Name) + name := node.Name + if pat.ignoreCase { + name = strings.ToLower(name) + } + + m, err := filepath.Match(pat.pattern, name) if err != nil { return nil, err } @@ -190,6 +199,11 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error { pat.pattern = args[0] + if opts.CaseInsensitive { + pat.pattern = strings.ToLower(pat.pattern) + pat.ignoreCase = true + } + if opts.Snapshot != "" { snapshotID, err := restic.FindSnapshot(repo, opts.Snapshot) if err != nil {