Files
Claus Lensbøl c687660ac5 ipn/ipnlocal{,/netmapcache}: extract file store in prep for new stores (#22266)
The filestore was the only implemented store but we want to be able to
add other stores depending on the platform.

Make space for compiling on more stores, though keep the file store as
the default option.

Updates #22265

Signed-off-by: Claus Lensbøl <[email protected]>
2026-11-13 09:51:10 -05:00

30 lines
725 B
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package netmapcache
import (
"context"
"errors"
"os"
)
// TODO(cmol): Add compiler flags when having more stores
// NewStore creates [Store] for backing the netmapcache. If the [Store] already
// exists, open the existing [Store].
func NewStore(_ context.Context, dir string) (Store, error) {
return FileStore(dir), nil
}
// OpenStore opens an existing [Store]. Returns nil, nil, if the store does not
// exist.
func OpenStore(_ context.Context, dir string) (Store, error) {
if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) {
return nil, nil
} else if err != nil {
return nil, err
}
return FileStore(dir), nil
}