pkg/containerfs: alias ContainerFS to string

Drop the constructor and redundant string() type-casts.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2022-09-23 14:09:51 -04:00
parent 95824f2b5f
commit e332c41e9d
43 changed files with 136 additions and 158 deletions

View file

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

View file

@ -45,7 +45,7 @@ type copyInfo struct {
} }
func (c copyInfo) fullPath() (string, error) { func (c copyInfo) fullPath() (string, error) {
return containerfs.ResolveScopedPath(string(c.root), c.path) return containerfs.ResolveScopedPath(c.root, c.path)
} }
func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo { 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 path = unnamedFilename
} }
o.tmpPaths = append(o.tmpPaths, string(remote.Root())) o.tmpPaths = append(o.tmpPaths, remote.Root())
hash, err := remote.Hash(path) hash, err := remote.Hash(path)
ci := newCopyInfoFromSource(remote, path, hash) 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()) o.source, err = remotecontext.NewLazySource(rwLayer.Root())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create context for copy from %s", string(rwLayer.Root())) return nil, errors.Wrapf(err, "failed to create context for copy from %s", rwLayer.Root())
} }
} }
@ -259,7 +259,7 @@ func (o *copier) storeInPathCache(im *imageMount, path string, hash string) {
func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) { func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) {
root := o.source.Root() root := o.source.Root()
var copyInfos []copyInfo var copyInfos []copyInfo
if err := filepath.Walk(string(root), func(path string, info os.FileInfo, err error) error { if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
@ -442,7 +442,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b
return return
} }
lc, err := remotecontext.NewLazySource(containerfs.NewLocalContainerFS(tmpDir)) lc, err := remotecontext.NewLazySource(tmpDir)
return lc, filename, err return lc, filename, 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 // translated (if necessary because of user namespaces), and replace
// the root pair with the chown pair for copy operations // the root pair with the chown pair for copy operations
if inst.chownStr != "" { if inst.chownStr != "" {
identity, err = parseChownFlag(b, state, inst.chownStr, string(destInfo.root), b.idMapping) identity, err = parseChownFlag(b, state, inst.chownStr, destInfo.root, b.idMapping)
if err != nil { if err != nil {
if b.options.Platform != "windows" { if b.options.Platform != "windows" {
return errors.Wrapf(err, "unable to convert uid/gid chown string to host mapping") return errors.Wrapf(err, "unable to convert uid/gid chown string to host mapping")

View file

@ -20,7 +20,7 @@ type archiveContext struct {
} }
func (c *archiveContext) Close() error { func (c *archiveContext) Close() error {
return os.RemoveAll(string(c.root)) return os.RemoveAll(c.root)
} }
func convertPathError(err error, cleanpath string) error { func convertPathError(err error, cleanpath string) error {
@ -53,7 +53,7 @@ func FromArchive(tarStream io.Reader) (builder.Source, error) {
} }
// Assume local file system. Since it's coming from a tar file. // Assume local file system. Since it's coming from a tar file.
tsc := &archiveContext{root: containerfs.NewLocalContainerFS(root)} tsc := &archiveContext{root: root}
// Make sure we clean-up upon error. In the happy case the caller // Make sure we clean-up upon error. In the happy case the caller
// is expected to manage the clean-up // is expected to manage the clean-up
@ -100,7 +100,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
return "", err return "", err
} }
rel, err := filepath.Rel(string(c.root), fullpath) rel, err := filepath.Rel(c.root, fullpath)
if err != nil { if err != nil {
return "", convertPathError(err, cleanpath) 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) { func normalize(path string, root containerfs.ContainerFS) (cleanPath, fullPath string, err error) {
cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:] cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:]
fullPath, err = containerfs.ResolveScopedPath(string(root), path) fullPath, err = containerfs.ResolveScopedPath(root, path)
if err != nil { if err != nil {
return "", "", errors.Wrapf(err, "forbidden path outside the build context: %s (%s)", path, cleanPath) 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 // FullPath is a helper for getting a full path for a path from a source
func FullPath(remote builder.Source, path string) (string, error) { func FullPath(remote builder.Source, path string) (string, error) {
fullPath, err := containerfs.ResolveScopedPath(string(remote.Root()), path) fullPath, err := containerfs.ResolveScopedPath(remote.Root(), path)
if err != nil { if err != nil {
if runtime.GOOS == "windows" { 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) 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

@ -53,7 +53,7 @@ func checkDirectory(t *testing.T, dir string, expectedFiles []string) {
} }
func executeProcess(t *testing.T, contextDir string) { func executeProcess(t *testing.T, contextDir string) {
modifiableCtx := &stubRemote{root: containerfs.NewLocalContainerFS(contextDir)} modifiableCtx := &stubRemote{root: contextDir}
err := removeDockerfile(modifiableCtx, builder.DefaultDockerfileName) err := removeDockerfile(modifiableCtx, builder.DefaultDockerfileName)
@ -119,5 +119,5 @@ func (r *stubRemote) Close() error {
return errors.New("not implemented") return errors.New("not implemented")
} }
func (r *stubRemote) Remove(p string) error { func (r *stubRemote) Remove(p string) error {
return os.Remove(filepath.Join(string(r.root), p)) return os.Remove(filepath.Join(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) { func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error) {
p := filepath.Join(string(c.root), relPath) p := filepath.Join(c.root, relPath)
h, err := NewFileHash(p, relPath, fi) h, err := NewFileHash(p, relPath, fi)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "failed to create hash for %s", relPath) 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) { func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
// filepath.Rel can't handle UUID paths in windows // filepath.Rel can't handle UUID paths in windows
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
pfx := string(basepath) + `\` pfx := basepath + `\`
if strings.HasPrefix(targpath, pfx) { if strings.HasPrefix(targpath, pfx) {
p := strings.TrimPrefix(targpath, pfx) p := strings.TrimPrefix(targpath, pfx)
if p == "" { if p == "" {
@ -100,5 +100,5 @@ func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
return p, nil return p, nil
} }
} }
return filepath.Rel(string(basepath), targpath) return filepath.Rel(basepath, targpath)
} }

View file

@ -28,7 +28,7 @@ type CachableSource struct {
func NewCachableSource(root string) *CachableSource { func NewCachableSource(root string) *CachableSource {
ts := &CachableSource{ ts := &CachableSource{
tree: iradix.New(), tree: iradix.New(),
root: containerfs.NewLocalContainerFS(root), root: root,
} }
return ts return ts
} }
@ -67,7 +67,7 @@ func (cs *CachableSource) Scan() error {
return err return err
} }
txn := iradix.New().Txn() txn := iradix.New().Txn()
err = filepath.Walk(string(cs.root), func(path string, info os.FileInfo, err error) error { err = filepath.Walk(cs.root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to walk %s", path) 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) t.Fatalf("Error while executing Close: %s", err)
} }
_, err = os.Stat(string(src.Root())) _, err = os.Stat(src.Root())
if !errors.Is(err, os.ErrNotExist) { if !errors.Is(err, os.ErrNotExist) {
t.Fatal("Directory should not exist at this point") t.Fatal("Directory should not exist at this point")
@ -118,7 +118,7 @@ func TestRemoveDirectory(t *testing.T) {
src := makeTestArchiveContext(t, contextDir) src := makeTestArchiveContext(t, contextDir)
_, err = os.Stat(filepath.Join(string(src.Root()), relativePath)) _, err = os.Stat(filepath.Join(src.Root(), relativePath))
if err != nil { if err != nil {
t.Fatalf("Statting %s shouldn't fail: %+v", relativePath, err) 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) t.Fatalf("Error when executing Remove: %s", err)
} }
_, err = os.Stat(filepath.Join(string(src.Root()), relativePath)) _, err = os.Stat(filepath.Join(src.Root(), relativePath))
if !errors.Is(err, os.ErrNotExist) { if !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Directory should not exist at this point: %+v ", err) t.Fatalf("Directory should not exist at this point: %+v ", err)
} }

View file

@ -64,7 +64,7 @@ func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.
return nil, err return nil, err
} }
linkTarget, err = filepath.Rel(string(container.BaseFS), hostPath) linkTarget, err = filepath.Rel(container.BaseFS, hostPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -304,13 +304,13 @@ func (container *Container) GetResourcePath(path string) (string, error) {
} }
// IMPORTANT - These are paths on the OS where the daemon is running, hence // IMPORTANT - These are paths on the OS where the daemon is running, hence
// any filepath operations must be done in an OS agnostic way. // any filepath operations must be done in an OS agnostic way.
r, e := containerfs.ResolveScopedPath(string(container.BaseFS), containerfs.CleanScopedPath(path)) r, e := containerfs.ResolveScopedPath(container.BaseFS, containerfs.CleanScopedPath(path))
// Log this here on the daemon side as there's otherwise no indication apart // 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 // 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. // debugging significantly easier and clearly indicates the error comes from the daemon.
if e != nil { if e != nil {
logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", string(container.BaseFS), path, e) logrus.Errorf("Failed to ResolveScopedPath BaseFS %s path %s %s\n", container.BaseFS, path, e)
} }
return r, 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)) opts := archive.TarResourceRebaseOpts(sourceBase, filepath.Base(absPath))
data, err := archivePath(driver, sourceDir, opts, string(container.BaseFS)) data, err := archivePath(driver, sourceDir, opts, container.BaseFS)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -333,14 +333,14 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
// a volume file path. // a volume file path.
var baseRel string var baseRel string
if strings.HasPrefix(resolvedPath, `\\?\Volume{`) { if strings.HasPrefix(resolvedPath, `\\?\Volume{`) {
if strings.HasPrefix(resolvedPath, string(driver)) { if strings.HasPrefix(resolvedPath, driver) {
baseRel = resolvedPath[len(string(driver)):] baseRel = resolvedPath[len(driver):]
if baseRel[:1] == `\` { if baseRel[:1] == `\` {
baseRel = baseRel[1:] baseRel = baseRel[1:]
} }
} }
} else { } else {
baseRel, err = filepath.Rel(string(driver), resolvedPath) baseRel, err = filepath.Rel(driver, resolvedPath)
} }
if err != nil { if err != nil {
return err return err
@ -372,7 +372,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
} }
} }
if err := extractArchive(driver, content, resolvedPath, options, string(container.BaseFS)); err != nil { if err := extractArchive(driver, content, resolvedPath, options, container.BaseFS); err != nil {
return err return err
} }
@ -434,7 +434,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
archv, err := archivePath(driver, basePath, &archive.TarOptions{ archv, err := archivePath(driver, basePath, &archive.TarOptions{
Compression: archive.Uncompressed, Compression: archive.Uncompressed,
IncludeFiles: filter, IncludeFiles: filter,
}, string(container.BaseFS)) }, container.BaseFS)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

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

View file

@ -370,7 +370,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
} }
} }
if count := a.ctr.Increment(m); count > 1 { if count := a.ctr.Increment(m); count > 1 {
return containerfs.NewLocalContainerFS(m), nil return m, nil
} }
// If a dir does not have a parent ( no layers )do not try to mount // If a dir does not have a parent ( no layers )do not try to mount
@ -384,7 +384,7 @@ func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
a.pathCacheLock.Lock() a.pathCacheLock.Lock()
a.pathCache[id] = m a.pathCache[id] = m
a.pathCacheLock.Unlock() a.pathCacheLock.Unlock()
return containerfs.NewLocalContainerFS(m), nil return m, nil
} }
// Put unmounts and updates list of active mounts. // Put unmounts and updates list of active mounts.

View file

@ -43,14 +43,6 @@ func testInit(dir string, t testing.TB) graphdriver.Driver {
return d return d
} }
func driverGet(d *Driver, id string, mntLabel string) (string, error) {
mnt, err := d.Get(id, mntLabel)
if err != nil {
return "", err
}
return string(mnt), nil
}
func newDriver(t testing.TB) *Driver { func newDriver(t testing.TB) *Driver {
if err := os.MkdirAll(tmp, 0755); err != nil { if err := os.MkdirAll(tmp, 0755); err != nil {
t.Fatal(err) t.Fatal(err)
@ -180,7 +172,7 @@ func TestGetWithoutParent(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expected := path.Join(tmp, "diff", "1") expected := path.Join(tmp, "diff", "1")
if string(diffPath) != expected { if diffPath != expected {
t.Fatalf("Expected path %s got %s", expected, diffPath) t.Fatalf("Expected path %s got %s", expected, diffPath)
} }
} }
@ -262,8 +254,8 @@ func TestMountWithParent(t *testing.T) {
} }
expected := path.Join(tmp, "mnt", "2") expected := path.Join(tmp, "mnt", "2")
if string(mntPath) != expected { if mntPath != expected {
t.Fatalf("Expected %s got %s", expected, string(mntPath)) t.Fatalf("Expected %s got %s", expected, mntPath)
} }
} }
@ -323,7 +315,7 @@ func TestGetDiff(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
diffPath, err := driverGet(d, "1", "") diffPath, err := d.Get("1", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -367,7 +359,7 @@ func TestChanges(t *testing.T) {
} }
}() }()
mntPoint, err := driverGet(d, "2", "") mntPoint, err := d.Get("2", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -406,7 +398,7 @@ func TestChanges(t *testing.T) {
if err := d.CreateReadWrite("3", "2", nil); err != nil { if err := d.CreateReadWrite("3", "2", nil); err != nil {
t.Fatal(err) t.Fatal(err)
} }
mntPoint, err = driverGet(d, "3", "") mntPoint, err = d.Get("3", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -452,7 +444,7 @@ func TestDiffSize(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
diffPath, err := driverGet(d, "1", "") diffPath, err := d.Get("1", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -494,7 +486,7 @@ func TestChildDiffSize(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
diffPath, err := driverGet(d, "1", "") diffPath, err := d.Get("1", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -595,7 +587,7 @@ func TestApplyDiff(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
diffPath, err := driverGet(d, "1", "") diffPath, err := d.Get("1", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -630,7 +622,7 @@ func TestApplyDiff(t *testing.T) {
// Ensure that the file is in the mount point for id 3 // Ensure that the file is in the mount point for id 3
mountPoint, err := driverGet(d, "3", "") mountPoint, err := d.Get("3", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -673,7 +665,7 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
err := d.CreateReadWrite(current, parent, nil) err := d.CreateReadWrite(current, parent, nil)
assert.NilError(t, err, "current layer %d", i) assert.NilError(t, err, "current layer %d", i)
point, err := driverGet(d, current, "") point, err := d.Get(current, "")
assert.NilError(t, err, "current layer %d", i) assert.NilError(t, err, "current layer %d", i)
f, err := os.Create(path.Join(point, current)) f, err := os.Create(path.Join(point, current))
@ -689,7 +681,7 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
} }
// Perform the actual mount for the top most image // Perform the actual mount for the top most image
point, err := driverGet(d, last, "") point, err := d.Get(last, "")
assert.NilError(t, err) assert.NilError(t, err)
files, err := os.ReadDir(point) files, err := os.ReadDir(point)
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -649,7 +649,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
} }
} }
return containerfs.NewLocalContainerFS(dir), nil return dir, nil
} }
// Put is not implemented for BTRFS as there is no cleanup required for the id. // Put is not implemented for BTRFS as there is no cleanup required for the id.

View file

@ -36,14 +36,12 @@ func TestBtrfsSubvolDelete(t *testing.T) {
} }
defer graphtest.PutDriver(t) defer graphtest.PutDriver(t)
dirFS, err := d.Get("test", "") dir, err := d.Get("test", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer d.Put("test") defer d.Put("test")
dir := string(dirFS)
if err := subvolCreate(dir, "subvoltest"); err != nil { if err := subvolCreate(dir, "subvoltest"); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -181,7 +181,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
mp := path.Join(d.home, "mnt", id) mp := path.Join(d.home, "mnt", id)
rootFs := path.Join(mp, "rootfs") rootFs := path.Join(mp, "rootfs")
if count := d.ctr.Increment(mp); count > 1 { if count := d.ctr.Increment(mp); count > 1 {
return containerfs.NewLocalContainerFS(rootFs), nil return rootFs, nil
} }
root := d.idMap.RootPair() root := d.idMap.RootPair()
@ -219,7 +219,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
} }
} }
return containerfs.NewLocalContainerFS(rootFs), nil return rootFs, nil
} }
// Put unmounts a device and removes it. // Put unmounts a device and removes it.

View file

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

View file

@ -316,14 +316,14 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if err != nil { if err != nil {
// If no lower, just return diff directory // If no lower, just return diff directory
if os.IsNotExist(err) { if os.IsNotExist(err) {
return containerfs.NewLocalContainerFS(diffDir), nil return diffDir, nil
} }
return "", err return "", err
} }
mergedDir := path.Join(dir, mergedDirName) mergedDir := path.Join(dir, mergedDirName)
if count := d.ctr.Increment(mergedDir); count > 1 { if count := d.ctr.Increment(mergedDir); count > 1 {
return containerfs.NewLocalContainerFS(mergedDir), nil return mergedDir, nil
} }
defer func() { defer func() {
if retErr != nil { if retErr != nil {
@ -380,7 +380,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
return "", 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 return mergedDir, nil
} }
// Put unmounts the mount path created for the give id. // Put unmounts the mount path created for the give id.

View file

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

View file

@ -96,10 +96,10 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str
dir, err := driver.Get("empty", "") dir, err := driver.Get("empty", "")
assert.NilError(t, err) assert.NilError(t, err)
verifyFile(t, string(dir), 0755|os.ModeDir, 0, 0) verifyFile(t, dir, 0755|os.ModeDir, 0, 0)
// Verify that the directory is empty // Verify that the directory is empty
fis, err := readDir(string(dir)) fis, err := readDir(dir)
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(fis, 0)) 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) quota := uint64(50 * units.MiB)
// Try to write a file smaller than quota, and ensure it works // Try to write a file smaller than quota, and ensure it works
err = writeRandomFile(path.Join(string(mountPath), "smallfile"), quota/2) err = writeRandomFile(path.Join(mountPath, "smallfile"), quota/2)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(path.Join(string(mountPath), "smallfile")) defer os.Remove(path.Join(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 // 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(string(mountPath), "bigfile"), quota) err = writeRandomFile(path.Join(mountPath, "bigfile"), quota)
if err == nil { if err == nil {
t.Fatalf("expected write to fail(), instead had success") t.Fatalf("expected write to fail(), instead had success")
} }
if pathError, ok := err.(*os.PathError); ok && pathError.Err != unix.EDQUOT && pathError.Err != unix.ENOSPC { if pathError, ok := err.(*os.PathError); ok && pathError.Err != unix.EDQUOT && pathError.Err != unix.ENOSPC {
os.Remove(path.Join(string(mountPath), "bigfile")) os.Remove(path.Join(mountPath, "bigfile"))
t.Fatalf("expect write() to fail with %v or %v, got %v", unix.EDQUOT, unix.ENOSPC, pathError.Err) 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) defer drv.Put(layer)
if err := os.WriteFile(filepath.Join(string(root), "file-a"), randomContent(64, seed), 0755); err != nil { if err := os.WriteFile(filepath.Join(root, "file-a"), randomContent(64, seed), 0755); err != nil {
return err return err
} }
if err := os.MkdirAll(filepath.Join(string(root), "dir-b"), 0755); err != nil { if err := os.MkdirAll(filepath.Join(root, "dir-b"), 0755); err != nil {
return err return err
} }
if err := os.WriteFile(filepath.Join(string(root), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { if err := os.WriteFile(filepath.Join(root, "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
return err return err
} }
return os.WriteFile(filepath.Join(string(root), "file-c"), randomContent(128*128, seed+2), 0755) return os.WriteFile(filepath.Join(root, "file-c"), randomContent(128*128, seed+2), 0755)
} }
func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error { 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) defer drv.Put(layer)
fileContent, err := os.ReadFile(filepath.Join(string(root), filename)) fileContent, err := os.ReadFile(filepath.Join(root, filename))
if err != nil { if err != nil {
return err return err
} }
@ -75,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
} }
defer drv.Put(layer) defer drv.Put(layer)
return os.WriteFile(filepath.Join(string(root), filename), content, 0755) return os.WriteFile(filepath.Join(root, filename), content, 0755)
} }
func addDirectory(drv graphdriver.Driver, layer, dir string) error { 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) defer drv.Put(layer)
return os.MkdirAll(filepath.Join(string(root), dir), 0755) return os.MkdirAll(filepath.Join(root, dir), 0755)
} }
func removeAll(drv graphdriver.Driver, layer string, names ...string) error { 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) defer drv.Put(layer)
for _, filename := range names { for _, filename := range names {
if err := os.RemoveAll(filepath.Join(string(root), filename)); err != nil { if err := os.RemoveAll(filepath.Join(root, filename)); err != nil {
return err return err
} }
} }
@ -110,8 +110,8 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
} }
defer drv.Put(layer) defer drv.Put(layer)
if _, err := os.Stat(filepath.Join(string(root), filename)); err == nil { if _, err := os.Stat(filepath.Join(root, filename)); err == nil {
return fmt.Errorf("file still exists: %s", filepath.Join(string(root), filename)) return fmt.Errorf("file still exists: %s", filepath.Join(root, filename))
} else if !os.IsNotExist(err) { } else if !os.IsNotExist(err) {
return err return err
} }
@ -127,7 +127,7 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e
defer drv.Put(layer) defer drv.Put(layer)
for i := 0; i < count; i += 100 { for i := 0; i < count; i += 100 {
dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i)) dir := filepath.Join(root, fmt.Sprintf("directory-%d", i))
if err := os.MkdirAll(dir, 0755); err != nil { if err := os.MkdirAll(dir, 0755); err != nil {
return err return err
} }
@ -152,7 +152,7 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
var changes []archive.Change var changes []archive.Change
for i := 0; i < count; i += 100 { for i := 0; i < count; i += 100 {
archiveRoot := fmt.Sprintf("/directory-%d", i) archiveRoot := fmt.Sprintf("/directory-%d", i)
if err := os.MkdirAll(filepath.Join(string(root), archiveRoot), 0755); err != nil { if err := os.MkdirAll(filepath.Join(root, archiveRoot), 0755); err != nil {
return nil, err return nil, err
} }
for j := 0; i+j < count && j < 100; j++ { 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: case 0:
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
change.Kind = archive.ChangeModify change.Kind = archive.ChangeModify
if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { if err := os.WriteFile(filepath.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
return nil, err return nil, err
} }
// Add file // Add file
case 1: case 1:
change.Path = filepath.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 change.Kind = archive.ChangeAdd
if err := os.WriteFile(filepath.Join(string(root), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { if err := os.WriteFile(filepath.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
return nil, err return nil, err
} }
// Remove file // Remove file
case 2: case 2:
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
change.Kind = archive.ChangeDelete change.Kind = archive.ChangeDelete
if err := os.Remove(filepath.Join(string(root), change.Path)); err != nil { if err := os.Remove(filepath.Join(root, change.Path)); err != nil {
return nil, err return nil, err
} }
} }
@ -201,7 +201,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64)
defer drv.Put(layer) defer drv.Put(layer)
for i := 0; i < count; i += 100 { for i := 0; i < count; i += 100 {
dir := filepath.Join(string(root), fmt.Sprintf("directory-%d", i)) dir := filepath.Join(root, fmt.Sprintf("directory-%d", i))
for j := 0; i+j < count && j < 100; j++ { for j := 0; i+j < count && j < 100; j++ {
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j)) file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
fileContent, err := os.ReadFile(file) fileContent, err := os.ReadFile(file)
@ -254,10 +254,10 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
} }
defer drv.Put(layer) defer drv.Put(layer)
if err := os.WriteFile(filepath.Join(string(root), "top-id"), []byte(layer), 0755); err != nil { if err := os.WriteFile(filepath.Join(root, "top-id"), []byte(layer), 0755); err != nil {
return err return err
} }
layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i)) layerDir := filepath.Join(root, fmt.Sprintf("layer-%d", i))
if err := os.MkdirAll(layerDir, 0755); err != nil { if err := os.MkdirAll(layerDir, 0755); err != nil {
return err return err
} }
@ -291,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
} }
defer drv.Put(layer) defer drv.Put(layer)
layerIDBytes, err := os.ReadFile(filepath.Join(string(root), "top-id")) layerIDBytes, err := os.ReadFile(filepath.Join(root, "top-id"))
if err != nil { if err != nil {
return err return err
} }
@ -301,7 +301,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
} }
for i := count; i > 0; i-- { for i := count; i > 0; i-- {
layerDir := filepath.Join(string(root), fmt.Sprintf("layer-%d", i)) layerDir := filepath.Join(root, fmt.Sprintf("layer-%d", i))
thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id")) thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id"))
if err != nil { if err != nil {

View file

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

View file

@ -349,12 +349,12 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro
// If id has a root, just return it // If id has a root, just return it
rootDir := path.Join(dir, "root") rootDir := path.Join(dir, "root")
if _, err := os.Stat(rootDir); err == nil { if _, err := os.Stat(rootDir); err == nil {
return containerfs.NewLocalContainerFS(rootDir), nil return rootDir, nil
} }
mergedDir := path.Join(dir, "merged") mergedDir := path.Join(dir, "merged")
if count := d.ctr.Increment(mergedDir); count > 1 { if count := d.ctr.Increment(mergedDir); count > 1 {
return containerfs.NewLocalContainerFS(mergedDir), nil return mergedDir, nil
} }
defer func() { defer func() {
if err != nil { if err != nil {
@ -391,7 +391,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err erro
if err := root.Chown(path.Join(workDir, "work")); err != nil { if err := root.Chown(path.Join(workDir, "work")); err != nil {
return "", err return "", err
} }
return containerfs.NewLocalContainerFS(mergedDir), nil return mergedDir, nil
} }
// Put unmounts the mount path created for the give id. // Put unmounts the mount path created for the give id.

View file

@ -526,14 +526,14 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if err != nil { if err != nil {
// If no lower, just return diff directory // If no lower, just return diff directory
if os.IsNotExist(err) { if os.IsNotExist(err) {
return containerfs.NewLocalContainerFS(diffDir), nil return diffDir, nil
} }
return "", err return "", err
} }
mergedDir := path.Join(dir, mergedDirName) mergedDir := path.Join(dir, mergedDirName)
if count := d.ctr.Increment(mergedDir); count > 1 { if count := d.ctr.Increment(mergedDir); count > 1 {
return containerfs.NewLocalContainerFS(mergedDir), nil return mergedDir, nil
} }
defer func() { defer func() {
if retErr != nil { if retErr != nil {
@ -613,7 +613,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
} }
} }
return containerfs.NewLocalContainerFS(mergedDir), nil return mergedDir, nil
} }
// Put unmounts the mount path created for the give id. // Put unmounts the mount path created for the give id.

View file

@ -141,7 +141,7 @@ func (d *graphDriverProxy) Get(id, mountLabel string) (containerfs.ContainerFS,
if ret.Err != "" { if ret.Err != "" {
err = errors.New(ret.Err) err = errors.New(ret.Err)
} }
return containerfs.NewLocalContainerFS(d.p.ScopedPath(ret.Dir)), err return d.p.ScopedPath(ret.Dir), err
} }
func (d *graphDriverProxy) Put(id string) error { func (d *graphDriverProxy) Put(id string) error {

View file

@ -172,7 +172,7 @@ func (d *Driver) create(id, parent string, size uint64) error {
if err != nil { if err != nil {
return fmt.Errorf("%s: %s", parent, err) return fmt.Errorf("%s: %s", parent, err)
} }
return CopyDir(string(parentDir), dir) return CopyDir(parentDir, dir)
} }
func (d *Driver) dir(id string) string { func (d *Driver) dir(id string) string {
@ -192,7 +192,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
} else if !st.IsDir() { } else if !st.IsDir() {
return "", fmt.Errorf("%s: not a directory", dir) return "", fmt.Errorf("%s: not a directory", dir)
} }
return containerfs.NewLocalContainerFS(dir), nil return dir, nil
} }
// Put is a noop for vfs that return nil for the error, since this driver has no runtime resources to clean up. // Put is a noop for vfs that return nil for the error, since this driver has no runtime resources to clean up.

View file

@ -402,7 +402,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
return "", err return "", err
} }
if count := d.ctr.Increment(rID); count > 1 { if count := d.ctr.Increment(rID); count > 1 {
return containerfs.NewLocalContainerFS(d.cache[rID]), nil return d.cache[rID], nil
} }
// Getting the layer paths must be done outside of the lock. // Getting the layer paths must be done outside of the lock.
@ -447,7 +447,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
dir = d.dir(id) dir = d.dir(id)
} }
return containerfs.NewLocalContainerFS(dir), nil return dir, nil
} }
// Put adds a new layer to the driver. // Put adds a new layer to the driver.
@ -651,7 +651,7 @@ func (d *Driver) DiffSize(id, parent string) (size int64, err error) {
} }
defer d.Put(id) defer d.Put(id)
return archive.ChangesSize(string(layerFs), changes), nil return archive.ChangesSize(layerFs, changes), nil
} }
// GetMetadata returns custom driver information. // GetMetadata returns custom driver information.

View file

@ -368,7 +368,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
defer d.locker.Unlock(id) defer d.locker.Unlock(id)
mountpoint := d.mountPath(id) mountpoint := d.mountPath(id)
if count := d.ctr.Increment(mountpoint); count > 1 { if count := d.ctr.Increment(mountpoint); count > 1 {
return containerfs.NewLocalContainerFS(mountpoint), nil return mountpoint, nil
} }
defer func() { defer func() {
if retErr != nil { if retErr != nil {
@ -404,7 +404,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
return "", 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 return mountpoint, nil
} }
// Put removes the existing mountpoint for the given id if it exists. // Put removes the existing mountpoint for the given id if it exists.

View file

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

View file

@ -9,7 +9,7 @@ import (
// excludeByIsolation is a platform specific helper function to support PS // excludeByIsolation is a platform specific helper function to support PS
// filtering by Isolation. This is a Windows-only concept, so is a no-op on Unix. // filtering by Isolation. This is a Windows-only concept, so is a no-op on Unix.
func excludeByIsolation(container *container.Snapshot, ctx *listContext) iterationAction { func excludeByIsolation(container *container.Snapshot, ctx *listContext) iterationAction {
i := strings.ToLower(string(container.HostConfig.Isolation)) i := strings.ToLower(container.HostConfig.Isolation)
if i == "" { if i == "" {
i = "default" i = "default"
} }

View file

@ -730,7 +730,7 @@ func WithCommonOptions(daemon *Daemon, c *container.Container) coci.SpecOpts {
} }
if !daemon.UsesSnapshotter() { if !daemon.UsesSnapshotter() {
s.Root = &specs.Root{ s.Root = &specs.Root{
Path: string(c.BaseFS), Path: c.BaseFS,
Readonly: c.HostConfig.ReadonlyRootfs, Readonly: c.HostConfig.ReadonlyRootfs,
} }
} }

View file

@ -10,7 +10,6 @@ import (
"github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/config"
"github.com/docker/docker/daemon/network" "github.com/docker/docker/daemon/network"
"github.com/docker/docker/libnetwork" "github.com/docker/docker/libnetwork"
"github.com/docker/docker/pkg/containerfs"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip" "gotest.tools/v3/skip"
@ -36,7 +35,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon {
} }
c.Root = root c.Root = root
c.BaseFS = containerfs.NewLocalContainerFS(rootfs) c.BaseFS = rootfs
if c.Config == nil { if c.Config == nil {
c.Config = new(containertypes.Config) c.Config = new(containertypes.Config)

View file

@ -240,7 +240,7 @@ func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.S
return errors.New("createSpecWindowsFields: BaseFS of container " + c.ID + " is unexpectedly empty") return errors.New("createSpecWindowsFields: BaseFS of container " + c.ID + " is unexpectedly empty")
} }
s.Root.Path = string(c.BaseFS) // This is not set for Hyper-V containers s.Root.Path = c.BaseFS // This is not set for Hyper-V containers
if !strings.HasSuffix(s.Root.Path, `\`) { if !strings.HasSuffix(s.Root.Path, `\`) {
s.Root.Path = s.Root.Path + `\` // Ensure a correctly formatted volume GUID path \\?\Volume{GUID}\ s.Root.Path = s.Root.Path + `\` // Ensure a correctly formatted volume GUID path \\?\Volume{GUID}\
} }

View file

@ -219,7 +219,7 @@ func setupPlugin(t *testing.T, ec map[string]*graphEventsCounter, ext string, mu
respond(w, err) respond(w, err)
return return
} }
respond(w, &graphDriverResponse{Dir: string(dir)}) respond(w, &graphDriverResponse{Dir: dir})
}) })
mux.HandleFunc("/GraphDriver.Put", func(w http.ResponseWriter, r *http.Request) { 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 { if err != nil {
return nil, err return nil, err
} }
return &fileGetPutter{storage.NewPathFileGetter(string(p)), n.Driver, id}, nil return &fileGetPutter{storage.NewPathFileGetter(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 { func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
fullPath := filepath.Join(string(root), tf.name) fullPath := filepath.Join(root, tf.name)
if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil {
return err return err
} }
@ -267,7 +267,7 @@ func TestMountAndRegister(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
b, err := os.ReadFile(filepath.Join(string(path2), "testfile.txt")) b, err := os.ReadFile(filepath.Join(path2, "testfile.txt"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -375,7 +375,7 @@ func TestStoreRestore(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err := os.WriteFile(filepath.Join(string(pathFS), "testfile.txt"), []byte("nothing here"), 0644); err != nil { if err := os.WriteFile(filepath.Join(pathFS, "testfile.txt"), []byte("nothing here"), 0644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -409,20 +409,20 @@ func TestStoreRestore(t *testing.T) {
if mountPath, err := m2.Mount(""); err != nil { if mountPath, err := m2.Mount(""); err != nil {
t.Fatal(err) t.Fatal(err)
} else if string(pathFS) != string(mountPath) { } else if pathFS != mountPath {
t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS)) t.Fatalf("Unexpected path %s, expected %s", mountPath, pathFS)
} }
if mountPath, err := m2.Mount(""); err != nil { if mountPath, err := m2.Mount(""); err != nil {
t.Fatal(err) t.Fatal(err)
} else if string(pathFS) != string(mountPath) { } else if pathFS != mountPath {
t.Fatalf("Unexpected path %s, expected %s", string(mountPath), string(pathFS)) t.Fatalf("Unexpected path %s, expected %s", mountPath, pathFS)
} }
if err := m2.Unmount(); err != nil { if err := m2.Unmount(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
b, err := os.ReadFile(filepath.Join(string(pathFS), "testfile.txt")) b, err := os.ReadFile(filepath.Join(pathFS, "testfile.txt"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -597,7 +597,7 @@ func tarFromFiles(files ...FileApplier) ([]byte, error) {
defer os.RemoveAll(td) defer os.RemoveAll(td)
for _, f := range files { for _, f := range files {
if err := f.ApplyFile(containerfs.NewLocalContainerFS(td)); err != nil { if err := f.ApplyFile(td); err != nil {
return nil, err return nil, err
} }
} }

View file

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

View file

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

View file

@ -186,7 +186,7 @@ func (aSpace *addrSpace) UnmarshalJSON(data []byte) error {
aSpace.scope = datastore.LocalScope aSpace.scope = datastore.LocalScope
s := m["Scope"].(string) s := m["Scope"].(string)
if s == string(datastore.GlobalScope) { if s == datastore.GlobalScope {
aSpace.scope = datastore.GlobalScope aSpace.scope = datastore.GlobalScope
} }

View file

@ -7,13 +7,7 @@ import (
) )
// ContainerFS is that represents a root file system // ContainerFS is that represents a root file system
type ContainerFS 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 ContainerFS(path)
}
// ResolveScopedPath evaluates the given path scoped to the root. // ResolveScopedPath evaluates the given path scoped to the root.
// For example, if root=/a, and path=/b/c, then this function would return /a/b/c. // For example, if root=/a, and path=/b/c, then this function would return /a/b/c.

View file

@ -12,7 +12,6 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/daemon/initlayer" "github.com/docker/docker/daemon/initlayer"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/plugins"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
@ -55,7 +54,7 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error {
} }
} }
rootFS := containerfs.NewLocalContainerFS(filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName)) rootFS := filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName)
if err := initlayer.Setup(rootFS, idtools.Identity{UID: 0, GID: 0}); err != nil { if err := initlayer.Setup(rootFS, idtools.Identity{UID: 0, GID: 0}); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }