Commit dadcf970 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Improve scheme manager error handling

parent 691fc331
......@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"github.com/pkg/errors"
)
......@@ -61,6 +62,11 @@ func EnsureDirectoryExists(path string) error {
return os.Mkdir(path, 0700)
}
func Empty(path string) bool {
matches, _ := filepath.Glob(filepath.Join(path, "*"))
return len(matches) == 0
}
func Copy(src, dest string) error {
exists, err := PathExists(src)
if err != nil || !exists {
......
......@@ -129,7 +129,9 @@ func New(
if err != nil {
return nil, err
}
if err = cm.Configuration.ParseFolder(); err != nil {
err = cm.Configuration.ParseFolder()
_, isSchemeMgrErr := err.(*irma.SchemeManagerError)
if err != nil && !isSchemeMgrErr {
return nil, err
}
......
......@@ -34,10 +34,13 @@ var clientUpdates = []func(client *Client) error{
// Check the signatures of all scheme managers, if any is not ok,
// copy the entire irma_configuration folder from assets
conf := client.Configuration
if len(conf.DisabledSchemeManagers) > 0 {
return conf.CopyFromAssets(true)
}
for manager := range conf.SchemeManagers {
valid, err := conf.VerifySignature(manager)
if err != nil || !valid {
return conf.CopyFromAssets(false)
return conf.CopyFromAssets(true)
}
}
return nil
......
......@@ -75,7 +75,7 @@ func NewConfiguration(path string, assets string) (conf *Configuration, err erro
if err = fs.EnsureDirectoryExists(conf.path); err != nil {
return nil, err
}
if conf.assets != "" {
if conf.assets != "" && fs.Empty(conf.path) {
if err = conf.CopyFromAssets(false); err != nil {
return nil, err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment