From 55d1f78bdac18073a76e0cf7cc52f12ae5b04968 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Fri, 23 Oct 2020 17:14:27 +0200 Subject: [PATCH] Fix delete for disk indexes --- accounts/pkg/indexer/index/disk/autoincrement.go | 2 +- accounts/pkg/indexer/index/disk/non_unique.go | 2 +- accounts/pkg/indexer/index/disk/unique.go | 2 +- accounts/pkg/indexer/indexer.go | 5 ++++- accounts/pkg/storage/disk.go | 8 ++++---- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/accounts/pkg/indexer/index/disk/autoincrement.go b/accounts/pkg/indexer/index/disk/autoincrement.go index d68665230..33bfd82b2 100644 --- a/accounts/pkg/indexer/index/disk/autoincrement.go +++ b/accounts/pkg/indexer/index/disk/autoincrement.go @@ -263,5 +263,5 @@ func (idx *Autoincrement) next() (int, error) { // Delete deletes the index folder from its storage. func (idx *Autoincrement) Delete() error { - return os.Remove(idx.indexRootDir) + return os.RemoveAll(idx.indexRootDir) } diff --git a/accounts/pkg/indexer/index/disk/non_unique.go b/accounts/pkg/indexer/index/disk/non_unique.go index 3dfa6bc18..d9fcf7508 100644 --- a/accounts/pkg/indexer/index/disk/non_unique.go +++ b/accounts/pkg/indexer/index/disk/non_unique.go @@ -236,5 +236,5 @@ func (idx *NonUnique) FilesDir() string { // Delete deletes the index folder from its storage. func (idx *NonUnique) Delete() error { - return os.Remove(idx.indexRootDir) + return os.RemoveAll(idx.indexRootDir) } diff --git a/accounts/pkg/indexer/index/disk/unique.go b/accounts/pkg/indexer/index/disk/unique.go index 751fd73de..a9252a334 100644 --- a/accounts/pkg/indexer/index/disk/unique.go +++ b/accounts/pkg/indexer/index/disk/unique.go @@ -223,5 +223,5 @@ func isValidSymlink(path string) (err error) { // Delete deletes the index folder from its storage. func (idx *Unique) Delete() error { - return os.Remove(idx.indexRootDir) + return os.RemoveAll(idx.indexRootDir) } diff --git a/accounts/pkg/indexer/indexer.go b/accounts/pkg/indexer/indexer.go index 69a28af51..e93baf9ed 100644 --- a/accounts/pkg/indexer/indexer.go +++ b/accounts/pkg/indexer/indexer.go @@ -47,7 +47,10 @@ func (i Indexer) Reset() error { for j := range i.indices { for _, indices := range i.indices[j].IndicesByField { for _, idx := range indices { - _ = idx.Delete() + err := idx.Delete() + if err != nil { + return err + } } } delete(i.indices, j) diff --git a/accounts/pkg/storage/disk.go b/accounts/pkg/storage/disk.go index 4d09e61b4..275c5a804 100644 --- a/accounts/pkg/storage/disk.go +++ b/accounts/pkg/storage/disk.go @@ -75,8 +75,8 @@ func (r DiskRepo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err er root := filepath.Join(r.cfg.Repo.Disk.Path, accountsFolder) return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { acc := &proto.Account{} - if err = r.LoadAccount(ctx, filepath.Base(path), acc); err != nil { - r.log.Err(err).Msg("could not load account") + if e := r.LoadAccount(ctx, filepath.Base(path), acc); e != nil { + r.log.Err(e).Msg("could not load account") return nil } *a = append(*a, acc) @@ -137,8 +137,8 @@ func (r DiskRepo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) root := filepath.Join(r.cfg.Repo.Disk.Path, groupsFolder) return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { grp := &proto.Group{} - if err = r.LoadGroup(ctx, filepath.Base(path), grp); err != nil { - r.log.Err(err).Msg("could not load group") + if e := r.LoadGroup(ctx, filepath.Base(path), grp); e != nil { + r.log.Err(e).Msg("could not load group") return nil } *g = append(*g, grp)