os

package
v1.99.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFileContents

func CopyFileContents(src string, dst string, permission os.FileMode) error

func FileContentMatches added in v1.20.0

func FileContentMatches(path string, expectedContent []byte) error

func FileExists

func FileExists(path string) bool

FileExists returns true if the file at path exists. It returns false if it does not exist, or if there was an error when checking for its existence. This means there can be false negatives if Lstat fails because of permission issues (file exists, but is not reachable by the current user)

func RemoveFileAsRoot

func RemoveFileAsRoot(reason, filepath string) error

func RemoveFileIfExists added in v1.23.0

func RemoveFileIfExists(path string) error

func ReplaceOrAddEnv added in v1.14.0

func ReplaceOrAddEnv(variables []string, varName string, value string) []string

ReplaceOrAddEnv changes the value of an environment variable if it exists otherwise add the new variable It drops the existing value and appends the new value in-place

func RunPrivileged added in v1.23.0

func RunPrivileged(reason string, cmdAndArgs ...string) (string, string, error)

RunPrivileged executes a command using sudo provide a reason why root is needed as the first argument

func RunWithDefaultLocale

func RunWithDefaultLocale(command string, args ...string) (string, string, error)

func RunWithDefaultLocalePrivate

func RunWithDefaultLocalePrivate(command string, args ...string) (string, string, error)

func RunningInTerminal added in v1.23.0

func RunningInTerminal() bool

func RunningUsingSSH added in v1.25.0

func RunningUsingSSH() bool

func WriteFileIfContentChanged

func WriteFileIfContentChanged(path string, newContent []byte, perm os.FileMode) (bool, error)

func WriteToFileAsRoot

func WriteToFileAsRoot(reason, content, filepath string, mode os.FileMode) error

Types

type CodeExitError added in v1.28.0

type CodeExitError struct {
	Err  error
	Code int
}

CodeExitError is an implementation of ExitError consisting of an error object and an exit code (the upper bits of os.exec.ExitStatus).

func (CodeExitError) Error added in v1.28.0

func (e CodeExitError) Error() string

func (CodeExitError) ExitStatus added in v1.28.0

func (e CodeExitError) ExitStatus() int

func (CodeExitError) Exited added in v1.28.0

func (e CodeExitError) Exited() bool

func (CodeExitError) String added in v1.28.0

func (e CodeExitError) String() string

func (CodeExitError) Unwrap added in v1.28.0

func (e CodeExitError) Unwrap() error

type CommandRunner added in v1.16.0

type CommandRunner interface {
	Run(command string, args ...string) (string, string, error)
	RunPrivate(command string, args ...string) (string, string, error)
	RunPrivileged(reason string, cmdAndArgs ...string) (string, string, error)
}

func NewLocalCommandRunner added in v1.16.0

func NewLocalCommandRunner() CommandRunner

type ExitError added in v1.28.0

type ExitError interface {
	String() string
	Error() string
	Exited() bool
	ExitStatus() int
	Unwrap() error
}

ExitError is an interface that presents an API similar to os.ProcessState, which is what ExitError from os/exec is. This is designed to make testing a bit easier and probably loses some of the cross-platform properties of the underlying library.

Directories

Path Synopsis
windows

Jump to

Keyboard shortcuts

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