1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Make sure all needed mountpoint are present

This commit is contained in:
Guillaume J. Charmes 2013-08-08 11:25:02 -07:00
parent 075d30dbce
commit 18fc707fdf
No known key found for this signature in database
GPG key ID: B33E4642CB6E3FF3

View file

@ -194,15 +194,41 @@ func (graph *Graph) getDockerInitLayer() (string, error) {
// For all other errors, abort.
return "", err
}
// FIXME: how the hell do I break down this line in a way
// that is idiomatic and not ugly as hell?
if f, err := os.OpenFile(path.Join(initLayer, ".dockerinit"), os.O_CREATE|os.O_TRUNC, 0700); err != nil && !os.IsExist(err) {
// If file already existed, keep going.
// For all other errors, abort.
return "", err
} else {
f.Close()
for pth, typ := range map[string]string{
"/dev/pts": "dir",
"/dev/shm": "dir",
"/proc": "dir",
"/sys": "dir",
"/.dockerinit": "file",
"/etc/resolv.conf": "file",
// "var/run": "dir",
// "var/lock": "dir",
} {
if _, err := os.Stat(path.Join(initLayer, pth)); err != nil {
if os.IsNotExist(err) {
switch typ {
case "dir":
if err := os.MkdirAll(path.Join(initLayer, pth), 0755); err != nil {
return "", err
}
case "file":
if err := os.MkdirAll(path.Join(initLayer, path.Dir(pth)), 0755); err != nil {
return "", err
}
if f, err := os.OpenFile(path.Join(initLayer, pth), os.O_CREATE, 0755); err != nil {
return "", err
} else {
f.Close()
}
}
} else {
return "", err
}
}
}
// Layer is ready to use, if it wasn't before.
return initLayer, nil
}