Fixes issues when running validator client with the --web flag and non existing validator.db file AND/OR prysm-wallet-v2 directory. (#13460)

* `getLegacyDatabaseLocation`: Add tests.

* `getLegacyDatabaseLocation`: Handle `c.wallet == nil`.

* `saveAuthToken`: Create parent directory if needed.
This commit is contained in:
Manu NALEPA
2024-01-12 16:53:27 +01:00
committed by GitHub
parent 6ddafe1159
commit 22a484c45e
4 changed files with 152 additions and 2 deletions

View File

@@ -149,7 +149,16 @@ func saveAuthToken(walletDirPath string, jwtKey []byte, token string) error {
if _, err := bytesBuf.WriteString("\n"); err != nil {
return err
}
return file.WriteFile(hashFilePath, bytesBuf.Bytes())
if err := file.MkdirAll(walletDirPath); err != nil {
return errors.Wrapf(err, "could not create directory %s", walletDirPath)
}
if err := file.WriteFile(hashFilePath, bytesBuf.Bytes()); err != nil {
return errors.Wrapf(err, "could not write to file %s", hashFilePath)
}
return nil
}
func readAuthTokenFile(r io.Reader) (secret []byte, token string, err error) {