system

package
v0.0.392 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: Apache-2.0 Imports: 18 Imported by: 2,809

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateNetworkAndBroadcast

func CalculateNetworkAndBroadcast(ipAddress, netmask string) (string, string, int, error)

func NewExecProcess

func NewExecProcess(cmd *exec.Cmd, keepAttached bool, quiet bool, logger boshlog.Logger) *execProcess

Types

type CmdRunner

type CmdRunner interface {
	// RunComplexCommand returns error as nil:
	//  - command runs and exits with a zero exit status
	// RunComplexCommand returns error:
	//  - command runs and exits with a non-zero exit status
	//  - command does not run
	RunComplexCommand(cmd Command) (stdout, stderr string, exitStatus int, err error)

	RunComplexCommandAsync(cmd Command) (Process, error)

	RunCommand(cmdName string, args ...string) (stdout, stderr string, exitStatus int, err error)

	RunCommandQuietly(cmdName string, args ...string) (stdout, stderr string, exitStatus int, err error)

	RunCommandWithInput(input, cmdName string, args ...string) (stdout, stderr string, exitStatus int, err error)

	CommandExists(cmdName string) (exists bool)
}

func NewExecCmdRunner

func NewExecCmdRunner(logger boshlog.Logger) CmdRunner

type Command

type Command struct {
	Name           string
	Args           []string
	Env            map[string]string
	UseIsolatedEnv bool

	WorkingDir string

	// On Linux when enabled inherits process group
	KeepAttached bool

	// Don't echo stdout/stderr
	Quiet bool

	Stdin io.Reader

	// Full stdout and stderr will be captured to memory
	// and returned in the Result unless custom Stdout/Stderr are specified.
	Stdout io.Writer
	Stderr io.Writer
}

type ConvergeFileContentsOpts

type ConvergeFileContentsOpts struct {
	DryRun bool
}

type ExecError

type ExecError struct {
	Command string
	StdOut  string
	StdErr  string
}

func NewExecError

func NewExecError(cmd, stdout, stderr string) ExecError

func (ExecError) Error

func (e ExecError) Error() string

func (ExecError) ShortError

func (e ExecError) ShortError() string

ShortError returns an error message that has stdout/stderr truncated.

type File

type File interface {
	io.ReadWriteCloser
	ReadAt([]byte, int64) (int, error)
	WriteAt([]byte, int64) (int, error)
	Seek(int64, int) (int64, error)
	Stat() (os.FileInfo, error)
	Name() string
}

File is a subset of os.File

type FileSystem

type FileSystem interface {
	HomeDir(username string) (path string, err error)
	ExpandPath(path string) (expandedPath string, err error)

	// MkdirAll will not change existing dir permissions
	// if dir exists and has different permissions
	MkdirAll(path string, perm os.FileMode) error
	RemoveAll(fileOrDir string) error

	Chown(path, username string) error
	Chmod(path string, perm os.FileMode) error

	OpenFile(path string, flag int, perm os.FileMode) (File, error)

	WriteFileString(path, content string) error
	WriteFile(path string, content []byte) error
	WriteFileQuietly(path string, content []byte) error
	ConvergeFileContents(path string, content []byte, opts ...ConvergeFileContentsOpts) (written bool, err error)

	ReadFileString(path string) (content string, err error)
	ReadFile(path string) (content []byte, err error)
	ReadFileWithOpts(path string, opts ReadOpts) (content []byte, err error)

	FileExists(path string) bool
	Stat(path string) (os.FileInfo, error)
	StatWithOpts(path string, opts StatOpts) (os.FileInfo, error)
	Lstat(path string) (os.FileInfo, error)

	Rename(oldPath, newPath string) error

	// After Symlink file at newPath will be pointing to file at oldPath.
	// Symlink call will remove file at newPath if one exists
	// to make newPath a symlink to the file at oldPath.
	Symlink(oldPath, newPath string) error

	ReadAndFollowLink(symlinkPath string) (targetPath string, err error)
	Readlink(symlinkPath string) (targetPath string, err error)

	CopyFile(srcPath, dstPath string) error
	CopyDir(srcPath, dstPath string) error

	// Returns *unique* temporary file/dir with a custom prefix
	TempFile(prefix string) (file File, err error)
	TempDir(prefix string) (path string, err error)
	ChangeTempRoot(path string) error

	Glob(pattern string) (matches []string, err error)
	RecursiveGlob(pattern string) (matches []string, err error)
	Walk(root string, walkFunc filepath.WalkFunc) error
}

func NewOsFileSystem

func NewOsFileSystem(logger boshlog.Logger) FileSystem

func NewOsFileSystemWithStrictTempRoot

func NewOsFileSystemWithStrictTempRoot(logger boshlog.Logger) FileSystem

type Process

type Process interface {
	// Wait is the only way to get back process result information.
	// It must not be called multiple times.
	Wait() <-chan Result

	// TerminateNicely can be called multiple times.
	// It must only be called after Wait().
	TerminateNicely(killGracePeriod time.Duration) error
}

type ReadOpts

type ReadOpts struct {
	Quiet bool
}

type Result

type Result struct {
	// Full stdout and stderr are captured to memory
	Stdout string
	Stderr string

	ExitStatus int
	Error      error
}

type StatOpts

type StatOpts struct {
	Quiet bool
}

Directories

Path Synopsis
exec_cmd_runner_fixtures
cat

Jump to

Keyboard shortcuts

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