github.com/jogo/docker@v1.7.0-rc1/daemon/volumes_linux.go (about)

     1  // +build !windows
     2  
     3  package daemon
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"sort"
     9  	"strings"
    10  
    11  	"github.com/docker/docker/daemon/execdriver"
    12  	"github.com/docker/docker/pkg/system"
    13  )
    14  
    15  // copyOwnership copies the permissions and uid:gid of the source file
    16  // into the destination file
    17  func copyOwnership(source, destination string) error {
    18  	stat, err := system.Stat(source)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	if err := os.Chown(destination, int(stat.Uid()), int(stat.Gid())); err != nil {
    24  		return err
    25  	}
    26  
    27  	return os.Chmod(destination, os.FileMode(stat.Mode()))
    28  }
    29  
    30  func (container *Container) setupMounts() ([]execdriver.Mount, error) {
    31  	var mounts []execdriver.Mount
    32  	for _, m := range container.MountPoints {
    33  		path, err := m.Setup()
    34  		if err != nil {
    35  			return nil, err
    36  		}
    37  
    38  		mounts = append(mounts, execdriver.Mount{
    39  			Source:      path,
    40  			Destination: m.Destination,
    41  			Writable:    m.RW,
    42  		})
    43  	}
    44  
    45  	mounts = sortMounts(mounts)
    46  	return append(mounts, container.networkMounts()...), nil
    47  }
    48  
    49  func sortMounts(m []execdriver.Mount) []execdriver.Mount {
    50  	sort.Sort(mounts(m))
    51  	return m
    52  }
    53  
    54  type mounts []execdriver.Mount
    55  
    56  func (m mounts) Len() int {
    57  	return len(m)
    58  }
    59  
    60  func (m mounts) Less(i, j int) bool {
    61  	return m.parts(i) < m.parts(j)
    62  }
    63  
    64  func (m mounts) Swap(i, j int) {
    65  	m[i], m[j] = m[j], m[i]
    66  }
    67  
    68  func (m mounts) parts(i int) int {
    69  	return len(strings.Split(filepath.Clean(m[i].Destination), string(os.PathSeparator)))
    70  }