2015-07-16 17:14:58 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
2016-01-20 18:32:02 -05:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-04-26 22:26:12 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/container"
|
2016-01-20 18:32:02 -05:00
|
|
|
)
|
2015-11-12 14:55:17 -05:00
|
|
|
|
2015-07-16 17:14:58 -04:00
|
|
|
// checkIfPathIsInAVolume checks if the path is in a volume. If it is, it
|
|
|
|
// cannot be in a read-only volume. If it is not in a volume, the container
|
|
|
|
// cannot be configured with a read-only rootfs.
|
2015-11-12 14:55:17 -05:00
|
|
|
func checkIfPathIsInAVolume(container *container.Container, absPath string) (bool, error) {
|
2015-07-16 17:14:58 -04:00
|
|
|
var toVolume bool
|
|
|
|
for _, mnt := range container.MountPoints {
|
2015-09-09 22:23:06 -04:00
|
|
|
if toVolume = mnt.HasResource(absPath); toVolume {
|
2015-07-16 17:14:58 -04:00
|
|
|
if mnt.RW {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return false, ErrVolumeReadonly
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toVolume, nil
|
|
|
|
}
|
2016-01-20 18:32:02 -05:00
|
|
|
|
|
|
|
func fixPermissions(source, destination string, uid, gid int, destExisted bool) error {
|
|
|
|
// If the destination didn't already exist, or the destination isn't a
|
|
|
|
// directory, then we should Lchown the destination. Otherwise, we shouldn't
|
|
|
|
// Lchown the destination.
|
|
|
|
destStat, err := os.Stat(destination)
|
|
|
|
if err != nil {
|
|
|
|
// This should *never* be reached, because the destination must've already
|
|
|
|
// been created while untar-ing the context.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
doChownDestination := !destExisted || !destStat.IsDir()
|
|
|
|
|
|
|
|
// We Walk on the source rather than on the destination because we don't
|
|
|
|
// want to change permissions on things we haven't created or modified.
|
|
|
|
return filepath.Walk(source, func(fullpath string, info os.FileInfo, err error) error {
|
|
|
|
// Do not alter the walk root iff. it existed before, as it doesn't fall under
|
|
|
|
// the domain of "things we should chown".
|
|
|
|
if !doChownDestination && (source == fullpath) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path is prefixed by source: substitute with destination instead.
|
|
|
|
cleaned, err := filepath.Rel(source, fullpath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fullpath = filepath.Join(destination, cleaned)
|
|
|
|
return os.Lchown(fullpath, uid, gid)
|
|
|
|
})
|
|
|
|
}
|
2017-03-15 14:29:12 -04:00
|
|
|
|
|
|
|
// isOnlineFSOperationPermitted returns an error if an online filesystem operation
|
|
|
|
// is not permitted.
|
|
|
|
func (daemon *Daemon) isOnlineFSOperationPermitted(container *container.Container) error {
|
|
|
|
return nil
|
|
|
|
}
|