MCPcopy
hub / github.com/pocketbase/pocketbase / filesContent

Function filesContent

plugins/jsvm/jsvm.go:537–570  ·  view source on GitHub ↗

filesContent returns a map with all direct files within the specified dir and their content. If directory with dirPath is missing or no files matching the pattern were found, it returns an empty map and no error. If pattern is empty string it matches all root files.

(dirPath string, pattern string)

Source from the content-addressed store, hash-verified

535//
536// If pattern is empty string it matches all root files.
537func filesContent(dirPath string, pattern string) (map[string][]byte, error) {
538 files, err := os.ReadDir(dirPath)
539 if err != nil {
540 if errors.Is(err, fs.ErrNotExist) {
541 return map[string][]byte{}, nil
542 }
543 return nil, err
544 }
545
546 var exp *regexp.Regexp
547 if pattern != "" {
548 var err error
549 if exp, err = regexp.Compile(pattern); err != nil {
550 return nil, err
551 }
552 }
553
554 result := map[string][]byte{}
555
556 for _, f := range files {
557 if f.IsDir() || (exp != nil && !exp.MatchString(f.Name())) {
558 continue
559 }
560
561 raw, err := os.ReadFile(filepath.Join(dirPath, f.Name()))
562 if err != nil {
563 return nil, err
564 }
565
566 result[f.Name()] = raw
567 }
568
569 return result, nil
570}

Callers 2

registerMigrationsMethod · 0.85
registerHooksMethod · 0.85

Calls 1

IsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…