mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix overlay use of rootdir and defer
Check for the rootDir first because the mergeDir may not exist if root is present. Also fix unmounting in the defer to make sure it does not have a refcount. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
4bac8bce98
commit
36a82c2032
1 changed files with 8 additions and 9 deletions
|
@ -333,23 +333,22 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
|
|||
if _, err := os.Stat(dir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// If id has a root, just return it
|
||||
rootDir := path.Join(dir, "root")
|
||||
if _, err := os.Stat(rootDir); err == nil {
|
||||
return rootDir, nil
|
||||
}
|
||||
mergedDir := path.Join(dir, "merged")
|
||||
if count := d.ctr.Increment(mergedDir); count > 1 {
|
||||
return mergedDir, nil
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
d.ctr.Decrement(mergedDir)
|
||||
syscall.Unmount(mergedDir, 0)
|
||||
if c := d.ctr.Decrement(mergedDir); c <= 0 {
|
||||
syscall.Unmount(mergedDir, 0)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// If id has a root, just return it
|
||||
rootDir := path.Join(dir, "root")
|
||||
if _, err := os.Stat(rootDir); err == nil {
|
||||
return rootDir, nil
|
||||
}
|
||||
|
||||
lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
Loading…
Reference in a new issue