pkg/containerfs: simplify ContainerFS type

Iterate towards dropping the type entirely.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2022-09-23 12:25:19 -04:00
parent be4f4644a8
commit 95824f2b5f
44 changed files with 159 additions and 174 deletions

View file

@ -291,7 +291,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl
return nil, nil, err
}
return []mount.Mount{{
Source: rootfs.Path(),
Source: string(rootfs),
Type: "bind",
Options: []string{"rbind"},
}}, func() error {
@ -312,7 +312,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl
return nil, nil, err
}
return []mount.Mount{{
Source: rootfs.Path(),
Source: string(rootfs),
Type: "bind",
Options: []string{"rbind"},
}}, func() error {

View file

@ -45,7 +45,7 @@ type copyInfo struct {
}
func (c copyInfo) fullPath() (string, error) {
return containerfs.ResolveScopedPath(c.root.Path(), c.path)
return containerfs.ResolveScopedPath(string(c.root), c.path)
}
func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo {
@ -159,7 +159,7 @@ func (o *copier) getCopyInfoForSourcePath(orig, dest string) ([]copyInfo, error)
}
path = unnamedFilename
}
o.tmpPaths = append(o.tmpPaths, remote.Root().Path())
o.tmpPaths = append(o.tmpPaths, string(remote.Root()))
hash, err := remote.Hash(path)
ci := newCopyInfoFromSource(remote, path, hash)
@ -202,7 +202,7 @@ func (o *copier) calcCopyInfo(origPath string, allowWildcards bool) ([]copyInfo,
o.source, err = remotecontext.NewLazySource(rwLayer.Root())
if err != nil {
return nil, errors.Wrapf(err, "failed to create context for copy from %s", rwLayer.Root().Path())
return nil, errors.Wrapf(err, "failed to create context for copy from %s", string(rwLayer.Root()))
}
}
@ -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 := filepath.Walk(root.Path(), func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(string(root), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

View file

@ -147,7 +147,7 @@ func (b *Builder) performCopy(req dispatchRequest, inst copyInstruction) error {
// translated (if necessary because of user namespaces), and replace
// the root pair with the chown pair for copy operations
if inst.chownStr != "" {
identity, err = parseChownFlag(b, state, inst.chownStr, destInfo.root.Path(), b.idMapping)
identity, err = parseChownFlag(b, state, inst.chownStr, string(destInfo.root), b.idMapping)
if err != nil {
if b.options.Platform != "windows" {
return errors.Wrapf(err, "unable to convert uid/gid chown string to host mapping")

View file

@ -184,7 +184,7 @@ func TestDeepCopyRunConfig(t *testing.T) {
type MockRWLayer struct{}
func (l *MockRWLayer) Release() error { return nil }
func (l *MockRWLayer) Root() containerfs.ContainerFS { return nil }
func (l *MockRWLayer) Root() containerfs.ContainerFS { return "" }
func (l *MockRWLayer) Commit() (builder.ROLayer, error) {
return &MockROLayer{
diffID: layer.DiffID(digest.Digest("sha256:1234")),

View file

@ -144,5 +144,5 @@ func (l *mockRWLayer) Commit() (builder.ROLayer, error) {
}
func (l *mockRWLayer) Root() containerfs.ContainerFS {
return nil
return ""
}

View file

@ -20,7 +20,7 @@ type archiveContext struct {
}
func (c *archiveContext) Close() error {
return os.RemoveAll(c.root.Path())
return os.RemoveAll(string(c.root))
}
func convertPathError(err error, cleanpath string) error {
@ -100,7 +100,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
return "", err
}
rel, err := filepath.Rel(c.root.Path(), fullpath)
rel, err := filepath.Rel(string(c.root), fullpath)
if err != nil {
return "", convertPathError(err, cleanpath)
}
@ -117,7 +117,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
func normalize(path string, root containerfs.ContainerFS) (cleanPath, fullPath string, err error) {
cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:]
fullPath, err = containerfs.ResolveScopedPath(root.Path(), path)
fullPath, err = containerfs.ResolveScopedPath(string(root), path)
if err != nil {
return "", "", errors.Wrapf(err, "forbidden path outside the build context: %s (%s)", path, cleanPath)
}

View file

@ -176,7 +176,7 @@ func StatAt(remote builder.Source, path string) (os.FileInfo, error) {
// FullPath is a helper for getting a full path for a path from a source
func FullPath(remote builder.Source, path string) (string, error) {
fullPath, err := containerfs.ResolveScopedPath(remote.Root().Path(), path)
fullPath, err := containerfs.ResolveScopedPath(string(remote.Root()), path)
if err != nil {
if runtime.GOOS == "windows" {
return "", fmt.Errorf("failed to resolve scoped path %s (%s): %s. Possible cause is a forbidden path outside the build context", path, fullPath, err)

View file

@ -119,5 +119,5 @@ func (r *stubRemote) Close() error {
return errors.New("not implemented")
}
func (r *stubRemote) Remove(p string) error {
return os.Remove(filepath.Join(r.root.Path(), p))
return os.Remove(filepath.Join(string(r.root), p))
}

View file

@ -66,7 +66,7 @@ func (c *lazySource) Hash(path string) (string, error) {
}
func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) {
p := filepath.Join(c.root.Path(), relPath)
p := filepath.Join(string(c.root), relPath)
h, err := NewFileHash(p, relPath, fi)
if err != nil {
return "", errors.Wrapf(err, "failed to create hash for %s", relPath)
@ -91,7 +91,7 @@ func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error)
func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
// filepath.Rel can't handle UUID paths in windows
if runtime.GOOS == "windows" {
pfx := basepath.Path() + `\`
pfx := string(basepath) + `\`
if strings.HasPrefix(targpath, pfx) {
p := strings.TrimPrefix(targpath, pfx)
if p == "" {
@ -100,5 +100,5 @@ func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
return p, nil
}
}
return filepath.Rel(basepath.Path(), targpath)
return filepath.Rel(string(basepath), targpath)
}

View file

@ -67,7 +67,7 @@ func (cs *CachableSource) Scan() error {
return err
}
txn := iradix.New().Txn()
err = filepath.Walk(cs.root.Path(), func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(string(cs.root), func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "failed to walk %s", path)
}

View file

@ -35,7 +35,7 @@ func TestCloseRootDirectory(t *testing.T) {
t.Fatalf("Error while executing Close: %s", err)
}
_, err = os.Stat(src.Root().Path())
_, err = os.Stat(string(src.Root()))
if !errors.Is(err, os.ErrNotExist) {
t.Fatal("Directory should not exist at this point")
@ -118,7 +118,7 @@ func TestRemoveDirectory(t *testing.T) {
src := makeTestArchiveContext(t, contextDir)
_, err = os.Stat(filepath.Join(src.Root().Path(), relativePath))
_, err = os.Stat(filepath.Join(string(src.Root()), 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 = os.Stat(filepath.Join(src.Root().Path(), relativePath))
_, err = os.Stat(filepath.Join(string(src.Root()), relativePath))
if !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Directory should not exist at this point: %+v ", err)
}

View file

@ -15,8 +15,8 @@ import (
// the absolute path to the resource relative to the container's rootfs, and
// an error if the path points to outside the container's rootfs.
func (container *Container) ResolvePath(path string) (resolvedPath, absPath string, err error) {
if container.BaseFS == nil {
return "", "", errors.New("ResolvePath: BaseFS of container " + container.ID + " is unexpectedly nil")
if container.BaseFS == "" {
return "", "", errors.New("ResolvePath: BaseFS of container " + container.ID + " is unexpectedly empty")
}
// Check if a drive letter supplied, it must be the system drive. No-op except on Windows
path, err = system.CheckSystemDriveAndRemoveDriveLetter(path)
@ -47,10 +47,9 @@ func (container *Container) ResolvePath(path string) (resolvedPath, absPath stri
// resolved to a path on the host corresponding to the given absolute path
// inside the container.
func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error) {
if container.BaseFS == nil {
return nil, errors.New("StatPath: BaseFS of container " + container.ID + " is unexpectedly nil")
if container.BaseFS == "" {
return nil, errors.New("StatPath: BaseFS of container " + container.ID + " is unexpectedly empty")
}
driver := container.BaseFS
lstat, err := os.Lstat(resolvedPath)
if err != nil {
@ -65,7 +64,7 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.
return nil, err
}
linkTarget, err = filepath.Rel(driver.Path(), hostPath)
linkTarget, err = filepath.Rel(string(container.BaseFS), hostPath)
if err != nil {
return nil, err
}

View file

@ -299,18 +299,18 @@ func (container *Container) SetupWorkingDirectory(rootIdentity idtools.Identity)
// symlinking to a different path) between using this method and using the
// path. See symlink.FollowSymlinkInScope for more details.
func (container *Container) GetResourcePath(path string) (string, error) {
if container.BaseFS == nil {
return "", errors.New("GetResourcePath: BaseFS of container " + container.ID + " is unexpectedly nil")
if container.BaseFS == "" {
return "", errors.New("GetResourcePath: BaseFS of container " + container.ID + " is unexpectedly empty")
}
// IMPORTANT - These are paths on the OS where the daemon is running, hence
// any filepath operations must be done in an OS agnostic way.
r, e := containerfs.ResolveScopedPath(container.BaseFS.Path(), containerfs.CleanScopedPath(path))
r, e := containerfs.ResolveScopedPath(string(container.BaseFS), containerfs.CleanScopedPath(path))
// Log this here on the daemon side as there's otherwise no indication apart
// from the error being propagated all the way back to the client. This makes
// debugging significantly easier and clearly indicates the error comes from the daemon.
if e != nil {
logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", container.BaseFS.Path(), path, e)
logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", string(container.BaseFS), path, e)
}
return r, e
}

View file

@ -246,7 +246,7 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
}
opts := archive.TarResourceRebaseOpts(sourceBase, filepath.Base(absPath))
data, err := archivePath(driver, sourceDir, opts, container.BaseFS.Path())
data, err := archivePath(driver, sourceDir, opts, string(container.BaseFS))
if err != nil {
return nil, nil, err
}
@ -333,14 +333,14 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
// a volume file path.
var baseRel string
if strings.HasPrefix(resolvedPath, `\\?\Volume{`) {
if strings.HasPrefix(resolvedPath, driver.Path()) {
baseRel = resolvedPath[len(driver.Path()):]
if strings.HasPrefix(resolvedPath, string(driver)) {
baseRel = resolvedPath[len(string(driver)):]
if baseRel[:1] == `\` {
baseRel = baseRel[1:]
}
}
} else {
baseRel, err = filepath.Rel(driver.Path(), resolvedPath)
baseRel, err = filepath.Rel(string(driver), resolvedPath)
}
if err != nil {
return err
@ -372,7 +372,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
}
}
if err := extractArchive(driver, content, resolvedPath, options, container.BaseFS.Path()); err != nil {
if err := extractArchive(driver, content, resolvedPath, options, string(container.BaseFS)); err != nil {
return err
}
@ -434,7 +434,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
archv, err := archivePath(driver, basePath, &archive.TarOptions{
Compression: archive.Uncompressed,
IncludeFiles: filter,
}, container.BaseFS.Path())
}, string(container.BaseFS))
if err != nil {
return nil, err
}

View file

@ -1270,7 +1270,7 @@ func (daemon *Daemon) Mount(container *container.Container) error {
}
logrus.WithField("container", container.ID).Debugf("container mounted via layerStore: %v", dir)
if container.BaseFS != nil && container.BaseFS.Path() != dir.Path() {
if container.BaseFS != "" && container.BaseFS != dir {
// The mount path reported by the graph driver should always be trusted on Windows, since the
// volume path for a given mounted layer may change over time. This should only be an error
// on non-Windows operating systems.

View file

@ -61,10 +61,10 @@ func (daemon *Daemon) containerExport(container *container.Container) (arch io.R
return nil, err
}
archv, err := archivePath(basefs, basefs.Path(), &archive.TarOptions{
archv, err := archivePath(basefs, string(basefs), &archive.TarOptions{
Compression: archive.Uncompressed,
IDMap: daemon.idMapping,
}, basefs.Path())
}, string(basefs))
if err != nil {
rwlayer.Unmount()
return nil, err

View file

@ -356,7 +356,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
defer a.locker.Unlock(id)
parents, err := a.getParentLayerPaths(id)
if err != nil && !os.IsNotExist(err) {
return nil, err
return "", err
}
a.pathCacheLock.Lock()
@ -377,7 +377,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
// just return the diff path to the data
if len(parents) > 0 {
if err := a.mount(id, m, mountLabel, parents); err != nil {
return nil, err
return "", err
}
}

View file

@ -48,7 +48,7 @@ func driverGet(d *Driver, id string, mntLabel string) (string, error) {
if err != nil {
return "", err
}
return mnt.Path(), nil
return string(mnt), nil
}
func newDriver(t testing.TB) *Driver {
@ -180,7 +180,7 @@ func TestGetWithoutParent(t *testing.T) {
t.Fatal(err)
}
expected := path.Join(tmp, "diff", "1")
if diffPath.Path() != expected {
if string(diffPath) != expected {
t.Fatalf("Expected path %s got %s", expected, diffPath)
}
}
@ -257,13 +257,13 @@ func TestMountWithParent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if mntPath == nil {
t.Fatal("mntPath should not be nil")
if mntPath == "" {
t.Fatal("mntPath should not be empty")
}
expected := path.Join(tmp, "mnt", "2")
if mntPath.Path() != expected {
t.Fatalf("Expected %s got %s", expected, mntPath.Path())
if string(mntPath) != expected {
t.Fatalf("Expected %s got %s", expected, string(mntPath))
}
}
@ -288,8 +288,8 @@ func TestRemoveMountedDir(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if mntPath == nil {
t.Fatal("mntPath should not be nil")
if mntPath == "" {
t.Fatal("mntPath should not be empty")
}
mounted, err := d.mounted(d.pathCache["2"])

View file

@ -631,20 +631,20 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
dir := d.subvolumesDirID(id)
st, err := os.Stat(dir)
if err != nil {
return nil, err
return "", err
}
if !st.IsDir() {
return nil, fmt.Errorf("%s: not a directory", dir)
return "", fmt.Errorf("%s: not a directory", dir)
}
if quota, err := os.ReadFile(d.quotasDirID(id)); err == nil {
if size, err := strconv.ParseUint(string(quota), 10, 64); err == nil && size >= d.options.minSpace {
if err := d.enableQuota(); err != nil {
return nil, err
return "", err
}
if err := subvolLimitQgroup(dir, size); err != nil {
return nil, err
return "", err
}
}
}

View file

@ -42,7 +42,7 @@ func TestBtrfsSubvolDelete(t *testing.T) {
}
defer d.Put("test")
dir := dirFS.Path()
dir := string(dirFS)
if err := subvolCreate(dir, "subvoltest"); err != nil {
t.Fatal(err)

View file

@ -189,23 +189,23 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
// Create the target directories if they don't exist
if err := idtools.MkdirAllAndChown(path.Join(d.home, "mnt"), 0755, root); err != nil {
d.ctr.Decrement(mp)
return nil, err
return "", err
}
if err := idtools.MkdirAndChown(mp, 0755, root); err != nil && !os.IsExist(err) {
d.ctr.Decrement(mp)
return nil, err
return "", err
}
// Mount the device
if err := d.DeviceSet.MountDevice(id, mp, mountLabel); err != nil {
d.ctr.Decrement(mp)
return nil, err
return "", err
}
if err := idtools.MkdirAllAndChown(rootFs, 0755, root); err != nil {
d.ctr.Decrement(mp)
d.DeviceSet.UnmountDevice(id, mp)
return nil, err
return "", err
}
idFile := path.Join(mp, "id")
@ -215,7 +215,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
if err := os.WriteFile(idFile, []byte(id), 0600); err != nil {
d.ctr.Decrement(mp)
d.DeviceSet.UnmountDevice(id, mp)
return nil, err
return "", err
}
}

View file

@ -50,7 +50,7 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err
if err != nil {
return nil, err
}
layerFs := layerRootFs.Path()
layerFs := string(layerRootFs)
defer func() {
if err != nil {
@ -76,7 +76,7 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err
}
defer driver.Put(parent)
parentFs := parentRootFs.Path()
parentFs := string(parentRootFs)
changes, err := archive.ChangesDirs(layerFs, parentFs)
if err != nil {
@ -112,7 +112,7 @@ func (gdw *NaiveDiffDriver) Changes(id, parent string) ([]archive.Change, error)
}
defer driver.Put(id)
layerFs := layerRootFs.Path()
layerFs := string(layerRootFs)
parentFs := ""
if parent != "" {
@ -121,7 +121,7 @@ func (gdw *NaiveDiffDriver) Changes(id, parent string) ([]archive.Change, error)
return nil, err
}
defer driver.Put(parent)
parentFs = parentRootFs.Path()
parentFs = string(parentRootFs)
}
return archive.ChangesDirs(layerFs, parentFs)
@ -140,7 +140,7 @@ func (gdw *NaiveDiffDriver) ApplyDiff(id, parent string, diff io.Reader) (size i
}
defer driver.Put(id)
layerFs := layerRootFs.Path()
layerFs := string(layerRootFs)
options := &archive.TarOptions{IDMap: gdw.idMap}
start := time.Now().UTC()
logrus.WithField("id", id).Debug("Start untar layer")
@ -169,5 +169,5 @@ func (gdw *NaiveDiffDriver) DiffSize(id, parent string) (size int64, err error)
}
defer driver.Put(id)
return archive.ChangesSize(layerFs.Path(), changes), nil
return archive.ChangesSize(string(layerFs), changes), nil
}

View file

@ -308,7 +308,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
defer d.locker.Unlock(id)
dir := d.dir(id)
if _, err := os.Stat(dir); err != nil {
return nil, err
return "", err
}
diffDir := path.Join(dir, diffDirName)
@ -318,7 +318,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if os.IsNotExist(err) {
return containerfs.NewLocalContainerFS(diffDir), nil
}
return nil, err
return "", err
}
mergedDir := path.Join(dir, mergedDirName)
@ -351,7 +351,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if _, err := os.Stat(path.Join(dir, "committed")); err == nil {
readonly = true
} else if !os.IsNotExist(err) {
return nil, err
return "", err
}
var opts string
@ -365,7 +365,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
mountTarget := mergedDir
if err := idtools.MkdirAndChown(mergedDir, 0700, d.idMap.RootPair()); err != nil {
return nil, err
return "", err
}
mountProgram := exec.Command(binary, "-o", mountData, mountTarget)
@ -377,7 +377,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if output == "" {
output = "<stderr empty>"
}
return nil, errors.Wrapf(err, "using mount program %s: %s", binary, output)
return "", errors.Wrapf(err, "using mount program %s: %s", binary, output)
}
return containerfs.NewLocalContainerFS(mergedDir), nil

View file

@ -250,7 +250,7 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d
for i := 0; i < b.N; i++ {
// Read content
c, err := os.ReadFile(filepath.Join(root.Path(), "testfile.txt"))
c, err := os.ReadFile(filepath.Join(string(root), "testfile.txt"))
if err != nil {
b.Fatal(err)
}

View file

@ -96,10 +96,10 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str
dir, err := driver.Get("empty", "")
assert.NilError(t, err)
verifyFile(t, dir.Path(), 0755|os.ModeDir, 0, 0)
verifyFile(t, string(dir), 0755|os.ModeDir, 0, 0)
// Verify that the directory is empty
fis, err := readDir(dir.Path())
fis, err := readDir(string(dir))
assert.NilError(t, err)
assert.Check(t, is.Len(fis, 0))
@ -324,19 +324,19 @@ func DriverTestSetQuota(t *testing.T, drivername string, required bool) {
quota := uint64(50 * units.MiB)
// Try to write a file smaller than quota, and ensure it works
err = writeRandomFile(path.Join(mountPath.Path(), "smallfile"), quota/2)
err = writeRandomFile(path.Join(string(mountPath), "smallfile"), quota/2)
if err != nil {
t.Fatal(err)
}
defer os.Remove(path.Join(mountPath.Path(), "smallfile"))
defer os.Remove(path.Join(string(mountPath), "smallfile"))
// Try to write a file bigger than quota. We've already filled up half the quota, so hitting the limit should be easy
err = writeRandomFile(path.Join(mountPath.Path(), "bigfile"), quota)
err = writeRandomFile(path.Join(string(mountPath), "bigfile"), quota)
if err == nil {
t.Fatalf("expected write to fail(), instead had success")
}
if pathError, ok := err.(*os.PathError); ok && pathError.Err != unix.EDQUOT && pathError.Err != unix.ENOSPC {
os.Remove(path.Join(mountPath.Path(), "bigfile"))
os.Remove(path.Join(string(mountPath), "bigfile"))
t.Fatalf("expect write() to fail with %v or %v, got %v", unix.EDQUOT, unix.ENOSPC, pathError.Err)
}
}

View file

@ -36,17 +36,17 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error {
}
defer drv.Put(layer)
if err := os.WriteFile(filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(root), "file-a"), randomContent(64, seed), 0755); err != nil {
return err
}
if err := os.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(string(root), "dir-b"), 0755); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(root), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
return err
}
return os.WriteFile(filepath.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755)
return os.WriteFile(filepath.Join(string(root), "file-c"), randomContent(128*128, seed+2), 0755)
}
func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error {
@ -56,7 +56,7 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e
}
defer drv.Put(layer)
fileContent, err := os.ReadFile(filepath.Join(root.Path(), filename))
fileContent, err := os.ReadFile(filepath.Join(string(root), filename))
if err != nil {
return err
}
@ -75,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
}
defer drv.Put(layer)
return os.WriteFile(filepath.Join(root.Path(), filename), content, 0755)
return os.WriteFile(filepath.Join(string(root), filename), content, 0755)
}
func addDirectory(drv graphdriver.Driver, layer, dir string) error {
@ -85,7 +85,7 @@ func addDirectory(drv graphdriver.Driver, layer, dir string) error {
}
defer drv.Put(layer)
return os.MkdirAll(filepath.Join(root.Path(), dir), 0755)
return os.MkdirAll(filepath.Join(string(root), dir), 0755)
}
func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
@ -96,7 +96,7 @@ func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
defer drv.Put(layer)
for _, filename := range names {
if err := os.RemoveAll(filepath.Join(root.Path(), filename)); err != nil {
if err := os.RemoveAll(filepath.Join(string(root), filename)); err != nil {
return err
}
}
@ -110,8 +110,8 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
}
defer drv.Put(layer)
if _, err := os.Stat(filepath.Join(root.Path(), filename)); err == nil {
return fmt.Errorf("file still exists: %s", filepath.Join(root.Path(), filename))
if _, err := os.Stat(filepath.Join(string(root), filename)); err == nil {
return fmt.Errorf("file still exists: %s", filepath.Join(string(root), filename))
} else if !os.IsNotExist(err) {
return err
}
@ -127,7 +127,7 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e
defer drv.Put(layer)
for i := 0; i < count; i += 100 {
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i))
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
@ -152,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 := os.MkdirAll(filepath.Join(root.Path(), archiveRoot), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(string(root), archiveRoot), 0755); err != nil {
return nil, err
}
for j := 0; i+j < count && j < 100; j++ {
@ -168,21 +168,21 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
case 0:
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
change.Kind = archive.ChangeModify
if err := os.WriteFile(filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
return nil, err
}
// Add file
case 1:
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j))
change.Kind = archive.ChangeAdd
if err := os.WriteFile(filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
return nil, err
}
// Remove file
case 2:
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
change.Kind = archive.ChangeDelete
if err := os.Remove(filepath.Join(root.Path(), change.Path)); err != nil {
if err := os.Remove(filepath.Join(string(root), change.Path)); err != nil {
return nil, err
}
}
@ -201,7 +201,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64)
defer drv.Put(layer)
for i := 0; i < count; i += 100 {
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i))
for j := 0; i+j < count && j < 100; j++ {
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
fileContent, err := os.ReadFile(file)
@ -254,10 +254,10 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
}
defer drv.Put(layer)
if err := os.WriteFile(filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(root), "top-id"), []byte(layer), 0755); err != nil {
return err
}
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i))
if err := os.MkdirAll(layerDir, 0755); err != nil {
return err
}
@ -291,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
}
defer drv.Put(layer)
layerIDBytes, err := os.ReadFile(filepath.Join(root.Path(), "top-id"))
layerIDBytes, err := os.ReadFile(filepath.Join(string(root), "top-id"))
if err != nil {
return err
}
@ -301,7 +301,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
}
for i := count; i > 0; i-- {
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i))
thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id"))
if err != nil {

View file

@ -45,11 +45,11 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) {
assert.NilError(t, err)
defer driver.Put(name)
subdir := filepath.Join(dirFS.Path(), "a subdir")
subdir := filepath.Join(string(dirFS), "a subdir")
assert.NilError(t, os.Mkdir(subdir, 0705|os.ModeSticky))
assert.NilError(t, contdriver.LocalDriver.Lchown(subdir, 1, 2))
file := filepath.Join(dirFS.Path(), "a file")
file := filepath.Join(string(dirFS), "a file")
err = os.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid)
assert.NilError(t, err)
}
@ -59,13 +59,13 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) {
assert.NilError(t, err)
defer driver.Put(name)
subdir := filepath.Join(dirFS.Path(), "a subdir")
subdir := filepath.Join(string(dirFS), "a subdir")
verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2)
file := filepath.Join(dirFS.Path(), "a file")
file := filepath.Join(string(dirFS), "a file")
verifyFile(t, file, 0222|os.ModeSetuid, 0, 0)
files, err := readDir(dirFS.Path())
files, err := readDir(string(dirFS))
assert.NilError(t, err)
assert.Check(t, is.Len(files, 2))
}

View file

@ -344,7 +344,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro
defer d.locker.Unlock(id)
dir := d.dir(id)
if _, err := os.Stat(dir); err != nil {
return nil, err
return "", err
}
// If id has a root, just return it
rootDir := path.Join(dir, "root")
@ -371,11 +371,11 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro
}()
lowerID, err := os.ReadFile(path.Join(dir, "lower-id"))
if err != nil {
return nil, err
return "", err
}
root := d.idMap.RootPair()
if err := idtools.MkdirAndChown(mergedDir, 0700, root); err != nil {
return nil, err
return "", err
}
var (
lowerDir = path.Join(d.dir(string(lowerID)), "root")
@ -384,12 +384,12 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro
opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lowerDir, upperDir, workDir)
)
if err := unix.Mount("overlay", mergedDir, "overlay", 0, label.FormatMountLabel(opts, mountLabel)); err != nil {
return nil, fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
}
// chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a
// user namespace requires this to move a directory from lower to upper.
if err := root.Chown(path.Join(workDir, "work")); err != nil {
return nil, err
return "", err
}
return containerfs.NewLocalContainerFS(mergedDir), nil
}

View file

@ -518,7 +518,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
defer d.locker.Unlock(id)
dir := d.dir(id)
if _, err := os.Stat(dir); err != nil {
return nil, err
return "", err
}
diffDir := path.Join(dir, diffDirName)
@ -528,7 +528,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if os.IsNotExist(err) {
return containerfs.NewLocalContainerFS(diffDir), nil
}
return nil, err
return "", err
}
mergedDir := path.Join(dir, mergedDirName)
@ -559,7 +559,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if _, err := os.Stat(path.Join(dir, "committed")); err == nil {
readonly = true
} else if !os.IsNotExist(err) {
return nil, err
return "", err
}
var opts string
@ -575,7 +575,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
root := d.idMap.RootPair()
if err := idtools.MkdirAndChown(mergedDir, 0700, root); err != nil {
return nil, err
return "", err
}
pageSize := unix.Getpagesize()
@ -592,7 +592,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
}
mountData = label.FormatMountLabel(opts, mountLabel)
if len(mountData) > pageSize-1 {
return nil, fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
}
mount = func(source string, target string, mType string, flags uintptr, label string) error {
@ -602,14 +602,14 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
}
if err := mount("overlay", mountTarget, "overlay", 0, mountData); err != nil {
return nil, fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
}
if !readonly {
// chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a
// user namespace requires this to move a directory from lower to upper.
if err := root.Chown(path.Join(workDir, workDirName)); err != nil {
return nil, err
return "", err
}
}

View file

@ -135,7 +135,7 @@ func (d *graphDriverProxy) Get(id, mountLabel string) (containerfs.ContainerFS,
}
var ret graphDriverResponse
if err := d.client.Call("GraphDriver.Get", args, &ret); err != nil {
return nil, err
return "", err
}
var err error
if ret.Err != "" {

View file

@ -172,7 +172,7 @@ func (d *Driver) create(id, parent string, size uint64) error {
if err != nil {
return fmt.Errorf("%s: %s", parent, err)
}
return CopyDir(parentDir.Path(), dir)
return CopyDir(string(parentDir), dir)
}
func (d *Driver) dir(id string) string {
@ -188,9 +188,9 @@ func (d *Driver) Remove(id string) error {
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
dir := d.dir(id)
if st, err := os.Stat(dir); err != nil {
return nil, err
return "", err
} else if !st.IsDir() {
return nil, fmt.Errorf("%s: not a directory", dir)
return "", fmt.Errorf("%s: not a directory", dir)
}
return containerfs.NewLocalContainerFS(dir), nil
}

View file

@ -399,7 +399,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
rID, err := d.resolveID(id)
if err != nil {
return nil, err
return "", err
}
if count := d.ctr.Increment(rID); count > 1 {
return containerfs.NewLocalContainerFS(d.cache[rID]), nil
@ -409,19 +409,19 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
layerChain, err := d.getLayerChain(rID)
if err != nil {
d.ctr.Decrement(rID)
return nil, err
return "", err
}
if err := hcsshim.ActivateLayer(d.info, rID); err != nil {
d.ctr.Decrement(rID)
return nil, err
return "", err
}
if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil {
d.ctr.Decrement(rID)
if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil {
logrus.Warnf("Failed to Deactivate %s: %s", id, err)
}
return nil, err
return "", err
}
mountPath, err := hcsshim.GetLayerMountPath(d.info, rID)
@ -433,7 +433,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil {
logrus.Warnf("Failed to Deactivate %s: %s", id, err)
}
return nil, err
return "", err
}
d.cacheMu.Lock()
d.cache[rID] = mountPath
@ -651,7 +651,7 @@ func (d *Driver) DiffSize(id, parent string) (size int64, err error) {
}
defer d.Put(id)
return archive.ChangesSize(layerFs.Path(), changes), nil
return archive.ChangesSize(string(layerFs), changes), nil
}
// GetMetadata returns custom driver information.

View file

@ -391,17 +391,17 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
root := d.idMap.RootPair()
// Create the target directories if they don't exist
if err := idtools.MkdirAllAndChown(mountpoint, 0755, root); err != nil {
return nil, err
return "", err
}
if err := mount.Mount(filesystem, mountpoint, "zfs", options); err != nil {
return nil, errors.Wrap(err, "error creating zfs mount")
return "", errors.Wrap(err, "error creating zfs mount")
}
// this could be our first mount after creation of the filesystem, and the root dir may still have root
// permissions instead of the remapped root uid:gid (if user namespaces are enabled):
if err := root.Chown(mountpoint); err != nil {
return nil, fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err)
return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err)
}
return containerfs.NewLocalContainerFS(mountpoint), nil

View file

@ -115,11 +115,11 @@ func (l *rwLayer) Release() error {
return nil
}
if l.fs != nil {
if l.fs != "" {
if err := l.rwLayer.Unmount(); err != nil {
return errors.Wrap(err, "failed to unmount RWLayer")
}
l.fs = nil
l.fs = ""
}
metadata, err := l.layerStore.ReleaseRWLayer(l.rwLayer)

View file

@ -20,7 +20,7 @@ import (
// the container from unwanted side-effects on the rw layer.
func Setup(initLayerFs containerfs.ContainerFS, rootIdentity idtools.Identity) error {
// Since all paths are local to the container, we can just extract initLayerFs.Path()
initLayer := initLayerFs.Path()
initLayer := string(initLayerFs)
for pth, typ := range map[string]string{
"/dev/pts": "dir",

View file

@ -721,8 +721,8 @@ func sysctlExists(s string) bool {
// WithCommonOptions sets common docker options
func WithCommonOptions(daemon *Daemon, c *container.Container) coci.SpecOpts {
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
if c.BaseFS == nil && !daemon.UsesSnapshotter() {
return errors.New("populateCommonSpec: BaseFS of container " + c.ID + " is unexpectedly nil")
if c.BaseFS == "" && !daemon.UsesSnapshotter() {
return errors.New("populateCommonSpec: BaseFS of container " + c.ID + " is unexpectedly empty")
}
linkedEnv, err := daemon.setupLinkedContainers(c)
if err != nil {
@ -730,7 +730,7 @@ func WithCommonOptions(daemon *Daemon, c *container.Container) coci.SpecOpts {
}
if !daemon.UsesSnapshotter() {
s.Root = &specs.Root{
Path: c.BaseFS.Path(),
Path: string(c.BaseFS),
Readonly: c.HostConfig.ReadonlyRootfs,
}
}

View file

@ -236,11 +236,11 @@ func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.S
}
s.Root.Readonly = false // Windows does not support a read-only root filesystem
if !isHyperV {
if c.BaseFS == nil {
return errors.New("createSpecWindowsFields: BaseFS of container " + c.ID + " is unexpectedly nil")
if c.BaseFS == "" {
return errors.New("createSpecWindowsFields: BaseFS of container " + c.ID + " is unexpectedly empty")
}
s.Root.Path = c.BaseFS.Path() // This is not set for Hyper-V containers
s.Root.Path = string(c.BaseFS) // This is not set for Hyper-V containers
if !strings.HasSuffix(s.Root.Path, `\`) {
s.Root.Path = s.Root.Path + `\` // Ensure a correctly formatted volume GUID path \\?\Volume{GUID}\
}

View file

@ -251,7 +251,7 @@ func (daemon *Daemon) Cleanup(container *container.Container) {
daemon.unregisterExecCommand(container, eConfig)
}
if container.BaseFS != nil && container.BaseFS.Path() != "" {
if container.BaseFS != "" {
if err := container.UnmountVolumes(daemon.LogVolumeEvent); err != nil {
logrus.Warnf("%s cleanup: Failed to umount volumes: %v", container.ID, err)
}

View file

@ -219,7 +219,7 @@ func setupPlugin(t *testing.T, ec map[string]*graphEventsCounter, ext string, mu
respond(w, err)
return
}
respond(w, &graphDriverResponse{Dir: dir.Path()})
respond(w, &graphDriverResponse{Dir: string(dir)})
})
mux.HandleFunc("/GraphDriver.Put", func(w http.ResponseWriter, r *http.Request) {

View file

@ -786,5 +786,5 @@ func (n *naiveDiffPathDriver) DiffGetter(id string) (graphdriver.FileGetCloser,
if err != nil {
return nil, err
}
return &fileGetPutter{storage.NewPathFileGetter(p.Path()), n.Driver, id}, nil
return &fileGetPutter{storage.NewPathFileGetter(string(p)), n.Driver, id}, nil
}

View file

@ -139,7 +139,7 @@ func newTestFile(name string, content []byte, perm os.FileMode) FileApplier {
}
func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
fullPath := filepath.Join(root.Path(), tf.name)
fullPath := filepath.Join(string(root), tf.name)
if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil {
return err
}
@ -267,7 +267,7 @@ func TestMountAndRegister(t *testing.T) {
t.Fatal(err)
}
b, err := os.ReadFile(filepath.Join(path2.Path(), "testfile.txt"))
b, err := os.ReadFile(filepath.Join(string(path2), "testfile.txt"))
if err != nil {
t.Fatal(err)
}
@ -375,7 +375,7 @@ func TestStoreRestore(t *testing.T) {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile.txt"), []byte("nothing here"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(string(pathFS), "testfile.txt"), []byte("nothing here"), 0644); err != nil {
t.Fatal(err)
}
@ -409,20 +409,20 @@ func TestStoreRestore(t *testing.T) {
if mountPath, err := m2.Mount(""); err != nil {
t.Fatal(err)
} else if pathFS.Path() != mountPath.Path() {
t.Fatalf("Unexpected path %s, expected %s", mountPath.Path(), pathFS.Path())
} else if string(pathFS) != string(mountPath) {
t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS))
}
if mountPath, err := m2.Mount(""); err != nil {
t.Fatal(err)
} else if pathFS.Path() != mountPath.Path() {
t.Fatalf("Unexpected path %s, expected %s", mountPath.Path(), pathFS.Path())
} else if string(pathFS) != string(mountPath) {
t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS))
}
if err := m2.Unmount(); err != nil {
t.Fatal(err)
}
b, err := os.ReadFile(filepath.Join(pathFS.Path(), "testfile.txt"))
b, err := os.ReadFile(filepath.Join(string(pathFS), "testfile.txt"))
if err != nil {
t.Fatal(err)
}

View file

@ -37,7 +37,7 @@ func GetLayerPath(s Store, layer ChainID) (string, error) {
return "", err
}
return path.Path(), nil
return string(path), nil
}
func (ls *layerStore) mountID(name string) string {

View file

@ -47,12 +47,12 @@ func TestMountInit(t *testing.T) {
t.Fatal(err)
}
fi, err := os.Stat(filepath.Join(pathFS.Path(), "testfile.txt"))
fi, err := os.Stat(filepath.Join(string(pathFS), "testfile.txt"))
if err != nil {
t.Fatal(err)
}
f, err := os.Open(filepath.Join(pathFS.Path(), "testfile.txt"))
f, err := os.Open(filepath.Join(string(pathFS), "testfile.txt"))
if err != nil {
t.Fatal(err)
}
@ -107,7 +107,7 @@ func TestMountSize(t *testing.T) {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pathFS.Path(), "file2"), content2, 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(pathFS), "file2"), content2, 0755); err != nil {
t.Fatal(err)
}
@ -159,23 +159,23 @@ func TestMountChanges(t *testing.T) {
t.Fatal(err)
}
if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS.Path(), "testfile1.txt"), 0755); err != nil {
if err := driver.LocalDriver.Lchmod(filepath.Join(string(pathFS), "testfile1.txt"), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile1.txt"), []byte("mount data!"), 0755); err != nil {
if err := os.WriteFile(filepath.Join(string(pathFS), "testfile1.txt"), []byte("mount data!"), 0755); err != nil {
t.Fatal(err)
}
if err := os.Remove(filepath.Join(pathFS.Path(), "testfile2.txt")); err != nil {
if err := os.Remove(filepath.Join(string(pathFS), "testfile2.txt")); err != nil {
t.Fatal(err)
}
if err := driver.LocalDriver.Lchmod(filepath.Join(pathFS.Path(), "testfile3.txt"), 0755); err != nil {
if err := driver.LocalDriver.Lchmod(filepath.Join(string(pathFS), "testfile3.txt"), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pathFS.Path(), "testfile4.txt"), []byte("mount data!"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(string(pathFS), "testfile4.txt"), []byte("mount data!"), 0644); err != nil {
t.Fatal(err)
}
@ -250,7 +250,7 @@ func TestMountApply(t *testing.T) {
t.Fatal(err)
}
f, err := os.Open(filepath.Join(pathFS.Path(), "newfile.txt"))
f, err := os.Open(filepath.Join(string(pathFS), "newfile.txt"))
if err != nil {
t.Fatal(err)
}

View file

@ -7,26 +7,12 @@ import (
)
// ContainerFS is that represents a root file system
type ContainerFS interface {
// Path returns the path to the root. Note that this may not exist
// on the local system, so the continuity operations must be used
Path() string
}
type ContainerFS string
// 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,
}
}
type local struct {
path string
}
func (l *local) Path() string {
return l.path
return ContainerFS(path)
}
// ResolveScopedPath evaluates the given path scoped to the root.