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:
Conrad Hoffmann 2022-03-16 15:02:18 +01:00
parent 86359a5e11
commit e5db18e289

View File

@ -154,17 +154,15 @@ func (b *filesystemBackend) AddressBook(ctx context.Context) (*carddav.AddressBo
return nil, err
}
path = filepath.Join(path, "default.json")
_, err = os.Stat(path)
data, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
err = createDefaultAddressBook(path)
if err != nil {
return nil, err
}
} else if err != nil {
return nil, fmt.Errorf("error opening address book: %s", err.Error())
data, err = ioutil.ReadFile(path)
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error opening address book: %s", err.Error())
}