Remove stat call from happy path
Just try to read the file, use it if it works. Only if the file does not exist, create default address book and try again.
This commit is contained in:
parent
86359a5e11
commit
e5db18e289
@ -154,17 +154,15 @@ func (b *filesystemBackend) AddressBook(ctx context.Context) (*carddav.AddressBo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
path = filepath.Join(path, "default.json")
|
path = filepath.Join(path, "default.json")
|
||||||
_, err = os.Stat(path)
|
|
||||||
|
data, err := ioutil.ReadFile(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
err = createDefaultAddressBook(path)
|
err = createDefaultAddressBook(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
data, err = ioutil.ReadFile(path)
|
||||||
return nil, fmt.Errorf("error opening address book: %s", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening address book: %s", err.Error())
|
return nil, fmt.Errorf("error opening address book: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user