1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Restrict repository indexing by file extension

This commit is contained in:
Guillermo Prandi
2019-08-06 01:01:28 -03:00
parent 026696b87a
commit a85393b655
3 changed files with 35 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ package setting
import (
"path"
"path/filepath"
"strings"
)
// enumerates all the indexer queue types
@@ -29,6 +30,8 @@ var (
IssueQueueDir string
IssueQueueConnStr string
IssueQueueBatchNumber int
FileExtensions map[string]bool
ExcludeExtensions bool
}{
IssueType: "bleve",
IssuePath: "indexers/issues.bleve",
@@ -51,6 +54,9 @@ func newIndexerService() {
if !filepath.IsAbs(Indexer.RepoPath) {
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
}
Indexer.FileExtensions = extensionsFromString(sec.Key("REPO_INDEXER_EXTENSIONS").MustString(""))
Indexer.ExcludeExtensions = sec.Key("REPO_EXTENSIONS_LIST_EXCLUDE").MustBool(false)
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
@@ -58,3 +64,19 @@ func newIndexerService() {
Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString(path.Join(AppDataPath, ""))
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)
if ext == "." {
extmap[""] = true
} else if ext != "" && !strings.Contains(ext, ".") {
extmap[ext] = true
}
}
if len(extmap) == 0 {
return nil
}
return extmap
}