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

Function OpenStoreDir

internal/utils/kvstore/store.go:94–116  ·  view source on GitHub ↗
(dir string, storeName string)

Source from the content-addressed store, hash-verified

92}
93
94func OpenStoreDir(dir string, storeName string) (*Store, error) {
95 if !IsValidName(storeName) {
96 return nil, errors.New("invalid store name '" + storeName + "'")
97 }
98
99 var path = strings.TrimSuffix(dir, "/") + "/" + storeName + StoreSuffix
100 _, err := os.Stat(path)
101 if err != nil && os.IsNotExist(err) {
102 _ = os.MkdirAll(path, 0777)
103 }
104
105 var store = &Store{
106 name: storeName,
107 path: path,
108 locker: fsutils.NewLocker(path + "/.fs"),
109 }
110
111 err = store.Open()
112 if err != nil {
113 return nil, err
114 }
115 return store, nil
116}
117
118var storeOnce = &sync.Once{}
119var defaultSore *Store

Callers 2

TestOpenStoreDirFunction · 0.92
OpenMethod · 0.92

Calls 3

IsValidNameFunction · 0.85
StatMethod · 0.65
OpenMethod · 0.45

Tested by 1

TestOpenStoreDirFunction · 0.74