提交 03bc2ccb 作者: Tommi Virtanen

Take FSRepo lock way earlier

There is no way this was safe before.

Be careful to unlock on the error paths.
上级 55228dae
...@@ -87,6 +87,18 @@ func open(repoPath string) (repo.Repo, error) { ...@@ -87,6 +87,18 @@ func open(repoPath string) (repo.Repo, error) {
path: expPath, path: expPath,
} }
r.lockfile, err = lockfile.Lock(r.path)
if err != nil {
return nil, err
}
keepLocked := false
defer func() {
// unlock on error, leave it locked on success
if !keepLocked {
r.lockfile.Close()
}
}()
if !isInitializedUnsynced(r.path) { if !isInitializedUnsynced(r.path) {
return nil, debugerror.New("ipfs not initialized, please run 'ipfs init'") return nil, debugerror.New("ipfs not initialized, please run 'ipfs init'")
} }
...@@ -108,11 +120,7 @@ func open(repoPath string) (repo.Repo, error) { ...@@ -108,11 +120,7 @@ func open(repoPath string) (repo.Repo, error) {
// log.Debugf("writing eventlogs to ...", c.path) // log.Debugf("writing eventlogs to ...", c.path)
configureEventLoggerAtRepoPath(r.config, r.path) configureEventLoggerAtRepoPath(r.config, r.path)
closer, err := lockfile.Lock(r.path) keepLocked = true
if err != nil {
return nil, err
}
r.lockfile = closer
return r, nil return r, nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论