mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 14:17:21 +01:00
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
1 changed files with 3 additions and 5 deletions
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue