fs.meta.load load any dirs with prefix "important" (#3747)

* fs.meta.load load any dirs with prefix "important"

* replace dirPattern to dirPrefix

* help dirPrefix
This commit is contained in:
Konstantin Lebedev 2022-09-27 21:58:46 +05:00 committed by GitHub
parent b6d7556dda
commit faa6167b6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ func init() {
} }
type commandFsMetaLoad struct { type commandFsMetaLoad struct {
dirPrefix *string
} }
func (c *commandFsMetaLoad) Name() string { func (c *commandFsMetaLoad) Name() string {
@ -30,6 +31,7 @@ func (c *commandFsMetaLoad) Help() string {
fs.meta.load <filer_host>-<port>-<time>.meta fs.meta.load <filer_host>-<port>-<time>.meta
fs.meta.load -v=false <filer_host>-<port>-<time>.meta // skip printing out the verbose output fs.meta.load -v=false <filer_host>-<port>-<time>.meta // skip printing out the verbose output
fs.meta.load -dirPrefix=/buckets/important* <filer_host>.meta // load any dirs with prefix "important"
` `
} }
@ -44,6 +46,7 @@ func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io.
fileName := args[len(args)-1] fileName := args[len(args)-1]
metaLoadCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) metaLoadCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.dirPrefix = metaLoadCommand.String("dirPrefix", "", "load entries only with directories matching prefix")
verbose := metaLoadCommand.Bool("v", true, "verbose mode") verbose := metaLoadCommand.Bool("v", true, "verbose mode")
if err = metaLoadCommand.Parse(args[0 : len(args)-1]); err != nil { if err = metaLoadCommand.Parse(args[0 : len(args)-1]); err != nil {
return nil return nil
@ -83,11 +86,22 @@ func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io.
return err return err
} }
// check collection name pattern
entryFullName := string(util.FullPath(fullEntry.Dir).Child(fullEntry.Entry.Name))
if *c.dirPrefix != "" {
if !strings.HasPrefix(fullEntry.Dir, *c.dirPrefix) {
if *verbose {
fmt.Fprintf(writer, "not match dir prefix %s\n", entryFullName)
}
continue
}
}
if *verbose || lastLogTime.Add(time.Second).Before(time.Now()) { if *verbose || lastLogTime.Add(time.Second).Before(time.Now()) {
if !*verbose { if !*verbose {
lastLogTime = time.Now() lastLogTime = time.Now()
} }
fmt.Fprintf(writer, "load %s\n", util.FullPath(fullEntry.Dir).Child(fullEntry.Entry.Name)) fmt.Fprintf(writer, "load %s\n", entryFullName)
} }
fullEntry.Entry.Name = strings.ReplaceAll(fullEntry.Entry.Name, "/", "x") fullEntry.Entry.Name = strings.ReplaceAll(fullEntry.Entry.Name, "/", "x")