Skip to content

Commit 4e08034

Browse files
committed
Enable auto-creation of host-path on Windows
Auto-creation of host-paths has been un-deprecated, so to have feature-parity between Linux and Windows, this feature should also be present on Windows. This enables auto-creation on Windows. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 926725b commit 4e08034

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

volume/volume.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package volume
33
import (
44
"fmt"
55
"os"
6-
"runtime"
76
"strings"
87

98
"github.com/docker/docker/pkg/stringid"
9+
"github.com/docker/docker/pkg/system"
1010
)
1111

1212
// DefaultDriverName is the driver name used for the driver
@@ -80,20 +80,20 @@ func (m *MountPoint) Setup() (string, error) {
8080
}
8181
return m.Volume.Mount(m.ID)
8282
}
83-
if len(m.Source) > 0 {
84-
if _, err := os.Stat(m.Source); err != nil {
85-
if !os.IsNotExist(err) {
86-
return "", err
87-
}
88-
if runtime.GOOS != "windows" { // Windows does not have deprecation issues here
89-
if err := os.MkdirAll(m.Source, 0755); err != nil {
90-
return "", err
91-
}
92-
}
83+
if len(m.Source) == 0 {
84+
return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
85+
}
86+
// system.MkdirAll() produces an error if m.Source exists and is a file (not a directory),
87+
// so first check if the path does not exist
88+
if _, err := os.Stat(m.Source); err != nil {
89+
if !os.IsNotExist(err) {
90+
return "", err
91+
}
92+
if err := system.MkdirAll(m.Source, 0755); err != nil {
93+
return "", err
9394
}
94-
return m.Source, nil
9595
}
96-
return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
96+
return m.Source, nil
9797
}
9898

9999
// Path returns the path of a volume in a mount point.

0 commit comments

Comments
 (0)