sysutil

package
v0.0.0-...-18b16e6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGetUserFailed indicates the system call for fetching user entry from passwd has failed
	ErrGetUserFailed = fmt.Errorf("failed to get user")
	// ErrUserNotFound indicates the user does not exist in the system
	ErrUserNotFound = fmt.Errorf("user not found")
	// ErrMakeDirFailed indicates the system call for making a directory has failed
	ErrMakeDirFailed = fmt.Errorf("failed to make directory")
	// ErrCreateFileFailed indicates the error of failing to create a file
	ErrCreateFileFailed = fmt.Errorf("failed to create file")
	// ErrRunCmdFailed is returned when a command is failed to run
	ErrRunCmdFailed = fmt.Errorf("failed to run command")
)

Possible errors

Functions

This section is empty.

Types

type CmdResult

type CmdResult struct {
	ExitCode int
	StdOut   string
	StdErr   string
}

CmdResult struct contains the result of executing a command

type SysManager

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

SysManager is the tool for interacting with the OS

func NewSysManager

func NewSysManager() *SysManager

NewSysManager returns a new SysManager Object

func (*SysManager) CopyFileAttribute

func (s *SysManager) CopyFileAttribute(from, to string) error

CopyFileAttribute copies a file's attribute to another In Linux, this is specifically designed to apply the selinux labels of a file to another

func (*SysManager) CreateFileForWrite

func (s *SysManager) CreateFileForWrite(file string, user *User, perm os.FileMode) (io.WriteCloser, error)

CreateFileForWrite creates a file for write

func (*SysManager) FileExists

func (s *SysManager) FileExists(name string) (bool, error)

FileExists checks whether a file exists or not

func (*SysManager) GetUserByName

func (s *SysManager) GetUserByName(username string) (*User, error)

GetUserByName gets an OS user info

func (*SysManager) MkDirIfNonExist

func (s *SysManager) MkDirIfNonExist(dir string, user *User, perm os.FileMode) error

MkDirIfNonExist creates a directory if it does not exist

func (*SysManager) ReadFile

func (s *SysManager) ReadFile(filename string) ([]byte, error)

ReadFile reads a file

func (*SysManager) RemoveFile

func (s *SysManager) RemoveFile(name string) error

RemoveFile removes a file

func (*SysManager) RenameFile

func (s *SysManager) RenameFile(oldpath, newpath string) error

RenameFile renames a file

func (*SysManager) RunCmd

func (s *SysManager) RunCmd(name string, arg ...string) (*CmdResult, error)

RunCmd runs a command and return the result

func (*SysManager) Sleep

func (s *SysManager) Sleep(d time.Duration)

type User

type User struct {
	Name    string
	UID     int
	GID     int
	HomeDir string
	Shell   string
}

User struct contains information of a user

Jump to

Keyboard shortcuts

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