Skip to content

Commit 2383e85

Browse files
authoredNov 24, 2022
fix: reset index before build new one (#2471)
1 parent 330a767 commit 2383e85

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

‎internal/index/build.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,14 @@ type Data struct {
5353
}
5454

5555
func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int) {
56-
WriteProgress(&Progress{
57-
FileCount: 0,
58-
IsDone: false,
59-
LastDoneTime: nil,
60-
})
56+
// TODO: partial remove indices
57+
Reset()
6158
var batchs []*bleve.Batch
6259
var fileCount uint64 = 0
6360
for _, indexPath := range indexPaths {
6461
batch := func() *bleve.Batch {
6562
batch := index.NewBatch()
6663
// TODO: cache unchanged part
67-
// TODO: store current progress
6864
walkFn := func(indexPath string, info model.Obj, err error) error {
6965
for _, avoidPath := range ignorePaths {
7066
if indexPath == avoidPath {

‎internal/index/index.go

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package index
22

33
import (
4+
"os"
5+
6+
"github.com/alist-org/alist/v3/internal/conf"
47
"github.com/blevesearch/bleve/v2"
58
log "github.com/sirupsen/logrus"
69
)
@@ -28,3 +31,17 @@ func Init(indexPath *string) {
2831
})
2932
}
3033
}
34+
35+
func Reset() {
36+
log.Infof("Removing old index...")
37+
err := os.RemoveAll(conf.Conf.IndexDir)
38+
if err != nil {
39+
log.Fatal(err)
40+
}
41+
Init(&conf.Conf.IndexDir)
42+
WriteProgress(&Progress{
43+
FileCount: 0,
44+
IsDone: false,
45+
LastDoneTime: nil,
46+
})
47+
}

0 commit comments

Comments
 (0)