Merge pull request #7523 from ginglis13/symlink-device

add option to resolve symlinks in WithLinuxDevice
This commit is contained in:
Kazuyoshi Kato
2022-11-14 16:32:46 -08:00
committed by GitHub
2 changed files with 94 additions and 0 deletions

View File

@@ -1307,12 +1307,28 @@ func WithLinuxDevices(devices []specs.LinuxDevice) SpecOpts {
}
}
func WithLinuxDeviceFollowSymlinks(path, permissions string) SpecOpts {
return withLinuxDevice(path, permissions, true)
}
// WithLinuxDevice adds the device specified by path to the spec
func WithLinuxDevice(path, permissions string) SpecOpts {
return withLinuxDevice(path, permissions, false)
}
func withLinuxDevice(path, permissions string, followSymlinks bool) SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
setLinux(s)
setResources(s)
if followSymlinks {
resolvedPath, err := filepath.EvalSymlinks(path)
if err != nil {
return err
}
path = resolvedPath
}
dev, err := DeviceFromPath(path)
if err != nil {
return err