system

package
v1.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 18 Imported by: 30

Documentation

Index

Constants

View Source
const (
	// Value is larger than the maximum size allowed
	E2BIG unix.Errno = unix.E2BIG

	// Operation not supported
	EOPNOTSUPP unix.Errno = unix.EOPNOTSUPP
)

Variables

View Source
var (
	// ErrNotSupportedPlatform means the platform is not supported.
	ErrNotSupportedPlatform = errors.New("platform and architecture is not supported")
)

Functions

func CheckSystemDriveAndRemoveDriveLetter

func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error)

CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter, is the system drive. This is a no-op on Linux.

func Chmod added in v0.46.1

func Chmod(name string, mode os.FileMode) error

func Chtimes

func Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access time and modified time of a file at the given path

func CommandLineToArgv

func CommandLineToArgv(commandLine string) ([]string, error)

CommandLineToArgv should not be used on Unix. It simply returns commandLine in the only element in the returned array.

func DefaultPathEnv

func DefaultPathEnv(platform string) string

DefaultPathEnv is unix style list of directories to search for executables. Each directory is separated from the next by a colon ':' character .

func EnsureRemoveAll

func EnsureRemoveAll(dir string) error

EnsureRemoveAll wraps `os.RemoveAll` to check for specific errors that can often be remedied. Only use `EnsureRemoveAll` if you really want to make every effort to remove a directory.

Because of the way `os.Remove` (and by extension `os.RemoveAll`) works, there can be a race between reading directory entries and then actually attempting to remove everything in the directory. These types of errors do not need to be returned since it's ok for the dir to be gone we can just retry the remove operation.

This should not return a `os.ErrNotExist` kind of error under any circumstances

func GetExitCode

func GetExitCode(err error) (int, error)

GetExitCode returns the ExitStatus of the specified error if its type is exec.ExitError, returns 0 and an error otherwise.

func IsProcessAlive

func IsProcessAlive(pid int) bool

IsProcessAlive returns true if process with a given pid is running.

func KillProcess

func KillProcess(pid int)

KillProcess force-stops a process.

func LCOWSupported

func LCOWSupported() bool

LCOWSupported returns true if Linux containers on Windows are supported.

func LUtimesNano

func LUtimesNano(path string, ts []syscall.Timespec) error

LUtimesNano is used to change access and modification time of the specified path. It's used for symbol link file because unix.UtimesNano doesn't support a NOFOLLOW flag atm.

func Lchown added in v0.46.1

func Lchown(name string, uid, gid int) error

func Lgetxattr

func Lgetxattr(path string, attr string) ([]byte, error)

Lgetxattr retrieves the value of the extended attribute identified by attr and associated with the given path in the file system. Returns a []byte slice if the xattr is set and nil otherwise.

func Llistxattr

func Llistxattr(path string) ([]string, error)

Llistxattr lists extended attributes associated with the given path in the file system.

func Lsetxattr

func Lsetxattr(path string, attr string, data []byte, flags int) error

Lsetxattr sets the value of the extended attribute identified by attr and associated with the given path in the file system.

func Mkdev

func Mkdev(major int64, minor int64) uint32

Mkdev is used to build the value of linux devices (in /dev/) which specifies major and minor number of the newly created device special file. Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes. They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major, then the top 12 bits of the minor.

func Mknod

func Mknod(path string, mode uint32, dev int) error

Mknod creates a filesystem node (file, device special file or named pipe) named path with attributes specified by mode and dev.

func ProcessExitCode

func ProcessExitCode(err error) (exitCode int)

ProcessExitCode process the specified error and returns the exit status code if the error was of type exec.ExitError, returns nothing otherwise.

func Umask

func Umask(newmask int) (oldmask int, err error)

Umask sets current process's file mode creation mask to newmask and returns oldmask.

func Unmount

func Unmount(dest string) error

Unmount is a platform-specific helper function to call the unmount syscall.

Types

type MemInfo

type MemInfo struct {
	// Total usable RAM (i.e. physical RAM minus a few reserved bits and the
	// kernel binary code).
	MemTotal int64

	// Amount of free memory.
	MemFree int64

	// Total amount of swap space available.
	SwapTotal int64

	// Amount of swap space that is currently unused.
	SwapFree int64
}

MemInfo contains memory statistics of the host system.

func ReadMemInfo

func ReadMemInfo() (*MemInfo, error)

ReadMemInfo retrieves memory statistics of the host system and returns a MemInfo type.

type StatT

type StatT struct {
	// contains filtered or unexported fields
}

StatT type contains status of a file. It contains metadata like permission, owner, group, size, etc about a file.

func FromStatT

func FromStatT(s *syscall.Stat_t) (*StatT, error)

FromStatT converts a syscall.Stat_t type to a system.Stat_t type This is exposed on Linux as pkg/archive/changes uses it.

func Fstat

func Fstat(fd int) (*StatT, error)

Fstat takes an open file descriptor and returns a system.StatT type pertaining to that file.

Throws an error if the file descriptor is invalid

func Lstat

func Lstat(path string) (*StatT, error)

Lstat takes a path to a file and returns a system.StatT type pertaining to that file.

Throws an error if the file does not exist

func Stat

func Stat(path string) (*StatT, error)

Stat takes a path to a file and returns a system.StatT type pertaining to that file.

Throws an error if the file does not exist

func (StatT) GID

func (s StatT) GID() uint32

GID returns file's group id of owner.

func (StatT) Mode

func (s StatT) Mode() uint32

Mode returns file's permission mode.

func (StatT) Mtim

func (s StatT) Mtim() syscall.Timespec

Mtim returns file's last modification time.

func (StatT) Rdev

func (s StatT) Rdev() uint64

Rdev returns file's device ID (if it's special file).

func (StatT) Size

func (s StatT) Size() int64

Size returns file's size.

func (StatT) UID

func (s StatT) UID() uint32

UID returns file's user id of owner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL