aboutsummaryrefslogtreecommitdiffstats
path: root/modules/indexer
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2021-11-15 13:16:11 +0000
committerGitHub <noreply@github.com>2021-11-15 21:16:11 +0800
commitab1379743e812eb1430e4d15a00c3f7b9e759da6 (patch)
tree81dfccc630574b917035842431b4d0e7c938a100 /modules/indexer
parent253d9e415813e90543cca8d94112c9e4238d39a4 (diff)
downloadgitea-ab1379743e812eb1430e4d15a00c3f7b9e759da6.tar.gz
gitea-ab1379743e812eb1430e4d15a00c3f7b9e759da6.zip
Fix nil checking on typed interface (#17598)
* Fix nil checking on typed interface - Partially resoles #17596 - Resolves SA4023 errors. - Ensure correctly that typed interface are nil. * Remove unnecessary code `NewBleveIndexer` will never return nil, even on errors. * Patch `NewBleveIndexer` * Fix low-level functions * Remove deadcode * Fix GetSession * Close Elastic search when err isn't nil * Update elastic_search.go Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/indexer')
-rw-r--r--modules/indexer/code/bleve.go4
-rw-r--r--modules/indexer/code/elastic_search.go5
-rw-r--r--modules/indexer/code/indexer.go6
3 files changed, 8 insertions, 7 deletions
diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go
index 8e5df34e60..66b2602d3b 100644
--- a/modules/indexer/code/bleve.go
+++ b/modules/indexer/code/bleve.go
@@ -173,6 +173,10 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) {
indexDir: indexDir,
}
created, err := indexer.init()
+ if err != nil {
+ indexer.Close()
+ return nil, false, err
+ }
return indexer, created, err
}
diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go
index 49633c3191..f76f316f64 100644
--- a/modules/indexer/code/elastic_search.go
+++ b/modules/indexer/code/elastic_search.go
@@ -82,7 +82,10 @@ func NewElasticSearchIndexer(url, indexerName string) (*ElasticSearchIndexer, bo
indexerAliasName: indexerName,
}
exists, err := indexer.init()
-
+ if err != nil {
+ indexer.Close()
+ return nil, false, err
+ }
return indexer, !exists, err
}
diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go
index 981167a825..c56b1b2bb0 100644
--- a/modules/indexer/code/indexer.go
+++ b/modules/indexer/code/indexer.go
@@ -185,9 +185,6 @@ func Init() {
rIndexer, populate, err = NewBleveIndexer(setting.Indexer.RepoPath)
if err != nil {
- if rIndexer != nil {
- rIndexer.Close()
- }
cancel()
indexer.Close()
close(waitChannel)
@@ -205,9 +202,6 @@ func Init() {
rIndexer, populate, err = NewElasticSearchIndexer(setting.Indexer.RepoConnStr, setting.Indexer.RepoIndexerName)
if err != nil {
- if rIndexer != nil {
- rIndexer.Close()
- }
cancel()
indexer.Close()
close(waitChannel)