forked from forgejo/forgejo
Add wildcard support to REPO_INDEXER_EXTENSIONS
This commit is contained in:
parent
021014acfe
commit
72a650c8e4
6 changed files with 42 additions and 29 deletions
|
@ -8,6 +8,10 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
)
|
||||
|
||||
// enumerates all the indexer queue types
|
||||
|
@ -30,8 +34,8 @@ var (
|
|||
IssueQueueDir string
|
||||
IssueQueueConnStr string
|
||||
IssueQueueBatchNumber int
|
||||
FileExtensions map[string]bool
|
||||
IncludeExtensions bool
|
||||
FilePatterns []glob.Glob
|
||||
IncludePatterns bool
|
||||
}{
|
||||
IssueType: "bleve",
|
||||
IssuePath: "indexers/issues.bleve",
|
||||
|
@ -54,8 +58,8 @@ func newIndexerService() {
|
|||
if !filepath.IsAbs(Indexer.RepoPath) {
|
||||
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
|
||||
}
|
||||
Indexer.FileExtensions = extensionsFromString(sec.Key("REPO_INDEXER_EXTENSIONS").MustString(""))
|
||||
Indexer.IncludeExtensions = sec.Key("REPO_EXTENSIONS_LIST_INCLUDE").MustBool(false)
|
||||
Indexer.FilePatterns = extensionsFromString(sec.Key("REPO_INDEXER_PATTERNS").MustString(""))
|
||||
Indexer.IncludePatterns = sec.Key("REPO_PATTERNS_INCLUDE").MustBool(false)
|
||||
|
||||
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
|
||||
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
|
||||
|
@ -65,25 +69,20 @@ func newIndexerService() {
|
|||
Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
|
||||
}
|
||||
|
||||
func extensionsFromString(from string) map[string]bool {
|
||||
extmap := make(map[string]bool)
|
||||
for _, ext := range strings.Split(strings.ToLower(from), ",") {
|
||||
ext = strings.TrimSpace(ext)
|
||||
// Accept *.txt, .txt and txt. Also use . to mean no ext
|
||||
if strings.HasPrefix(ext, "*.") {
|
||||
ext = ext[1:]
|
||||
}
|
||||
if ext == "." {
|
||||
extmap[""] = true
|
||||
} else {
|
||||
ext = strings.TrimPrefix(ext, ".")
|
||||
if ext != "" {
|
||||
extmap[ext] = true
|
||||
func extensionsFromString(from string) []glob.Glob {
|
||||
extarr := make([]glob.Glob, 0, 10)
|
||||
for _, expr := range strings.Split(strings.ToLower(from), ",") {
|
||||
expr = strings.TrimSpace(expr)
|
||||
if expr != "" {
|
||||
if g, err := glob.Compile(expr, '.', '/'); err != nil {
|
||||
log.Trace("Index file extensions: '%s': bad pattern: %v", expr, err)
|
||||
} else {
|
||||
extarr = append(extarr, g)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(extmap) == 0 {
|
||||
if len(extarr) == 0 {
|
||||
return nil
|
||||
}
|
||||
return extmap
|
||||
return extarr
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue