MCPcopy
hub / github.com/perkeep/perkeep / RunCommand

Method RunCommand

cmd/pk/dp_idx_rebuild.go:61–136  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

59}
60
61func (c *reindexdpCmd) RunCommand(args []string) error {
62 var path string
63 var indexConf jsonconfig.Obj
64
65 switch len(args) {
66 case 0:
67 case 1:
68 path = args[0]
69 default:
70 return errors.New("More than 1 argument not allowed")
71 }
72 cfg, err := serverinit.LoadFile(osutil.UserServerConfigPath())
73 if err != nil {
74 return err
75 }
76 low := cfg.LowLevelJSONConfig() //lint:ignore SA1019 we use it
77 prefixes, ok := low["prefixes"].(map[string]interface{})
78 if !ok {
79 return fmt.Errorf("No 'prefixes' object in low-level (or converted) config file %s", osutil.UserServerConfigPath())
80 }
81 paths, confs := []string{}, []jsonconfig.Obj{}
82 for prefix, vei := range prefixes {
83 pmap, ok := vei.(map[string]interface{})
84 if !ok {
85 log.Printf("prefix %q value is a %T, not an object", prefix, vei)
86 continue
87 }
88 pconf := jsonconfig.Obj(pmap)
89 handlerType := pconf.RequiredString("handler")
90 handlerArgs := pconf.OptionalObject("handlerArgs")
91 // no pconf.Validate, as this is a recover tool
92 if handlerType != "storage-diskpacked" {
93 continue
94 }
95 log.Printf("handlerArgs of %q: %v", prefix, handlerArgs)
96 if handlerArgs == nil {
97 log.Printf("no handlerArgs for %q", prefix)
98 continue
99 }
100 aconf := jsonconfig.Obj(handlerArgs)
101 apath := aconf.RequiredString("path")
102 // no aconv.Validate, as this is a recover tool
103 if apath == "" {
104 log.Printf("path is missing for %q", prefix)
105 continue
106 }
107 if path != "" && path != apath {
108 continue
109 }
110 paths = append(paths, apath)
111 confs = append(confs, aconf)
112 }
113 if len(paths) == 0 {
114 return fmt.Errorf("server config file %s doesn't specify a disk-packed storage handler",
115 osutil.UserServerConfigPath())
116 }
117 if len(paths) > 1 {
118 return fmt.Errorf("Ambiguity. Server config file %s d specify more than 1 disk-packed storage handler. Please specify one of: %v", osutil.UserServerConfigPath(), paths)

Callers

nothing calls this directly

Calls 7

LoadFileFunction · 0.92
UserServerConfigPathFunction · 0.92
CtxSetVerboseFunction · 0.92
IsDebugFunction · 0.92
ReindexFunction · 0.92
LowLevelJSONConfigMethod · 0.80
PrintfMethod · 0.80

Tested by

no test coverage detected