Files
tailscale/ipn/ipnlocal/netmapcache/default_store.go
Claus Lensbøl 400247776e wip
Signed-off-by: Claus Lensbøl <[email protected]>
2026-11-23 16:39:35 -05:00

39 lines
1.1 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package netmapcache
import (
"context"
"errors"
"os"
"tailscale.com/types/logger"
)
// NewStore creates [Store] for backing the netmapcache. If the [Store] already
// exists, open the existing [Store]. If [HookNewStore] is set (e.g. by
// feature/netmapcachesqlite), that implementation is used instead of the
// default [FileStore].
func NewStore(ctx context.Context, dir string, logf logger.Logf) (Store, error) {
if f, ok := HookNewStore.GetOk(); ok {
return f(ctx, dir, logf)
}
return FileStore(dir), nil
}
// OpenStore opens an existing [Store]. Returns nil, nil, if the store does not
// exist. If [HookOpenStore] is set (e.g. by feature/netmapcachesqlite), that
// implementation is used instead of the default [FileStore].
func OpenStore(ctx context.Context, dir string, logf logger.Logf) (Store, error) {
if f, ok := HookOpenStore.GetOk(); ok {
return f(ctx, dir, logf)
}
if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) {
return nil, nil
} else if err != nil {
return nil, err
}
return FileStore(dir), nil
}