Move resolveSymbolicLink to OS package and stub out for tests
Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
@@ -289,7 +289,7 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint3
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := addOCIDevices(&g, config.GetDevices()); err != nil {
|
||||
if err := c.addOCIDevices(&g, config.GetDevices()); err != nil {
|
||||
return nil, fmt.Errorf("failed to set devices mapping %+v: %v", config.GetDevices(), err)
|
||||
}
|
||||
|
||||
@@ -414,10 +414,10 @@ func clearReadOnly(m *runtimespec.Mount) {
|
||||
}
|
||||
|
||||
// addDevices set device mapping without privilege.
|
||||
func addOCIDevices(g *generate.Generator, devs []*runtime.Device) error {
|
||||
func (c *criContainerdService) addOCIDevices(g *generate.Generator, devs []*runtime.Device) error {
|
||||
spec := g.Spec()
|
||||
for _, device := range devs {
|
||||
path, err := resolveSymbolicLink(device.HostPath)
|
||||
path, err := c.os.ResolveSymbolicLink(device.HostPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -497,7 +497,7 @@ func addOCIBindMounts(g *generate.Generator, mounts []*runtime.Mount, mountLabel
|
||||
}
|
||||
// TODO(random-liu): Add cri-containerd integration test or cri validation test
|
||||
// for this.
|
||||
src, err := resolveSymbolicLink(src)
|
||||
src, err := c.os.ResolveSymbolicLink(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve symlink %q: %v", src, err)
|
||||
}
|
||||
|
||||
@@ -297,19 +297,6 @@ func (c *criContainerdService) ensureImageExists(ctx context.Context, ref string
|
||||
return &newImage, nil
|
||||
}
|
||||
|
||||
// resolveSymbolicLink resolves a possbile symlink path. If the path is a symlink, returns resolved
|
||||
// path; if not, returns the original path.
|
||||
func resolveSymbolicLink(path string) (string, error) {
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if info.Mode()&os.ModeSymlink != os.ModeSymlink {
|
||||
return path, nil
|
||||
}
|
||||
return filepath.EvalSymlinks(path)
|
||||
}
|
||||
|
||||
// loadCgroup loads the cgroup associated with path if it exists and moves the current process into the cgroup. If the cgroup
|
||||
// is not created it is created and returned.
|
||||
func loadCgroup(cgroupPath string) (cgroups.Cgroup, error) {
|
||||
|
||||
Reference in New Issue
Block a user