@cryptotaxi247 / kubo / commits / ac530d0ab

refactor(fsrepo) move Close under Open

Brian Tiger Chow committed Jan 14, 2015 at 04:06 UTC ac530d0ab6a01c81420d8804c3fb6ad71c3c4ebb
1 file changed +12 -11
repo/fsrepo/fsrepo.go
+12 -11
@@ -72,6 +72,7 @@ func ConfigAt(repoPath string) (*config.Config, error) {
72 }
73
74 // Init initializes a new FSRepo at the given path with the provided config.
75 +// TODO add support for custom datastores.
76 func Init(path string, conf *config.Config) error {
77
78 // packageLock must be held to ensure that the repo is not initialized more
@@ -175,6 +176,17 @@ func (r *FSRepo) Open() error {
176 return transitionToOpened(r)
177 }
178
179 +// Close closes the FSRepo, releasing held resources.
180 +func (r *FSRepo) Close() error {
181 + packageLock.Lock()
182 + defer packageLock.Unlock()
183 +
184 + if r.state != opened {
185 + return debugerror.Errorf("repo is %s", r.state)
186 + }
187 + return transitionToClosed(r)
188 +}
189 +
190 // Config returns the FSRepo's config. This method must not be called if the
191 // repo is not open.
192 //
@@ -253,17 +265,6 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
265 return r.setConfigUnsynced(conf)
266 }
267
256 -// Close closes the FSRepo, releasing held resources.
257 -func (r *FSRepo) Close() error {
258 - packageLock.Lock()
259 - defer packageLock.Unlock()
260 -
261 - if r.state != opened {
262 - return debugerror.Errorf("repo is %s", r.state)
263 - }
264 - return transitionToClosed(r)
265 -}
266 -
268 var _ io.Closer = &FSRepo{}
269 var _ repo.Repo = &FSRepo{}
270