Fix for creation of windows source directory in case it didn't exist

Signed-off-by: Ameya Gawde <agawde@mirantis.com>
This commit is contained in:
Ameya Gawde 2023-07-24 10:21:32 -07:00
parent 96b473a0bd
commit e6b06e24fd
No known key found for this signature in database
GPG key ID: 64765AF5C5C36611
3 changed files with 17 additions and 2 deletions

View file

@ -15,6 +15,7 @@ func TestLCOWParseMountRaw(t *testing.T) {
`/foo/`,
`/foo bar`,
`c:\:/foo`,
`c:\notexist:/foo`,
`c:\windows\:/foo`,
`c:\windows:/s p a c e`,
`c:\windows:/s p a c e:RW`,
@ -40,7 +41,6 @@ func TestLCOWParseMountRaw(t *testing.T) {
`c:\:/foo:xyzzy`: "invalid volume specification: ",
`/`: "destination can't be '/'",
`/..`: "destination can't be '/'",
`c:\notexist:/foo`: `source path does not exist: c:\notexist`,
`c:\windows\system32\ntdll.dll:/foo`: `source path must be a directory`,
`name<:/foo`: `invalid volume specification`,
`name>:/foo`: `invalid volume specification`,

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/system"
)
// NewWindowsParser creates a parser with Windows semantics.
@ -246,6 +247,11 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid
if err != nil {
return &errMountConfig{mnt, err}
}
if windowsDetectMountType(mnt.Target) == mount.TypeNamedPipe {
return &errMountConfig{mnt, fmt.Errorf("'%s' is not a valid bind path", mnt.Target)}
}
if !exists {
return &errMountConfig{mnt, errBindSourceDoesNotExist(mnt.Source)}
}
@ -336,6 +342,15 @@ func (p *windowsParser) parseMount(arr []string, raw, volumeDriver string, conve
spec.Type = windowsDetectMountType(spec.Source)
spec.ReadOnly = !p.ReadWrite(mode)
// We need to create source directory if it didn't exist for short hand bind mounts.
if spec.Type == mount.TypeBind {
if _, err := os.Stat(spec.Source); os.IsNotExist(err) {
if err := system.MkdirAllWithACL(spec.Source, 0, system.SddlAdministratorsLocalSystem); err != nil {
return nil, fmt.Errorf("failed to mkdir bind source path: %s", spec.Source)
}
}
}
// cannot assume that if a volume driver is passed in that we should set it
if volumeDriver != "" && spec.Type == mount.TypeVolume {
spec.VolumeOptions = &mount.VolumeOptions{

View file

@ -16,6 +16,7 @@ func TestWindowsParseMountRaw(t *testing.T) {
`d:\path`,
`d:\path with space`,
`c:\:d:\`,
`c:\notexist:d:`,
`c:\windows\:d:`,
`c:\windows:d:\s p a c e`,
`c:\windows:d:\s p a c e:RW`,
@ -45,7 +46,6 @@ func TestWindowsParseMountRaw(t *testing.T) {
`c:\:d:\:xyzzy`: "invalid volume specification: ",
`c:`: "cannot be `c:`",
`c:\`: "cannot be `c:`",
`c:\notexist:d:`: `source path does not exist: c:\notexist`,
`c:\windows\system32\ntdll.dll:d:`: `source path must be a directory`,
`name<:d:`: `invalid volume specification`,
`name>:d:`: `invalid volume specification`,