mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 08:06:49 -05:00
8735fcdb7d
- The [rupture](https://github.com/ethantkoenig/rupture) dependency was essentially outdated in the sense it was using old version of dependencies. - The usage by Forgejo was rather a small portion, so that portion is now vendored (with its tests). - Removes old dependencies from go.sum (less dependencies is better for reviewing what the heck we're importing). Just to note that they were likely not being used by Go's build process (according to https://go.dev/ref/mod#minimal-version-selection), so it's really a matter of formal cleaning up dependencies we don't use and therefor don't want to download and be in our go.sum. (cherry picked from commitaa72a5f009
) Conflicts: go.sum https://codeberg.org/forgejo/forgejo/pulls/2148 (cherry picked from commitfbe8d65f0b
) (cherry picked from commite18debcb6a
) Conflicts: go.sum https://codeberg.org/forgejo/forgejo/pulls/2245 (cherry picked from commit8c43c2ada8
)
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package bleve
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
"github.com/blevesearch/bleve/v2"
|
|
"github.com/blevesearch/bleve/v2/index/upsidedown"
|
|
)
|
|
|
|
// openIndexer open the index at the specified path, checking for metadata
|
|
// updates and bleve version updates. If index needs to be created (or
|
|
// re-created), returns (nil, nil)
|
|
func openIndexer(path string, latestVersion int) (bleve.Index, int, error) {
|
|
_, err := os.Stat(path)
|
|
if err != nil && os.IsNotExist(err) {
|
|
return nil, 0, nil
|
|
} else if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
metadata, err := readIndexMetadata(path)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if metadata.Version < latestVersion {
|
|
// the indexer is using a previous version, so we should delete it and
|
|
// re-populate
|
|
return nil, metadata.Version, util.RemoveAll(path)
|
|
}
|
|
|
|
index, err := bleve.Open(path)
|
|
if err != nil {
|
|
if errors.Is(err, upsidedown.IncompatibleVersion) {
|
|
log.Warn("Indexer was built with a previous version of bleve, deleting and rebuilding")
|
|
return nil, 0, util.RemoveAll(path)
|
|
}
|
|
return nil, 0, err
|
|
}
|
|
|
|
return index, 0, nil
|
|
}
|