MCPcopy Create free account
hub / github.com/containers/common / DeviceFromPath

Function DeviceFromPath

pkg/parse/parse_unix.go:14–50  ·  view source on GitHub ↗
(device string)

Source from the content-addressed store, hash-verified

12)
13
14func DeviceFromPath(device string) ([]devices.Device, error) {
15 var devs []devices.Device
16 src, dst, permissions, err := Device(device)
17 if err != nil {
18 return nil, err
19 }
20 if unshare.IsRootless() && src != dst {
21 return nil, errors.Errorf("Renaming device %s to %s is not supported in rootless containers", src, dst)
22 }
23 srcInfo, err := os.Stat(src)
24 if err != nil {
25 return nil, err
26 }
27
28 if !srcInfo.IsDir() {
29
30 dev, err := devices.DeviceFromPath(src, permissions)
31 if err != nil {
32 return nil, errors.Wrapf(err, "%s is not a valid device", src)
33 }
34 dev.Path = dst
35 devs = append(devs, *dev)
36 return devs, nil
37 }
38
39 // If source device is a directory
40 srcDevices, err := devices.GetDevices(src)
41 if err != nil {
42 return nil, errors.Wrapf(err, "error getting source devices from directory %s", src)
43 }
44 for _, d := range srcDevices {
45 d.Path = filepath.Join(dst, filepath.Base(d.Path))
46 d.Permissions = devices.Permissions(permissions)
47 devs = append(devs, *d)
48 }
49 return devs, nil
50}

Callers 1

TestDeviceFromPathFunction · 0.85

Calls 2

DeviceFunction · 0.70
StatMethod · 0.65

Tested by 1

TestDeviceFromPathFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…