1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 09:52:20 +08:00

fix panic caused by accessing config after repo closed

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-09-03 09:28:36 -07:00
parent 3fc1854d24
commit ab0c668ab8
14 changed files with 84 additions and 41 deletions

View File

@ -445,11 +445,8 @@ func (r *FSRepo) Close() error {
return nil
}
// Config returns the FSRepo's config. This method must not be called if the
// repo is not open.
//
// Result when not Open is undefined. The method may panic if it pleases.
func (r *FSRepo) Config() *config.Config {
func (r *FSRepo) Config() (*config.Config, error) {
// It is not necessary to hold the package lock since the repo is in an
// opened state. The package lock is _not_ meant to ensure that the repo is
@ -460,9 +457,9 @@ func (r *FSRepo) Config() *config.Config {
defer packageLock.Unlock()
if r.closed {
panic("repo is closed")
return nil, errors.New("cannot access config, repo not open")
}
return r.config
return r.config, nil
}
// setConfigUnsynced is for private use.