github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/containerfs/containerfs.go (about)

     1  package containerfs
     2  
     3  import (
     4  	"path/filepath"
     5  	"runtime"
     6  
     7  	"github.com/containerd/continuity/driver"
     8  	"github.com/containerd/continuity/pathdriver"
     9  	"github.com/docker/docker/pkg/symlink"
    10  )
    11  
    12  // ContainerFS is that represents a root file system
    13  type ContainerFS interface {
    14  	// Path returns the path to the root. Note that this may not exist
    15  	// on the local system, so the continuity operations must be used
    16  	Path() string
    17  
    18  	// ResolveScopedPath evaluates the given path scoped to the root.
    19  	// For example, if root=/a, and path=/b/c, then this function would return /a/b/c.
    20  	// If rawPath is true, then the function will not preform any modifications
    21  	// before path resolution. Otherwise, the function will clean the given path
    22  	// by making it an absolute path.
    23  	ResolveScopedPath(path string, rawPath bool) (string, error)
    24  
    25  	Driver
    26  }
    27  
    28  // Driver combines both continuity's Driver and PathDriver interfaces with a Platform
    29  // field to determine the OS.
    30  type Driver interface {
    31  	// OS returns the OS where the rootfs is located. Essentially,
    32  	// runtime.GOOS for everything aside from LCOW, which is "linux"
    33  	OS() string
    34  
    35  	// Architecture returns the hardware architecture where the
    36  	// container is located.
    37  	Architecture() string
    38  
    39  	// Driver & PathDriver provide methods to manipulate files & paths
    40  	driver.Driver
    41  	pathdriver.PathDriver
    42  }
    43  
    44  // NewLocalContainerFS is a helper function to implement daemon's Mount interface
    45  // when the graphdriver mount point is a local path on the machine.
    46  func NewLocalContainerFS(path string) ContainerFS {
    47  	return &local{
    48  		path:       path,
    49  		Driver:     driver.LocalDriver,
    50  		PathDriver: pathdriver.LocalPathDriver,
    51  	}
    52  }
    53  
    54  // NewLocalDriver provides file and path drivers for a local file system. They are
    55  // essentially a wrapper around the `os` and `filepath` functions.
    56  func NewLocalDriver() Driver {
    57  	return &local{
    58  		Driver:     driver.LocalDriver,
    59  		PathDriver: pathdriver.LocalPathDriver,
    60  	}
    61  }
    62  
    63  type local struct {
    64  	path string
    65  	driver.Driver
    66  	pathdriver.PathDriver
    67  }
    68  
    69  func (l *local) Path() string {
    70  	return l.path
    71  }
    72  
    73  func (l *local) ResolveScopedPath(path string, rawPath bool) (string, error) {
    74  	cleanedPath := path
    75  	if !rawPath {
    76  		cleanedPath = cleanScopedPath(path)
    77  	}
    78  	return symlink.FollowSymlinkInScope(filepath.Join(l.path, cleanedPath), l.path)
    79  }
    80  
    81  func (l *local) OS() string {
    82  	return runtime.GOOS
    83  }
    84  
    85  func (l *local) Architecture() string {
    86  	return runtime.GOARCH
    87  }