Merge pull request #3566 from tianon/fix-volume-symlinks

Fix symlink mounting issues
This commit is contained in:
Guillaume J. Charmes 2014-01-21 11:37:05 -08:00
commit e56562c35e
1 changed files with 17 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import (
"net" "net"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
@ -644,7 +645,14 @@ func (container *Container) Start() (err error) {
mountAs = "rw" mountAs = "rw"
} }
if err := mount.Mount(v, path.Join(root, r), "none", fmt.Sprintf("bind,%s", mountAs)); err != nil { r = path.Join(root, r)
if p, err := utils.FollowSymlinkInScope(r, root); err != nil {
return err
} else {
r = p
}
if err := mount.Mount(v, r, "none", fmt.Sprintf("bind,%s", mountAs)); err != nil {
return err return err
} }
} }
@ -805,7 +813,7 @@ func (container *Container) createVolumes() error {
if strings.ToLower(bindMap.Mode) == "rw" { if strings.ToLower(bindMap.Mode) == "rw" {
srcRW = true srcRW = true
} }
if stat, err := os.Lstat(bindMap.SrcPath); err != nil { if stat, err := os.Stat(bindMap.SrcPath); err != nil {
return err return err
} else { } else {
volIsDir = stat.IsDir() volIsDir = stat.IsDir()
@ -826,6 +834,13 @@ func (container *Container) createVolumes() error {
} }
srcRW = true // RW by default srcRW = true // RW by default
} }
if p, err := filepath.EvalSymlinks(srcPath); err != nil {
return err
} else {
srcPath = p
}
container.Volumes[volPath] = srcPath container.Volumes[volPath] = srcPath
container.VolumesRW[volPath] = srcRW container.VolumesRW[volPath] = srcRW