mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 22:27:35 +00:00
Merge pull request #864 from restic/find-case-insensitive
find: Add option to ignore case
This commit is contained in:
commit
340f2c80a0
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user