MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / NewStoreWithPath

Function NewStoreWithPath

internal/utils/kvstore/store.go:57–79  ·  view source on GitHub ↗

NewStoreWithPath create store with path

(path string)

Source from the content-addressed store, hash-verified

55
56// NewStoreWithPath create store with path
57func NewStoreWithPath(path string) (*Store, error) {
58 if !strings.HasSuffix(path, ".store") {
59 return nil, errors.New("store path must contains a '.store' suffix")
60 }
61
62 _, err := os.Stat(path)
63 if err != nil && os.IsNotExist(err) {
64 _ = os.MkdirAll(path, 0777)
65 }
66
67 var storeName = filepath.Base(path)
68 storeName = strings.TrimSuffix(storeName, ".store")
69
70 if !IsValidName(storeName) {
71 return nil, errors.New("invalid store name '" + storeName + "'")
72 }
73
74 return &Store{
75 name: storeName,
76 path: path,
77 locker: fsutils.NewLocker(path + "/.fs"),
78 }, nil
79}
80
81func OpenStore(storeName string) (*Store, error) {
82 store, err := NewStore(storeName)

Callers

nothing calls this directly

Calls 2

IsValidNameFunction · 0.85
StatMethod · 0.65

Tested by

no test coverage detected