99
1010 mounttypes "github.com/docker/docker/api/types/mount"
1111 "github.com/docker/docker/pkg/idtools"
12- "github.com/docker/docker/pkg/symlink"
1312 "github.com/docker/docker/pkg/stringid"
1413 "github.com/opencontainers/runc/libcontainer/label"
1514 "github.com/pkg/errors"
@@ -125,28 +124,23 @@ type MountPoint struct {
125124
126125// Setup sets up a mount point by either mounting the volume if it is
127126// configured, or creating the source directory if supplied.
128- func (m * MountPoint ) Setup (prefix , mountLabel string , rootUID , rootGID int ) (path string , err error ) {
129- symlinkRoot := prefix
130- if symlinkRoot == "" {
131- symlinkRoot = "/"
132- }
133- sourcePath , err := symlink .FollowSymlinkInScope (filepath .Join (prefix , m .Source ), symlinkRoot )
134- if err != nil {
135- path = ""
136- err = errors .Wrapf (err , "error evaluating symlink from mount source '%s'" , m .Source )
137- return
138- }
139-
127+ func (m * MountPoint ) Setup (mountLabel string , rootUID , rootGID int ) (path string , err error ) {
140128 defer func () {
141129 if err == nil {
142130 if label .RelabelNeeded (m .Mode ) {
131+ sourcePath , err := filepath .EvalSymlinks (m .Source )
132+ if err != nil {
133+ path = ""
134+ err = errors .Wrapf (err , "error evaluating symlink from mount source '%s'" , m .Source )
135+ return
136+ }
143137 err = label .Relabel (sourcePath , mountLabel , label .IsShared (m .Mode ))
144138 if err == syscall .ENOTSUP {
145139 err = nil
146140 }
147141 if err != nil {
148142 path = ""
149- err = errors .Wrapf (err , "error setting label on mount source '%s'" , sourcePath )
143+ err = errors .Wrapf (err , "error setting label on mount source '%s'" , m . Source )
150144 return
151145 }
152146 }
@@ -168,19 +162,19 @@ func (m *MountPoint) Setup(prefix, mountLabel string, rootUID, rootGID int) (pat
168162 if len (m .Source ) == 0 {
169163 return "" , fmt .Errorf ("Unable to setup mount point, neither source nor volume defined" )
170164 }
171- // system.MkdirAll() produces an error if source exists and is a file (not a directory),
165+ // system.MkdirAll() produces an error if m.Source exists and is a file (not a directory),
172166 if m .Type == mounttypes .TypeBind {
173- // idtools.MkdirAllNewAs() produces an error if source exists and is a file (not a directory)
167+ // idtools.MkdirAllNewAs() produces an error if m.Source exists and is a file (not a directory)
174168 // also, makes sure that if the directory is created, the correct remapped rootUID/rootGID will own it
175- if err := idtools .MkdirAllNewAs (sourcePath , 0755 , rootUID , rootGID ); err != nil {
169+ if err := idtools .MkdirAllNewAs (m . Source , 0755 , rootUID , rootGID ); err != nil {
176170 if perr , ok := err .(* os.PathError ); ok {
177171 if perr .Err != syscall .ENOTDIR {
178- return "" , errors .Wrapf (err , "error while creating mount source path '%s'" , sourcePath )
172+ return "" , errors .Wrapf (err , "error while creating mount source path '%s'" , m . Source )
179173 }
180174 }
181175 }
182176 }
183- return sourcePath , nil
177+ return m . Source , nil
184178}
185179
186180// Path returns the path of a volume in a mount point.
0 commit comments