fsutil

package
v0.0.0-...-5f60744 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilePermUserExe  = 0100
	FilePermGroupExe = 0010
	FilePermOtherExe = 0001
)

File permission bits (execute bits only)

View Source
const (
	FMSticky = 01000
	FMSetgid = 02000
	FMSetuid = 04000
)

Native FileModes for extra flags

View Source
const (
	BitSticky = 1
	BitSetgid = 2
	BitSetuid = 4
)

Native FileMode bits for extra flags

View Source
const FMSpecialBits = os.ModeSticky | os.ModeSetgid | os.ModeSetuid

Native FileMode special bits mask

Variables

View Source
var (
	ErrNoFileData                = errors.New("no file data")
	ErrNoSrcDir                  = errors.New("no source directory path")
	ErrNoDstDir                  = errors.New("no destination directory path")
	ErrSameDir                   = errors.New("source and destination directories are the same")
	ErrSrcDirNotExist            = errors.New("source directory doesn't exist")
	ErrSrcNotDir                 = errors.New("source is not a directory")
	ErrSrcNotRegularFile         = errors.New("source is not a regular file")
	ErrUnsupportedFileObjectType = errors.New("unsupported file object type")
)

Directory and file related errors

Functions

func AppendToFile

func AppendToFile(target string, data []byte, preserveTimes bool) error

AppendToFile appends the provided data to the target file

func ArchiveDir

func ArchiveDir(afname string,
	d2aname string,
	trimPrefix string,
	addPrefix string) error

func ArchiveFiles

func ArchiveFiles(afname string,
	files []string,
	removePath bool,
	addPrefix string) error

func CopyAndObfuscateFile

func CopyAndObfuscateFile(
	clone bool,
	src string,
	dst string,
	makeDir bool) error

CopyAndObfuscateFile copies a regular file and performs basic file reference obfuscation

func CopyDir

func CopyDir(clone bool,
	src string,
	dst string,
	copyRelPath bool,
	skipErrors bool,
	excludePatterns []string,
	ignoreDirNames map[string]struct{},
	ignoreFileNames map[string]struct{}) (error, []error)

CopyDir copies a directory

func CopyDirOnly

func CopyDirOnly(clone bool, src, dst string) error

CopyDirOnly copies a directory without any files

func CopyFile

func CopyFile(clone bool, src, dst string, makeDir bool) error

CopyFile copies the source file system object to the desired destination

func CopyRegularFile

func CopyRegularFile(clone bool, src, dst string, makeDir bool) error

CopyRegularFile copies a regular file

func CopySymlinkFile

func CopySymlinkFile(clone bool, src, dst string, makeDir bool) error

CopySymlinkFile copies a symlink file

func DirExists

func DirExists(target string) bool

DirExists returns true if the target exists and it's a directory

func ExeDir

func ExeDir() string

ExeDir returns the directory information for the application

func Exists

func Exists(target string) bool

Exists returns true if the target file system object exists

func FileDir

func FileDir(fileName string) string

FileDir returns the directory information for the given file

func FileModeExtraBitUnix2Go

func FileModeExtraBitUnix2Go(bit uint32) os.FileMode

FileModeExtraBitUnix2Go converts the standard unix filemode bit for the extra flags to the filemode in Go

func FileModeExtraBitsUnix2Go

func FileModeExtraBitsUnix2Go(bits uint32) os.FileMode

FileModeExtraBitsUnix2Go converts the standard unix filemode bits for the extra flags to the filemode flags in Go

func FileModeExtraUnix2Go

func FileModeExtraUnix2Go(mode uint32) os.FileMode

FileModeExtraUnix2Go converts the standard unix filemode for the extra flags to the Go version

func FileModeIsSetgid

func FileModeIsSetgid(mode os.FileMode) bool

FileModeIsSetgid checks if FileMode has the setgid bit set

func FileModeIsSetuid

func FileModeIsSetuid(mode os.FileMode) bool

FileModeIsSetuid checks if FileMode has the setuid bit set

func FileModeIsSticky

func FileModeIsSticky(mode os.FileMode) bool

FileModeIsSticky checks if FileMode has the sticky bit set

func IsDir

func IsDir(target string) bool

IsDir returns true if the target file system object is a directory

func IsRegularFile

func IsRegularFile(target string) bool

IsRegularFile returns true if the target file system object is a regular file

func IsSymlink(target string) bool

IsSymlink returns true if the target file system object is a symlink

func IsTarFile

func IsTarFile(target string) bool

IsTarFile returns true if the target file system object is a tar archive

func LoadStructFromFile

func LoadStructFromFile(filePath string, out interface{}) error

LoadStructFromFile creates a struct from a file

func PrepareImageStateDirs

func PrepareImageStateDirs(statePrefix, imageID string) (string, string, string, string)

PrepareImageStateDirs ensures that the required application directories exist

func PreparePostUpdateStateDir

func PreparePostUpdateStateDir(statePrefix string)

PreparePostUpdateStateDir ensures that the updated sensor is copied to the state directory if necessary

func PrepareReleaseStateDirs

func PrepareReleaseStateDirs(statePrefix, version string) (string, string)

PrepareReleaseStateDirs ensures that the required app release directories exist

func Remove

func Remove(artifactLocation string) error

Remove removes the artifacts generated during the current application execution

func ReplaceFileData

func ReplaceFileData(target string, replace []ReplaceInfo, preserveTimes bool) error

ReplaceFileData replaces the selected file bytes with the caller provided bytes

func ResolveImageStateBasePath

func ResolveImageStateBasePath(statePrefix string) string

ResolveImageStateBasePath resolves the base path for the state path

func SetAccess

func SetAccess(dst string, access *AccessInfo) error

SetAccess updates the access permissions on the destination

func Touch

func Touch(target string) error

Touch creates the target file or updates its timestamp

func UpdateFileData

func UpdateFileData(target string, updater DataUpdaterFn, preserveTimes bool) error

UpdateFileData updates all file data in target file using the updater function

func UpdateFileTimes

func UpdateFileTimes(target string, atime, mtime syscall.Timespec) error

UpdateFileTimes updates the atime and mtime timestamps on the target file

func UpdateSymlinkTimes

func UpdateSymlinkTimes(target string, atime, mtime syscall.Timespec) error

UpdateSymlinkTimes updates the atime and mtime timestamps on the target symlink

Types

type AccessInfo

type AccessInfo struct {
	Flags     os.FileMode
	PermsOnly bool
	UID       int
	GID       int
}

AccessInfo provides the file object access properties

func NewAccessInfo

func NewAccessInfo() *AccessInfo

type DataUpdaterFn

type DataUpdaterFn func(target string, data []byte) ([]byte, error)

type ReplaceInfo

type ReplaceInfo struct {
	PathSuffix   string
	IsMatchRegex string
	Match        string
	Replace      string
}

type SysStat

type SysStat struct {
	Ok    bool
	Uid   uint32
	Gid   uint32
	Atime syscall.Timespec
	Mtime syscall.Timespec
	Ctime syscall.Timespec
}

func SysStatInfo

func SysStatInfo(raw *syscall.Stat_t) SysStat

Jump to

Keyboard shortcuts

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