[#1288] neofs-adm: Allow to store garbage in alphabet wallet dir

Check the full file name instead of just prefix. Also, fix a bug where
a single missing wallet could lead to an incorrect size calculation.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-04-05 10:16:35 +03:00 committed by Alex Vanin
parent 923db59149
commit a5cf38dcbf

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
@ -193,14 +192,15 @@ func openAlphabetWallets(walletDir string) ([]*wallet.Wallet, error) {
var size int var size int
loop: loop:
for i := range walletFiles { for i := 0; i < len(walletFiles); i++ {
for j := 0; j < len(walletFiles); j++ { name := innerring.GlagoliticLetter(i).String() + ".json"
letter := innerring.GlagoliticLetter(j).String() for j := range walletFiles {
if strings.HasPrefix(walletFiles[i].Name(), letter) { if walletFiles[j].Name() == name {
size++ size++
continue loop continue loop
} }
} }
break
} }
if size == 0 { if size == 0 {
return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)") return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)")