diff --git a/internal/index/build.go b/internal/index/build.go index 754c52b4..1835774a 100644 --- a/internal/index/build.go +++ b/internal/index/build.go @@ -53,18 +53,14 @@ type Data struct { } func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int) { - WriteProgress(&Progress{ - FileCount: 0, - IsDone: false, - LastDoneTime: nil, - }) + // TODO: partial remove indices + Reset() var batchs []*bleve.Batch var fileCount uint64 = 0 for _, indexPath := range indexPaths { batch := func() *bleve.Batch { batch := index.NewBatch() // TODO: cache unchanged part - // TODO: store current progress walkFn := func(indexPath string, info model.Obj, err error) error { for _, avoidPath := range ignorePaths { if indexPath == avoidPath { diff --git a/internal/index/index.go b/internal/index/index.go index 631cfb97..393c54a9 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -1,6 +1,9 @@ package index import ( + "os" + + "github.com/alist-org/alist/v3/internal/conf" "github.com/blevesearch/bleve/v2" log "github.com/sirupsen/logrus" ) @@ -28,3 +31,17 @@ func Init(indexPath *string) { }) } } + +func Reset() { + log.Infof("Removing old index...") + err := os.RemoveAll(conf.Conf.IndexDir) + if err != nil { + log.Fatal(err) + } + Init(&conf.Conf.IndexDir) + WriteProgress(&Progress{ + FileCount: 0, + IsDone: false, + LastDoneTime: nil, + }) +}