Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cells-fuse: ability to search by node uuid #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions cmd/cells-fuse/c-lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
lookupGlob string
lookupI bool
lookupType string
lookupUuid string
)

var LookupCmd = &cobra.Command{
Expand All @@ -42,13 +43,15 @@ EXAMPLES
3. List all files under an existing folder /folder/path
$ ` + os.Args[0] + ` lookup --snapshot file:///var/cells/data/pydiods1/snapshot.db --name "*" --type file --base "/folder/path"

4. Search file by uuid
$ ` + os.Args[0] + ` lookup --snapshot file:///var/cells/data/pydiods1/snapshot.db --uuid "146afdbb-0056-4862-91fe-d996a2d05555"
`,
RunE: func(cmd *cobra.Command, args []string) error {
if storageURL == "" {
return fmt.Errorf("please provide a snapshot URL")
}
if lookupGlob == "" {
return fmt.Errorf("please provide a filename or a glob matcher like *")
if lookupGlob == "" && lookupUuid == ""{
return fmt.Errorf("please provide a filename or a glob matcher like * or an uuid")
}
if lookupI {
lookupGlob = strings.ToLower(lookupGlob)
Expand All @@ -72,20 +75,21 @@ EXAMPLES
if lookupType == "folder" && node.IsLeaf() {
return nil
}
if gw.Match(base) {

if gw.Match(base) || lookupUuid == node.GetUuid() {
if !header {
fmt.Println(promptui.IconGood + " Found Matches!")
fmt.Println("")
fmt.Println("Type \t | MTime \t | Size \t | Path")
fmt.Println("----- \t | ----- \t | ----- \t | -----")
fmt.Println("Type \t | MTime \t | Size \t | Uuid \t\t\t\t | Path ")
fmt.Println("----- \t | ----- \t | ----- \t | ----- \t\t\t\t | -----")
header = true
}
typeName := "Folder"
if node.IsLeaf() {
typeName = "File"
}
mTime := time.Unix(node.GetMTime(), 0).Format("06-01-02")
fmt.Println(typeName + "\t | " + mTime + "\t | " + humanize.IBytes(uint64(node.GetSize())) + "\t | " + node.GetPath())
fmt.Println(typeName + "\t | " + mTime + "\t | " + humanize.IBytes(uint64(node.GetSize())) + "\t | " + node.GetUuid() + "\t | " + node.GetPath())
}
return nil
}, lookupBase, true)
Expand All @@ -106,5 +110,6 @@ func init() {
LookupCmd.Flags().StringVarP(&lookupGlob, "name", "n", "", "Filename to search (using wildcards for glob). Searching for \"*\" will list all files.")
LookupCmd.Flags().BoolVarP(&lookupI, "insensitive", "i", false, "Search with insensitive case.")
LookupCmd.Flags().StringVarP(&lookupType, "type", "t", "", "Restrict to files ('file') or folders ('folder')")
LookupCmd.Flags().StringVarP(&lookupUuid, "uuid", "u", "", "Search by uuid")
FuseCmd.AddCommand(LookupCmd)
}