mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
56e478046a
Errors from unix.* are always bare and thus can be used directly.
Add //nolint:errorlint annotation to ignore errors such as these:
libcontainer/system/xattrs_linux.go:18:7: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
case errno == unix.ERANGE:
^
libcontainer/container_linux.go:1259:9: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
if e != unix.EINVAL {
^
libcontainer/rootfs_linux.go:919:7: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
if err != unix.EINVAL && err != unix.EPERM {
^
libcontainer/rootfs_linux.go:1002:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint)
switch err {
^
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
37 lines
934 B
Go
37 lines
934 B
Go
package system
|
|
|
|
import "golang.org/x/sys/unix"
|
|
|
|
// Returns a []byte slice if the xattr is set and nil otherwise
|
|
// Requires path and its attribute as arguments
|
|
func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
var sz int
|
|
// Start with a 128 length byte array
|
|
dest := make([]byte, 128)
|
|
sz, errno := unix.Lgetxattr(path, attr, dest)
|
|
|
|
//nolint:errorlint // unix errors are bare
|
|
switch {
|
|
case errno == unix.ENODATA:
|
|
return nil, errno
|
|
case errno == unix.ENOTSUP:
|
|
return nil, errno
|
|
case errno == unix.ERANGE:
|
|
// 128 byte array might just not be good enough,
|
|
// A dummy buffer is used to get the real size
|
|
// of the xattrs on disk
|
|
sz, errno = unix.Lgetxattr(path, attr, []byte{})
|
|
if errno != nil {
|
|
return nil, errno
|
|
}
|
|
dest = make([]byte, sz)
|
|
sz, errno = unix.Lgetxattr(path, attr, dest)
|
|
if errno != nil {
|
|
return nil, errno
|
|
}
|
|
case errno != nil:
|
|
return nil, errno
|
|
}
|
|
return dest[:sz], nil
|
|
}
|