mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-28 13:57:52 +08:00
Take FSRepo lock way earlier
There is no way this was safe before. Be careful to unlock on the error paths.
This commit is contained in:
parent
55228dae11
commit
03bc2ccb9d
@ -87,6 +87,18 @@ func open(repoPath string) (repo.Repo, error) {
|
||||
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) {
|
||||
return nil, debugerror.New("ipfs not initialized, please run 'ipfs init'")
|
||||
}
|
||||
@ -108,11 +120,7 @@ func open(repoPath string) (repo.Repo, error) {
|
||||
// log.Debugf("writing eventlogs to ...", c.path)
|
||||
configureEventLoggerAtRepoPath(r.config, r.path)
|
||||
|
||||
closer, err := lockfile.Lock(r.path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.lockfile = closer
|
||||
keepLocked = true
|
||||
return r, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user