mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/containerfs: drop PathDriver abstraction
With LCOW support removed, there is no need to support non-native file paths any longer. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
e37a2d1879
commit
7014c0d65d
21 changed files with 125 additions and 236 deletions
|
@ -259,7 +259,7 @@ func (o *copier) storeInPathCache(im *imageMount, path string, hash string) {
|
|||
func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) {
|
||||
root := o.source.Root()
|
||||
var copyInfos []copyInfo
|
||||
if err := root.Walk(root.Path(), func(path string, info os.FileInfo, err error) error {
|
||||
if err := filepath.Walk(root.Path(), func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) {
|
|||
if rel == "." {
|
||||
return nil
|
||||
}
|
||||
if match, _ := root.Match(origPath, rel); !match {
|
||||
if match, _ := filepath.Match(origPath, rel); !match {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ func walkSource(source builder.Source, origPath string) ([]string, error) {
|
|||
}
|
||||
// Must be a dir
|
||||
var subfiles []string
|
||||
err = source.Root().Walk(fp, func(path string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ func performCopyForInfo(dest copyInfo, source copyInfo, options copyFileOptions)
|
|||
if endsInSlash(dest.path) || destExistsAsDir {
|
||||
// source.path must be used to get the correct filename when the source
|
||||
// is a symlink
|
||||
destPath = dest.root.Join(destPath, source.root.Base(source.path))
|
||||
destPath = filepath.Join(destPath, filepath.Base(source.path))
|
||||
}
|
||||
return copyFile(archiver, srcPath, destPath, options.identity)
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
rel, err := c.root.Rel(c.root.Path(), fullpath)
|
||||
rel, err := filepath.Rel(c.root.Path(), fullpath)
|
||||
if err != nil {
|
||||
return "", convertPathError(err, cleanpath)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
|
|||
}
|
||||
|
||||
func normalize(path string, root containerfs.ContainerFS) (cleanPath, fullPath string, err error) {
|
||||
cleanPath = root.Clean(string(root.Separator()) + path)[1:]
|
||||
cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:]
|
||||
fullPath, err = containerfs.ResolveScopedPath(root.Path(), path)
|
||||
if err != nil {
|
||||
return "", "", errors.Wrapf(err, "forbidden path outside the build context: %s (%s)", path, cleanPath)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
|
@ -118,5 +119,5 @@ func (r *stubRemote) Close() error {
|
|||
return errors.New("not implemented")
|
||||
}
|
||||
func (r *stubRemote) Remove(p string) error {
|
||||
return r.root.Remove(r.root.Join(r.root.Path(), p))
|
||||
return r.root.Remove(filepath.Join(r.root.Path(), p))
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package remotecontext // import "github.com/docker/docker/builder/remotecontext"
|
|||
import (
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
@ -65,7 +66,7 @@ func (c *lazySource) Hash(path string) (string, error) {
|
|||
}
|
||||
|
||||
func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) {
|
||||
p := c.root.Join(c.root.Path(), relPath)
|
||||
p := filepath.Join(c.root.Path(), relPath)
|
||||
h, err := NewFileHash(p, relPath, fi)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to create hash for %s", relPath)
|
||||
|
@ -99,5 +100,5 @@ func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
|
|||
return p, nil
|
||||
}
|
||||
}
|
||||
return basepath.Rel(basepath.Path(), targpath)
|
||||
return filepath.Rel(basepath.Path(), targpath)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package remotecontext // import "github.com/docker/docker/builder/remotecontext"
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/pkg/containerfs"
|
||||
|
@ -66,7 +67,7 @@ func (cs *CachableSource) Scan() error {
|
|||
return err
|
||||
}
|
||||
txn := iradix.New().Txn()
|
||||
err = cs.root.Walk(cs.root.Path(), func(path string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(cs.root.Path(), func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to walk %s", path)
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ func TestRemoveDirectory(t *testing.T) {
|
|||
|
||||
src := makeTestArchiveContext(t, contextDir)
|
||||
|
||||
_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
|
||||
_, err = src.Root().Stat(filepath.Join(src.Root().Path(), relativePath))
|
||||
if err != nil {
|
||||
t.Fatalf("Statting %s shouldn't fail: %+v", relativePath, err)
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ func TestRemoveDirectory(t *testing.T) {
|
|||
t.Fatalf("Error when executing Remove: %s", err)
|
||||
}
|
||||
|
||||
_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
|
||||
_, err = src.Root().Stat(filepath.Join(src.Root().Path(), relativePath))
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("Directory should not exist at this point: %+v ", err)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package container // import "github.com/docker/docker/container"
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
|
@ -18,20 +19,17 @@ func (container *Container) ResolvePath(path string) (resolvedPath, absPath stri
|
|||
return "", "", errors.New("ResolvePath: BaseFS of container " + container.ID + " is unexpectedly nil")
|
||||
}
|
||||
// Check if a drive letter supplied, it must be the system drive. No-op except on Windows
|
||||
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path, container.BaseFS)
|
||||
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// Consider the given path as an absolute path in the container.
|
||||
absPath = archive.PreserveTrailingDotOrSeparator(
|
||||
container.BaseFS.Join(string(container.BaseFS.Separator()), path),
|
||||
path,
|
||||
container.BaseFS.Separator())
|
||||
absPath = archive.PreserveTrailingDotOrSeparator(filepath.Join(string(filepath.Separator), path), path)
|
||||
|
||||
// Split the absPath into its Directory and Base components. We will
|
||||
// resolve the dir in the scope of the container then append the base.
|
||||
dirPath, basePath := container.BaseFS.Split(absPath)
|
||||
dirPath, basePath := filepath.Split(absPath)
|
||||
|
||||
resolvedDirPath, err := container.GetResourcePath(dirPath)
|
||||
if err != nil {
|
||||
|
@ -40,7 +38,7 @@ func (container *Container) ResolvePath(path string) (resolvedPath, absPath stri
|
|||
|
||||
// resolvedDirPath will have been cleaned (no trailing path separators) so
|
||||
// we can manually join it with the base path element.
|
||||
resolvedPath = resolvedDirPath + string(container.BaseFS.Separator()) + basePath
|
||||
resolvedPath = resolvedDirPath + string(filepath.Separator) + basePath
|
||||
return resolvedPath, absPath, nil
|
||||
}
|
||||
|
||||
|
@ -67,17 +65,17 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
linkTarget, err = driver.Rel(driver.Path(), hostPath)
|
||||
linkTarget, err = filepath.Rel(driver.Path(), hostPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make it an absolute path.
|
||||
linkTarget = driver.Join(string(driver.Separator()), linkTarget)
|
||||
linkTarget = filepath.Join(string(filepath.Separator), linkTarget)
|
||||
}
|
||||
|
||||
return &types.ContainerPathStat{
|
||||
Name: driver.Base(absPath),
|
||||
Name: filepath.Base(absPath),
|
||||
Size: lstat.Size(),
|
||||
Mode: lstat.Mode(),
|
||||
Mtime: lstat.ModTime(),
|
||||
|
|
|
@ -3,6 +3,7 @@ package daemon // import "github.com/docker/docker/daemon"
|
|||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -165,7 +166,7 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
|
|||
}
|
||||
|
||||
// Normalize path before sending to rootfs
|
||||
path = container.BaseFS.FromSlash(path)
|
||||
path = filepath.FromSlash(path)
|
||||
|
||||
resolvedPath, absPath, err := container.ResolvePath(path)
|
||||
if err != nil {
|
||||
|
@ -208,7 +209,7 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
|
|||
}
|
||||
|
||||
// Normalize path before sending to rootfs
|
||||
path = container.BaseFS.FromSlash(path)
|
||||
path = filepath.FromSlash(path)
|
||||
|
||||
resolvedPath, absPath, err := container.ResolvePath(path)
|
||||
if err != nil {
|
||||
|
@ -232,18 +233,18 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
|
|||
|
||||
// Get the source and the base paths of the container resolved path in order
|
||||
// to get the proper tar options for the rebase tar.
|
||||
resolvedPath = driver.Clean(resolvedPath)
|
||||
if driver.Base(resolvedPath) == "." {
|
||||
resolvedPath += string(driver.Separator()) + "."
|
||||
resolvedPath = filepath.Clean(resolvedPath)
|
||||
if filepath.Base(resolvedPath) == "." {
|
||||
resolvedPath += string(filepath.Separator) + "."
|
||||
}
|
||||
|
||||
sourceDir := resolvedPath
|
||||
sourceBase := "."
|
||||
|
||||
if stat.Mode&os.ModeDir == 0 { // not dir
|
||||
sourceDir, sourceBase = driver.Split(resolvedPath)
|
||||
sourceDir, sourceBase = filepath.Split(resolvedPath)
|
||||
}
|
||||
opts := archive.TarResourceRebaseOpts(sourceBase, driver.Base(absPath))
|
||||
opts := archive.TarResourceRebaseOpts(sourceBase, filepath.Base(absPath))
|
||||
|
||||
data, err := archivePath(driver, sourceDir, opts, container.BaseFS.Path())
|
||||
if err != nil {
|
||||
|
@ -285,11 +286,11 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
|
|||
}
|
||||
|
||||
// Normalize path before sending to rootfs'
|
||||
path = container.BaseFS.FromSlash(path)
|
||||
path = filepath.FromSlash(path)
|
||||
driver := container.BaseFS
|
||||
|
||||
// Check if a drive letter supplied, it must be the system drive. No-op except on Windows
|
||||
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path, driver)
|
||||
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -301,10 +302,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
|
|||
// that you can extract an archive to a symlink that points to a directory.
|
||||
|
||||
// Consider the given path as an absolute path in the container.
|
||||
absPath := archive.PreserveTrailingDotOrSeparator(
|
||||
driver.Join(string(driver.Separator()), path),
|
||||
path,
|
||||
driver.Separator())
|
||||
absPath := archive.PreserveTrailingDotOrSeparator(filepath.Join(string(filepath.Separator), path), path)
|
||||
|
||||
// This will evaluate the last path element if it is a symlink.
|
||||
resolvedPath, err := container.GetResourcePath(absPath)
|
||||
|
@ -342,13 +340,13 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
|
|||
}
|
||||
}
|
||||
} else {
|
||||
baseRel, err = driver.Rel(driver.Path(), resolvedPath)
|
||||
baseRel, err = filepath.Rel(driver.Path(), resolvedPath)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Make it an absolute path.
|
||||
absPath = driver.Join(string(driver.Separator()), baseRel)
|
||||
absPath = filepath.Join(string(filepath.Separator), baseRel)
|
||||
|
||||
// @ TODO: gupta-ak: Technically, this works since it no-ops
|
||||
// on Windows and the file system is local anyway on linux.
|
||||
|
@ -416,7 +414,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
|
|||
}
|
||||
|
||||
// Normalize path before sending to rootfs
|
||||
resource = container.BaseFS.FromSlash(resource)
|
||||
resource = filepath.FromSlash(resource)
|
||||
driver := container.BaseFS
|
||||
|
||||
basePath, err := container.GetResourcePath(resource)
|
||||
|
@ -429,7 +427,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
|
|||
}
|
||||
var filter []string
|
||||
if !stat.IsDir() {
|
||||
d, f := driver.Split(basePath)
|
||||
d, f := filepath.Split(basePath)
|
||||
basePath = d
|
||||
filter = []string{f}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphte
|
|||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
contdriver "github.com/containerd/continuity/driver"
|
||||
|
@ -249,7 +250,7 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d
|
|||
for i := 0; i < b.N; i++ {
|
||||
|
||||
// Read content
|
||||
c, err := contdriver.ReadFile(root, root.Join(root.Path(), "testfile.txt"))
|
||||
c, err := contdriver.ReadFile(root, filepath.Join(root.Path(), "testfile.txt"))
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/containerd/continuity/driver"
|
||||
|
@ -35,17 +36,17 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error {
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
if err := driver.WriteFile(root, root.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := root.MkdirAll(root.Join(root.Path(), "dir-b"), 0755); err != nil {
|
||||
if err := root.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := driver.WriteFile(root, root.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return driver.WriteFile(root, root.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755)
|
||||
return driver.WriteFile(root, filepath.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755)
|
||||
}
|
||||
|
||||
func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error {
|
||||
|
@ -55,7 +56,7 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
fileContent, err := driver.ReadFile(root, root.Join(root.Path(), filename))
|
||||
fileContent, err := driver.ReadFile(root, filepath.Join(root.Path(), filename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
return driver.WriteFile(root, root.Join(root.Path(), filename), content, 0755)
|
||||
return driver.WriteFile(root, filepath.Join(root.Path(), filename), content, 0755)
|
||||
}
|
||||
|
||||
func addDirectory(drv graphdriver.Driver, layer, dir string) error {
|
||||
|
@ -84,7 +85,7 @@ func addDirectory(drv graphdriver.Driver, layer, dir string) error {
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
return root.MkdirAll(root.Join(root.Path(), dir), 0755)
|
||||
return root.MkdirAll(filepath.Join(root.Path(), dir), 0755)
|
||||
}
|
||||
|
||||
func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
|
||||
|
@ -95,7 +96,7 @@ func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
|
|||
defer drv.Put(layer)
|
||||
|
||||
for _, filename := range names {
|
||||
if err := root.RemoveAll(root.Join(root.Path(), filename)); err != nil {
|
||||
if err := root.RemoveAll(filepath.Join(root.Path(), filename)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +110,8 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
if _, err := root.Stat(root.Join(root.Path(), filename)); err == nil {
|
||||
return fmt.Errorf("file still exists: %s", root.Join(root.Path(), filename))
|
||||
if _, err := root.Stat(filepath.Join(root.Path(), filename)); err == nil {
|
||||
return fmt.Errorf("file still exists: %s", filepath.Join(root.Path(), filename))
|
||||
} else if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -126,12 +127,12 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e
|
|||
defer drv.Put(layer)
|
||||
|
||||
for i := 0; i < count; i += 100 {
|
||||
dir := root.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
||||
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
||||
if err := root.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
for j := 0; i+j < count && j < 100; j++ {
|
||||
file := root.Join(dir, fmt.Sprintf("file-%d", i+j))
|
||||
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
|
||||
if err := driver.WriteFile(root, file, randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -151,7 +152,7 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
|
|||
var changes []archive.Change
|
||||
for i := 0; i < count; i += 100 {
|
||||
archiveRoot := fmt.Sprintf("/directory-%d", i)
|
||||
if err := root.MkdirAll(root.Join(root.Path(), archiveRoot), 0755); err != nil {
|
||||
if err := root.MkdirAll(filepath.Join(root.Path(), archiveRoot), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for j := 0; i+j < count && j < 100; j++ {
|
||||
|
@ -165,23 +166,23 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
|
|||
switch j % 3 {
|
||||
// Update file
|
||||
case 0:
|
||||
change.Path = root.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
||||
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
||||
change.Kind = archive.ChangeModify
|
||||
if err := driver.WriteFile(root, root.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Add file
|
||||
case 1:
|
||||
change.Path = root.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j))
|
||||
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j))
|
||||
change.Kind = archive.ChangeAdd
|
||||
if err := driver.WriteFile(root, root.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Remove file
|
||||
case 2:
|
||||
change.Path = root.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
||||
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
||||
change.Kind = archive.ChangeDelete
|
||||
if err := root.Remove(root.Join(root.Path(), change.Path)); err != nil {
|
||||
if err := root.Remove(filepath.Join(root.Path(), change.Path)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -200,9 +201,9 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64)
|
|||
defer drv.Put(layer)
|
||||
|
||||
for i := 0; i < count; i += 100 {
|
||||
dir := root.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
||||
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
||||
for j := 0; i+j < count && j < 100; j++ {
|
||||
file := root.Join(dir, fmt.Sprintf("file-%d", i+j))
|
||||
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
|
||||
fileContent, err := driver.ReadFile(root, file)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -253,17 +254,17 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
if err := driver.WriteFile(root, root.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
layerDir := root.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
||||
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
||||
if err := root.MkdirAll(layerDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := driver.WriteFile(root, root.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
||||
if err := driver.WriteFile(root, filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
return driver.WriteFile(root, root.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
||||
return driver.WriteFile(root, filepath.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
||||
}
|
||||
|
||||
func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) {
|
||||
|
@ -290,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
|
|||
}
|
||||
defer drv.Put(layer)
|
||||
|
||||
layerIDBytes, err := driver.ReadFile(root, root.Join(root.Path(), "top-id"))
|
||||
layerIDBytes, err := driver.ReadFile(root, filepath.Join(root.Path(), "top-id"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -300,16 +301,16 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
|
|||
}
|
||||
|
||||
for i := count; i > 0; i-- {
|
||||
layerDir := root.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
||||
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
||||
|
||||
thisLayerIDBytes, err := driver.ReadFile(root, root.Join(layerDir, "layer-id"))
|
||||
thisLayerIDBytes, err := driver.ReadFile(root, filepath.Join(layerDir, "layer-id"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(thisLayerIDBytes, layerIDBytes) {
|
||||
return fmt.Errorf("mismatched file content %v, expecting %v", thisLayerIDBytes, layerIDBytes)
|
||||
}
|
||||
layerIDBytes, err = driver.ReadFile(root, root.Join(layerDir, "parent-id"))
|
||||
layerIDBytes, err = driver.ReadFile(root, filepath.Join(layerDir, "parent-id"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphte
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
|
@ -44,11 +45,11 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) {
|
|||
assert.NilError(t, err)
|
||||
defer driver.Put(name)
|
||||
|
||||
subdir := dirFS.Join(dirFS.Path(), "a subdir")
|
||||
subdir := filepath.Join(dirFS.Path(), "a subdir")
|
||||
assert.NilError(t, dirFS.Mkdir(subdir, 0705|os.ModeSticky))
|
||||
assert.NilError(t, dirFS.Lchown(subdir, 1, 2))
|
||||
|
||||
file := dirFS.Join(dirFS.Path(), "a file")
|
||||
file := filepath.Join(dirFS.Path(), "a file")
|
||||
err = contdriver.WriteFile(dirFS, file, []byte("Some data"), 0222|os.ModeSetuid)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
@ -58,10 +59,10 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) {
|
|||
assert.NilError(t, err)
|
||||
defer driver.Put(name)
|
||||
|
||||
subdir := dirFS.Join(dirFS.Path(), "a subdir")
|
||||
subdir := filepath.Join(dirFS.Path(), "a subdir")
|
||||
verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2)
|
||||
|
||||
file := dirFS.Join(dirFS.Path(), "a file")
|
||||
file := filepath.Join(dirFS.Path(), "a file")
|
||||
verifyFile(t, file, 0222|os.ModeSetuid, 0, 0)
|
||||
|
||||
files, err := readDir(dirFS, dirFS.Path())
|
||||
|
|
|
@ -139,8 +139,8 @@ func newTestFile(name string, content []byte, perm os.FileMode) FileApplier {
|
|||
}
|
||||
|
||||
func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
|
||||
fullPath := root.Join(root.Path(), tf.name)
|
||||
if err := root.MkdirAll(root.Dir(fullPath), 0755); err != nil {
|
||||
fullPath := filepath.Join(root.Path(), tf.name)
|
||||
if err := root.MkdirAll(filepath.Dir(fullPath), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
// Check if already exists
|
||||
|
@ -267,7 +267,7 @@ func TestMountAndRegister(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := driver.ReadFile(path2, path2.Join(path2.Path(), "testfile.txt"))
|
||||
b, err := driver.ReadFile(path2, filepath.Join(path2.Path(), "testfile.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ func TestStoreRestore(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := driver.WriteFile(pathFS, pathFS.Join(pathFS.Path(), "testfile.txt"), []byte("nothing here"), 0644); err != nil {
|
||||
if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile.txt"), []byte("nothing here"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ func TestStoreRestore(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := driver.ReadFile(pathFS, pathFS.Join(pathFS.Path(), "testfile.txt"))
|
||||
b, err := driver.ReadFile(pathFS, filepath.Join(pathFS.Path(), "testfile.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package layer // import "github.com/docker/docker/layer"
|
|||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"testing"
|
||||
|
@ -45,12 +46,12 @@ func TestMountInit(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fi, err := pathFS.Stat(pathFS.Join(pathFS.Path(), "testfile.txt"))
|
||||
fi, err := pathFS.Stat(filepath.Join(pathFS.Path(), "testfile.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := pathFS.Open(pathFS.Join(pathFS.Path(), "testfile.txt"))
|
||||
f, err := pathFS.Open(filepath.Join(pathFS.Path(), "testfile.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ func TestMountSize(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := driver.WriteFile(pathFS, pathFS.Join(pathFS.Path(), "file2"), content2, 0755); err != nil {
|
||||
if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "file2"), content2, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -157,23 +158,23 @@ func TestMountChanges(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := pathFS.Lchmod(pathFS.Join(pathFS.Path(), "testfile1.txt"), 0755); err != nil {
|
||||
if err := pathFS.Lchmod(filepath.Join(pathFS.Path(), "testfile1.txt"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := driver.WriteFile(pathFS, pathFS.Join(pathFS.Path(), "testfile1.txt"), []byte("mount data!"), 0755); err != nil {
|
||||
if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile1.txt"), []byte("mount data!"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := pathFS.Remove(pathFS.Join(pathFS.Path(), "testfile2.txt")); err != nil {
|
||||
if err := pathFS.Remove(filepath.Join(pathFS.Path(), "testfile2.txt")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := pathFS.Lchmod(pathFS.Join(pathFS.Path(), "testfile3.txt"), 0755); err != nil {
|
||||
if err := pathFS.Lchmod(filepath.Join(pathFS.Path(), "testfile3.txt"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := driver.WriteFile(pathFS, pathFS.Join(pathFS.Path(), "testfile4.txt"), []byte("mount data!"), 0644); err != nil {
|
||||
if err := driver.WriteFile(pathFS, filepath.Join(pathFS.Path(), "testfile4.txt"), []byte("mount data!"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -248,7 +249,7 @@ func TestMountApply(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := pathFS.Open(pathFS.Join(pathFS.Path(), "newfile.txt"))
|
||||
f, err := pathFS.Open(filepath.Join(pathFS.Path(), "newfile.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -26,23 +26,23 @@ var (
|
|||
// path (from before being processed by utility functions from the path or
|
||||
// filepath stdlib packages) ends with a trailing `/.` or `/`. If the cleaned
|
||||
// path already ends in a `.` path segment, then another is not added. If the
|
||||
// clean path already ends in the separator, then another is not added.
|
||||
func PreserveTrailingDotOrSeparator(cleanedPath string, originalPath string, sep byte) string {
|
||||
// clean path already ends in a path separator, then another is not added.
|
||||
func PreserveTrailingDotOrSeparator(cleanedPath string, originalPath string) string {
|
||||
// Ensure paths are in platform semantics
|
||||
cleanedPath = strings.ReplaceAll(cleanedPath, "/", string(sep))
|
||||
originalPath = strings.ReplaceAll(originalPath, "/", string(sep))
|
||||
cleanedPath = normalizePath(cleanedPath)
|
||||
originalPath = normalizePath(originalPath)
|
||||
|
||||
if !specifiesCurrentDir(cleanedPath) && specifiesCurrentDir(originalPath) {
|
||||
if !hasTrailingPathSeparator(cleanedPath, sep) {
|
||||
if !hasTrailingPathSeparator(cleanedPath) {
|
||||
// Add a separator if it doesn't already end with one (a cleaned
|
||||
// path would only end in a separator if it is the root).
|
||||
cleanedPath += string(sep)
|
||||
cleanedPath += string(filepath.Separator)
|
||||
}
|
||||
cleanedPath += "."
|
||||
}
|
||||
|
||||
if !hasTrailingPathSeparator(cleanedPath, sep) && hasTrailingPathSeparator(originalPath, sep) {
|
||||
cleanedPath += string(sep)
|
||||
if !hasTrailingPathSeparator(cleanedPath) && hasTrailingPathSeparator(originalPath) {
|
||||
cleanedPath += string(filepath.Separator)
|
||||
}
|
||||
|
||||
return cleanedPath
|
||||
|
@ -51,14 +51,14 @@ func PreserveTrailingDotOrSeparator(cleanedPath string, originalPath string, sep
|
|||
// assertsDirectory returns whether the given path is
|
||||
// asserted to be a directory, i.e., the path ends with
|
||||
// a trailing '/' or `/.`, assuming a path separator of `/`.
|
||||
func assertsDirectory(path string, sep byte) bool {
|
||||
return hasTrailingPathSeparator(path, sep) || specifiesCurrentDir(path)
|
||||
func assertsDirectory(path string) bool {
|
||||
return hasTrailingPathSeparator(path) || specifiesCurrentDir(path)
|
||||
}
|
||||
|
||||
// hasTrailingPathSeparator returns whether the given
|
||||
// path ends with the system's path separator character.
|
||||
func hasTrailingPathSeparator(path string, sep byte) bool {
|
||||
return len(path) > 0 && path[len(path)-1] == sep
|
||||
func hasTrailingPathSeparator(path string) bool {
|
||||
return len(path) > 0 && path[len(path)-1] == filepath.Separator
|
||||
}
|
||||
|
||||
// specifiesCurrentDir returns whether the given path specifies
|
||||
|
@ -285,7 +285,7 @@ func PrepareArchiveCopy(srcContent io.Reader, srcInfo, dstInfo CopyInfo) (dstDir
|
|||
srcBase = srcInfo.RebaseName
|
||||
}
|
||||
return dstDir, RebaseArchiveEntries(srcContent, srcBase, dstBase), nil
|
||||
case assertsDirectory(dstInfo.Path, os.PathSeparator):
|
||||
case assertsDirectory(dstInfo.Path):
|
||||
// The destination does not exist and is asserted to be created as a
|
||||
// directory, but the source content is not a directory. This is an
|
||||
// error condition since you cannot create a directory from a file
|
||||
|
@ -387,8 +387,8 @@ func CopyResource(srcPath, dstPath string, followLink bool) error {
|
|||
dstPath = normalizePath(dstPath)
|
||||
|
||||
// Clean the source and destination paths.
|
||||
srcPath = PreserveTrailingDotOrSeparator(filepath.Clean(srcPath), srcPath, os.PathSeparator)
|
||||
dstPath = PreserveTrailingDotOrSeparator(filepath.Clean(dstPath), dstPath, os.PathSeparator)
|
||||
srcPath = PreserveTrailingDotOrSeparator(filepath.Clean(srcPath), srcPath)
|
||||
dstPath = PreserveTrailingDotOrSeparator(filepath.Clean(dstPath), dstPath)
|
||||
|
||||
if srcInfo, err = CopyInfoSourcePath(srcPath, followLink); err != nil {
|
||||
return err
|
||||
|
@ -451,7 +451,7 @@ func ResolveHostSourcePath(path string, followLink bool) (resolvedPath, rebaseNa
|
|||
// resolvedDirPath will have been cleaned (no trailing path separators) so
|
||||
// we can manually join it with the base path element.
|
||||
resolvedPath = resolvedDirPath + string(filepath.Separator) + basePath
|
||||
if hasTrailingPathSeparator(path, os.PathSeparator) &&
|
||||
if hasTrailingPathSeparator(path) &&
|
||||
filepath.Base(path) != filepath.Base(resolvedPath) {
|
||||
rebaseName = filepath.Base(path)
|
||||
}
|
||||
|
@ -470,8 +470,8 @@ func GetRebaseName(path, resolvedPath string) (string, string) {
|
|||
resolvedPath += string(filepath.Separator) + "."
|
||||
}
|
||||
|
||||
if hasTrailingPathSeparator(path, os.PathSeparator) &&
|
||||
!hasTrailingPathSeparator(resolvedPath, os.PathSeparator) {
|
||||
if hasTrailingPathSeparator(path) &&
|
||||
!hasTrailingPathSeparator(resolvedPath) {
|
||||
resolvedPath += string(filepath.Separator)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/containerd/continuity/driver"
|
||||
"github.com/containerd/continuity/pathdriver"
|
||||
"github.com/moby/sys/symlink"
|
||||
)
|
||||
|
||||
|
@ -14,25 +13,22 @@ type ContainerFS interface {
|
|||
// on the local system, so the continuity operations must be used
|
||||
Path() string
|
||||
|
||||
// Driver & PathDriver provide methods to manipulate files & paths
|
||||
// Driver provides methods to manipulate files
|
||||
driver.Driver
|
||||
pathdriver.PathDriver
|
||||
}
|
||||
|
||||
// NewLocalContainerFS is a helper function to implement daemon's Mount interface
|
||||
// when the graphdriver mount point is a local path on the machine.
|
||||
func NewLocalContainerFS(path string) ContainerFS {
|
||||
return &local{
|
||||
path: path,
|
||||
Driver: driver.LocalDriver,
|
||||
PathDriver: pathdriver.LocalPathDriver,
|
||||
path: path,
|
||||
Driver: driver.LocalDriver,
|
||||
}
|
||||
}
|
||||
|
||||
type local struct {
|
||||
path string
|
||||
driver.Driver
|
||||
pathdriver.PathDriver
|
||||
}
|
||||
|
||||
func (l *local) Path() string {
|
||||
|
|
|
@ -16,12 +16,6 @@ func DefaultPathEnv(os string) string {
|
|||
|
||||
}
|
||||
|
||||
// PathVerifier defines the subset of a PathDriver that CheckSystemDriveAndRemoveDriveLetter
|
||||
// actually uses in order to avoid system depending on containerd/continuity.
|
||||
type PathVerifier interface {
|
||||
IsAbs(string) bool
|
||||
}
|
||||
|
||||
// CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter,
|
||||
// is the system drive.
|
||||
// On Linux: this is a no-op.
|
||||
|
@ -37,6 +31,6 @@ type PathVerifier interface {
|
|||
// a --> a
|
||||
// /a --> \a
|
||||
// d:\ --> Fail
|
||||
func CheckSystemDriveAndRemoveDriveLetter(path string, driver PathVerifier) (string, error) {
|
||||
return checkSystemDriveAndRemoveDriveLetter(path, driver)
|
||||
func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
||||
return checkSystemDriveAndRemoveDriveLetter(path)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ func GetLongPathName(path string) (string, error) {
|
|||
|
||||
// checkSystemDriveAndRemoveDriveLetter is the non-Windows implementation
|
||||
// of CheckSystemDriveAndRemoveDriveLetter
|
||||
func checkSystemDriveAndRemoveDriveLetter(path string, driver PathVerifier) (string, error) {
|
||||
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
||||
return path, nil
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ func GetLongPathName(path string) (string, error) {
|
|||
|
||||
// checkSystemDriveAndRemoveDriveLetter is the Windows implementation
|
||||
// of CheckSystemDriveAndRemoveDriveLetter
|
||||
func checkSystemDriveAndRemoveDriveLetter(path string, driver PathVerifier) (string, error) {
|
||||
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
||||
if len(path) == 2 && string(path[1]) == ":" {
|
||||
return "", fmt.Errorf("No relative path specified in %q", path)
|
||||
}
|
||||
if !driver.IsAbs(path) || len(path) < 2 {
|
||||
if !filepath.IsAbs(path) || len(path) < 2 {
|
||||
return filepath.FromSlash(path), nil
|
||||
}
|
||||
if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") {
|
||||
|
|
|
@ -5,21 +5,19 @@ package system // import "github.com/docker/docker/pkg/system"
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/continuity/pathdriver"
|
||||
)
|
||||
|
||||
// TestCheckSystemDriveAndRemoveDriveLetter tests CheckSystemDriveAndRemoveDriveLetter
|
||||
func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
||||
// Fails if not C drive.
|
||||
_, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`, pathdriver.LocalPathDriver)
|
||||
_, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`)
|
||||
if err == nil || err.Error() != "The specified path is not on the system drive (C:)" {
|
||||
t.Fatalf("Expected error for d:")
|
||||
}
|
||||
|
||||
// Single character is unchanged
|
||||
var path string
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter("z", pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter("z"); err != nil {
|
||||
t.Fatalf("Single character should pass")
|
||||
}
|
||||
if path != "z" {
|
||||
|
@ -27,7 +25,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Two characters without colon is unchanged
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter("AB", pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter("AB"); err != nil {
|
||||
t.Fatalf("2 characters without colon should pass")
|
||||
}
|
||||
if path != "AB" {
|
||||
|
@ -35,7 +33,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Abs path without drive letter
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`\l`, pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`\l`); err != nil {
|
||||
t.Fatalf("abs path no drive letter should pass")
|
||||
}
|
||||
if path != `\l` {
|
||||
|
@ -43,7 +41,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Abs path without drive letter, linux style
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`/l`, pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`/l`); err != nil {
|
||||
t.Fatalf("abs path no drive letter linux style should pass")
|
||||
}
|
||||
if path != `\l` {
|
||||
|
@ -51,7 +49,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Drive-colon should be stripped
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:\`, pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:\`); err != nil {
|
||||
t.Fatalf("An absolute path should pass")
|
||||
}
|
||||
if path != `\` {
|
||||
|
@ -59,7 +57,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify with a linux-style path
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:/`, pathdriver.LocalPathDriver); err != nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:/`); err != nil {
|
||||
t.Fatalf("An absolute path should pass")
|
||||
}
|
||||
if path != `\` {
|
||||
|
@ -67,7 +65,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Failure on c:
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`, pathdriver.LocalPathDriver); err == nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`); err == nil {
|
||||
t.Fatalf("c: should fail")
|
||||
}
|
||||
if err.Error() != `No relative path specified in "c:"` {
|
||||
|
@ -75,7 +73,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Failure on d:
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`, pathdriver.LocalPathDriver); err == nil {
|
||||
if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`); err == nil {
|
||||
t.Fatalf("c: should fail")
|
||||
}
|
||||
if err.Error() != `No relative path specified in "d:"` {
|
||||
|
|
101
vendor/github.com/containerd/continuity/pathdriver/path_driver.go
generated
vendored
101
vendor/github.com/containerd/continuity/pathdriver/path_driver.go
generated
vendored
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pathdriver
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// PathDriver provides all of the path manipulation functions in a common
|
||||
// interface. The context should call these and never use the `filepath`
|
||||
// package or any other package to manipulate paths.
|
||||
type PathDriver interface {
|
||||
Join(paths ...string) string
|
||||
IsAbs(path string) bool
|
||||
Rel(base, target string) (string, error)
|
||||
Base(path string) string
|
||||
Dir(path string) string
|
||||
Clean(path string) string
|
||||
Split(path string) (dir, file string)
|
||||
Separator() byte
|
||||
Abs(path string) (string, error)
|
||||
Walk(string, filepath.WalkFunc) error
|
||||
FromSlash(path string) string
|
||||
ToSlash(path string) string
|
||||
Match(pattern, name string) (matched bool, err error)
|
||||
}
|
||||
|
||||
// pathDriver is a simple default implementation calls the filepath package.
|
||||
type pathDriver struct{}
|
||||
|
||||
// LocalPathDriver is the exported pathDriver struct for convenience.
|
||||
var LocalPathDriver PathDriver = &pathDriver{}
|
||||
|
||||
func (*pathDriver) Join(paths ...string) string {
|
||||
return filepath.Join(paths...)
|
||||
}
|
||||
|
||||
func (*pathDriver) IsAbs(path string) bool {
|
||||
return filepath.IsAbs(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Rel(base, target string) (string, error) {
|
||||
return filepath.Rel(base, target)
|
||||
}
|
||||
|
||||
func (*pathDriver) Base(path string) string {
|
||||
return filepath.Base(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Dir(path string) string {
|
||||
return filepath.Dir(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Clean(path string) string {
|
||||
return filepath.Clean(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Split(path string) (dir, file string) {
|
||||
return filepath.Split(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Separator() byte {
|
||||
return filepath.Separator
|
||||
}
|
||||
|
||||
func (*pathDriver) Abs(path string) (string, error) {
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
||||
// Note that filepath.Walk calls os.Stat, so if the context wants to
|
||||
// to call Driver.Stat() for Walk, they need to create a new struct that
|
||||
// overrides this method.
|
||||
func (*pathDriver) Walk(root string, walkFn filepath.WalkFunc) error {
|
||||
return filepath.Walk(root, walkFn)
|
||||
}
|
||||
|
||||
func (*pathDriver) FromSlash(path string) string {
|
||||
return filepath.FromSlash(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) ToSlash(path string) string {
|
||||
return filepath.ToSlash(path)
|
||||
}
|
||||
|
||||
func (*pathDriver) Match(pattern, name string) (bool, error) {
|
||||
return filepath.Match(pattern, name)
|
||||
}
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
|
@ -236,7 +236,6 @@ github.com/containerd/containerd/version
|
|||
github.com/containerd/continuity/devices
|
||||
github.com/containerd/continuity/driver
|
||||
github.com/containerd/continuity/fs
|
||||
github.com/containerd/continuity/pathdriver
|
||||
github.com/containerd/continuity/sysx
|
||||
# github.com/containerd/fifo v1.0.0
|
||||
## explicit; go 1.13
|
||||
|
|
Loading…
Reference in a new issue