From 483129c247f143a51a89ec85ecbcde29f1f856e5 Mon Sep 17 00:00:00 2001 From: tran Date: Mon, 2 Sep 2024 13:55:30 +0200 Subject: [PATCH] enable uuid --- cmd/cells-fuse/c-lookup.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/cells-fuse/c-lookup.go b/cmd/cells-fuse/c-lookup.go index b116f82e39..38116304eb 100644 --- a/cmd/cells-fuse/c-lookup.go +++ b/cmd/cells-fuse/c-lookup.go @@ -20,6 +20,7 @@ var ( lookupGlob string lookupI bool lookupType string + lookupUuid string ) var LookupCmd = &cobra.Command{ @@ -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) @@ -72,12 +75,13 @@ 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" @@ -85,7 +89,7 @@ EXAMPLES 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) @@ -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) }