mirror of
https://github.com/octoleo/restic.git
synced 2024-11-04 12:34:13 +00:00
parent
bf88a62a16
commit
221bef48c0
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -28,6 +29,7 @@ type FindOptions struct {
|
|||||||
Oldest string
|
Oldest string
|
||||||
Newest string
|
Newest string
|
||||||
Snapshot string
|
Snapshot string
|
||||||
|
CaseInsensitive bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var findOptions FindOptions
|
var findOptions FindOptions
|
||||||
@ -39,11 +41,13 @@ func init() {
|
|||||||
f.StringVarP(&findOptions.Oldest, "oldest", "o", "", "oldest modification date/time")
|
f.StringVarP(&findOptions.Oldest, "oldest", "o", "", "oldest modification date/time")
|
||||||
f.StringVarP(&findOptions.Newest, "newest", "n", "", "newest 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.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 {
|
type findPattern struct {
|
||||||
oldest, newest time.Time
|
oldest, newest time.Time
|
||||||
pattern string
|
pattern string
|
||||||
|
ignoreCase bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type findResult struct {
|
type findResult struct {
|
||||||
@ -86,7 +90,12 @@ func findInTree(repo *repository.Repository, pat findPattern, id restic.ID, path
|
|||||||
for _, node := range tree.Nodes {
|
for _, node := range tree.Nodes {
|
||||||
debug.Log(" testing entry %q\n", node.Name)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -190,6 +199,11 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
|||||||
|
|
||||||
pat.pattern = args[0]
|
pat.pattern = args[0]
|
||||||
|
|
||||||
|
if opts.CaseInsensitive {
|
||||||
|
pat.pattern = strings.ToLower(pat.pattern)
|
||||||
|
pat.ignoreCase = true
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Snapshot != "" {
|
if opts.Snapshot != "" {
|
||||||
snapshotID, err := restic.FindSnapshot(repo, opts.Snapshot)
|
snapshotID, err := restic.FindSnapshot(repo, opts.Snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user