NewStoreWithPath create store with path
(path string)
| 55 | |
| 56 | // NewStoreWithPath create store with path |
| 57 | func 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 | |
| 81 | func OpenStore(storeName string) (*Store, error) { |
| 82 | store, err := NewStore(storeName) |
nothing calls this directly
no test coverage detected