sysutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sysutil is a cross-platform compatibility layer on top of package syscall. It exposes APIs for common operations that require package syscall and re-exports several symbols from package syscall that are known to be safe. Using package syscall directly from other packages is forbidden.

Index

Constants

View Source
const (
	ECONNRESET   = syscall.ECONNRESET
	ECONNREFUSED = syscall.ECONNREFUSED
)

Exported syscall.Errno constants.

Variables

This section is empty.

Functions

func ExceedsPermissions

func ExceedsPermissions(objectMode, allowedMode os.FileMode) bool

ExceedsPermissions returns true if the passed os.FileMode represents a more stringent set of permissions than the ACLInfo's mode.

For example, calling this function with an objectMode of 0640 will return false if the passed allowedMode is 0600.

func ExitStatus

func ExitStatus(err *exec.ExitError) int

ExitStatus returns the exit status contained within an exec.ExitError.

func IsCrossDeviceLinkErrno

func IsCrossDeviceLinkErrno(errno error) bool

IsCrossDeviceLinkErrno checks whether the given error object (as extracted from an *os.LinkError) is a cross-device link/rename error.

func IsErrConnectionRefused

func IsErrConnectionRefused(err error) bool

IsErrConnectionRefused returns true if an error is a "connection refused" error.

func IsErrConnectionReset

func IsErrConnectionReset(err error) bool

IsErrConnectionReset returns true if an error is a "connection reset by peer" error.

func ProcessIdentity

func ProcessIdentity() string

ProcessIdentity returns a string describing the user and group that this process is running as.

func RefreshSignaledChan

func RefreshSignaledChan() <-chan os.Signal

RefreshSignaledChan returns a channel that will receive an os.Signal whenever the process receives a "refresh" signal (currently SIGHUP). A refresh signal indicates that the user wants to apply nondisruptive updates, like reloading certificates and flushing log files.

On Windows, the returned channel will never receive any values, as Windows does not support signals. Consider exposing a refresh trigger through other means if Windows support is important.

func ResizeLargeFile

func ResizeLargeFile(path string, bytes int64) error

ResizeLargeFile resizes the file at the given path to be the provided length in bytes. If no file exists at path, ResizeLargeFile creates a file. All disk blocks within the new file are allocated, and there are no sparse regions.

On Linux, it uses the fallocate syscall to efficiently allocate disk space. On other platforms, it naively writes the specified number of bytes, which can take a long time.

Types

type ACLInfo

type ACLInfo interface {
	// UID returns the ID of the user that owns the file in question.
	UID() uint64
	// GID returns the ID of the group that owns the file in question.
	GID() uint64

	// IsOwnedByUID returns true of the passed UID is equal to the UID of the file in question.
	IsOwnedByUID(uint64) bool
	// IsOwnedByGID returns true of the passed GID is equal to the GID of the file in question.
	IsOwnedByGID(uint64) bool

	// Mode returns the os.FileMode representing the files permissions. Implementers of this
	// interface should return only the result of the `Perm` function in os.FileMode, to
	// ensure that only permissions are returned.
	Mode() os.FileMode
}

ACLInfo represents access control information for a file in the filesystem. It can be used to determine if a file has the correct permissions associated with it.

func GetFileACLInfo

func GetFileACLInfo(info os.FileInfo) ACLInfo

GetFileACLInfo returns an ACLInfo that has the UID and GID populated from the system specific file information.

type Errno

type Errno = syscall.Errno

Errno is syscall.Errno.

type Signal

type Signal = syscall.Signal

Signal is syscall.Signal.

Jump to

Keyboard shortcuts

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