From e5db18e289e1e3a5a58c9af08bb979199739dd25 Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Wed, 16 Mar 2022 15:02:18 +0100 Subject: [PATCH] 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. --- storage/filesystem.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/storage/filesystem.go b/storage/filesystem.go index 6de19e4..d958331 100644 --- a/storage/filesystem.go +++ b/storage/filesystem.go @@ -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()) }