Documentation ¶
Index ¶
- Constants
- Variables
- func ActivityIndicator(stream io.Writer, description ...string) (stopIndicator func())
- func AnySliceToTypeSlice[T any](anySlice []any) (typeSlice []T)
- func AppendToFile(name string) (*os.File, error)
- func BatchFileExtension() (extension string)
- func BinaryExtension() (extension string)
- func CanonicalizeAndEvaluateSymlinks(path string) (resolvedPath string, err error)
- func Capture(call func()) (output []byte, err error)
- func CaptureWithCGo(call func()) (output []byte, err error)
- func Chdir(workingDirectory string, call func() error) (err error)
- func ChecksumForPath(path string) (digest []byte, err error)
- func ChecksumsSHA256ForFiles(filePath string) (err error)
- func CommandFileExtension() (extension string)
- func CompressDirectory(srcDirectory string, archive string) (err error)
- func CopyFile(src string, dst string) (err error)
- func CopyFileCompressed(src string, dst string, compressionLevel int) (err error)
- func CopyTree(sourcePath string, destinationPath string) (err error)
- func DirExists(filePath string) error
- func DirectoriesRecursive(directoryPath string) (directories []string, err error)
- func DirectoryPermissionOfParent(path string) (permission fs.FileMode, err error)
- func DownloadFile(url string, filePath string) (err error)
- func DownloadFileWithProgress(url string, filePath string) (err error)
- func EnforceProcessTreeLimits(limits ProcessTreeLimits)
- func EnvOrDefault(key string, defaultValue string) (value string)
- func EnvironMap() (environMap map[string]string)
- func EnvironmentPathList() (filePaths []string)
- func ExtractFile(archiveFilePath string, destinationPath string) (err error)
- func FileChange(filePath string, change func(data []byte) (changed []byte, err error)) error
- func FileExists(filePath string) error
- func FileOrSymlinkExists(filepath string) error
- func FilePermissionOfParent(path string) (permission fs.FileMode, err error)
- func FilesRecursive(path string) (files []string, err error)
- func ForEachFile(path string, handle func(filePath string) error) error
- func GreatestCommonDirectory(paths []string) string
- func Info() (info map[string]string, err error)
- func IsArchitectureARMWith32Bit() bool
- func IsArchitectureARMWith64Bit() bool
- func IsArchitectureX86With32Bit() bool
- func IsArchitectureX86With64Bit() bool
- func IsDarwin() bool
- func IsEnvEnabled(key string, additionalEnabledValues ...string) bool
- func IsLinux() bool
- func IsWindows() bool
- func MakeFileCopyTargets(sourceMakefilePath string, destinationMakefilePath string, ...) (err error)
- func MkdirAll(path string) error
- func ProgressBar(stream io.Writer, max int, description ...string) (progress *progressbar.ProgressBar)
- func ProgressBarBytes(stream io.Writer, length int, description ...string) (progress *progressbar.ProgressBar)
- func RemoveFileIfExists(filePath string) error
- func RemoveFromEnvironmentPathBySearchTerm(searchTerms ...string) (newEnvironmentPath string)
- func RemoveTemporaryDirectory(directoryPath string)
- func ReplaceVariablesInFile(filePath string, variables map[string]string) (err error)
- func RequireEnv(key string) (value string, err error)
- func RewriteStaticIndexFile(filePath string) (err error)
- func SetRLimitFiles(limit uint64, call func(limit uint64)) (err error)
- func Stat(filePath string) (os.FileInfo, error)
- func Tar(archiveFilePath string, path string) error
- func TarExtract(stream io.Reader, destinationPath string, compressionType CompressionType) (err error)
- func TarExtractFile(archiveFilePath string, destinationPath string) (err error)
- func TestCapture(t *testing.T)
- func TestCaptureRecursive(t *testing.T)
- func TestCaptureWithCGo(t *testing.T)
- func TestCaptureWithCGoWithHugeOutput(t *testing.T)
- func TestCaptureWithCGoWithPanic(t *testing.T)
- func TestCaptureWithHugeOutput(t *testing.T)
- func TestCaptureWithPanic(t *testing.T)
- func Uncompress(archive io.Reader, dstDirectory string) (err error)
- func ValidateChecksumForPath(path string, checksumFile string) (valid bool, err error)
- func WriteChecksumForPath(path string, checksumFile string) error
- func ZipExtractFile(archiveFilePath string, destinationPath string) (err error)
- type CompressionType
- type FilePathsByHierarchy
- type InMemoryStream
- type ProcessTreeLimits
- type StandardStream
- type StaticFile
Constants ¶
const ( // CompressionTypeNone indicates no compression. CompressionTypeNone = CompressionType("") // CompressionTypeGNUZipped indicates a GNU zipped compression. CompressionTypeGNUZipped = CompressionType("gz") // CompressionTypeXZ indicates a XZ compression. CompressionTypeXZ = CompressionType("xz") )
const ( // KernelVersionIdentifier holds the identifier for the kernel version OS information. KernelVersionIdentifier = "KernelVersion" // OperatingSystemIdentifier holds the identifier for the OS name OS information. OperatingSystemIdentifier = "ProductName" // OperatingSystemVersionIdentifier holds the identifier for the OS version OS information. OperatingSystemVersionIdentifier = "ProductVersion" )
const ( // Darwin holds the value of GOOS on MacOS. Darwin = "darwin" // Linux holds the value of GOOS on Linux. Linux = "linux" // Windows holds the value of GOOS on Windows. Windows = "windows" )
const (
// EnvironmentPathIdentifier holds the environment variable identifier for the "PATH" variable.
EnvironmentPathIdentifier = "PATH"
)
const (
// LineEnding holds the line ending for text files.
LineEnding = "\n"
)
Variables ¶
var ( // ErrNotADirectory indicates that the given directory does not exist. ErrNotADirectory = errors.New("not a directory") // ErrNotAFile indicates thate the given file does not exist. ErrNotAFile = errors.New("not a file") )
var ErrDirectoryNotEmpty = syscall.ENOTEMPTY
ErrDirectoryNotEmpty indicates that a directory is not empty.
var HTTPClient *http.Client = func() *http.Client { c := &http.Client{ Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, ResponseHeaderTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }, Timeout: 0, } c.Jar, _ = cookiejar.New(nil) return c }()
HTTPClient defines an HTTP client with sane default settings.
Functions ¶
func ActivityIndicator ¶
ActivityIndicator prints a spinning activity indicator to the given stream until the indicator is stopped.
func AnySliceToTypeSlice ¶
AnySliceToTypeSlice returns a slice of the designated type with the values from the given "any" slice that match the type.
func AppendToFile ¶
AppendToFile opens the named file. If the file does not exist it is created.
func BatchFileExtension ¶
func BatchFileExtension() (extension string)
BatchFileExtension returns the common file extension of a batch file.
func BinaryExtension ¶
func BinaryExtension() (extension string)
BinaryExtension returns the common file extension of a binary.
func CanonicalizeAndEvaluateSymlinks ¶
CanonicalizeAndEvaluateSymlinks returns the path after canonicalizing it and the evaluation of any symbolic links.
func CaptureWithCGo ¶
CaptureWithCGo captures stderr and stdout as well as stderr and stdout of C of a given function call. Currently this function cannot be nested.
func Chdir ¶
Chdir temporarily changes to the given working directory while calling the given function.
func ChecksumForPath ¶
ChecksumForPath computes a checksum of a file or directory.
func ChecksumsSHA256ForFiles ¶
ChecksumsSHA256ForFiles creates checksum-files with SHA-256 recursively for all files in a directory.
func CommandFileExtension ¶
func CommandFileExtension() (extension string)
CommandFileExtension returns the common file extension of a command file.
func CompressDirectory ¶
CompressDirectory reads the directory srcDirectory and writes a compressed version to archive.
func CopyFileCompressed ¶
CopyFileCompressed reads the file src and writes a compressed version to dst. The compression level can be gzip.DefaultCompression, gzip.NoCompression, gzip.HuffmanOnly or any integer value between gzip.BestSpeed and gzip.BestCompression inclusive.
func DirectoriesRecursive ¶
DirectoriesRecursive returns all subdirectories of the given path including the given path.
func DirectoryPermissionOfParent ¶
DirectoryPermissionOfParent looks at parent directory of the given path and returns a directory permission based on the permission of the parent. The returned permission copies the read, write and execute permissions.
func DownloadFile ¶
DownloadFile downloads a file from the URL to the file path.
func DownloadFileWithProgress ¶
DownloadFileWithProgress downloads a file from the URL to the file path while printing a progress to STDOUT.
func EnforceProcessTreeLimits ¶
func EnforceProcessTreeLimits(limits ProcessTreeLimits)
EnforceProcessTreeLimits constrains the current process and all descendant processes to the specified limits. The current process exits when the limits are exceeded.
func EnvOrDefault ¶
EnvOrDefault returns the environment variable with the given key, or the default value if the key is not defined.
func EnvironMap ¶ added in v1.2.0
EnvironMap returns a map of the current environment variables.
func EnvironmentPathList ¶
func EnvironmentPathList() (filePaths []string)
EnvironmentPathList returns the list of file paths contained in the "PATH" environment variable.
func ExtractFile ¶
ExtractFile extracts a compressed file to a given path. How the archive is compressed and packed is automatically inferred, e.g. by the file extension.
func FileChange ¶
FileChange changes the content of a file.
func FileExists ¶
FileExists checks if a file exists while following symlinks.
func FileOrSymlinkExists ¶
FileOrSymlinkExists checks if a file exists while not following symlinks.
func FilePermissionOfParent ¶
FilePermissionOfParent looks at parent directory of the given path and returns a file permission based on the permission of the parent. The returned permission copies the read and write permissions but not the execute permission.
func FilesRecursive ¶
FilesRecursive returns all files in a given path and its subpaths.
func ForEachFile ¶
ForEachFile walks through the given path and calls the given callback with every file.
func GreatestCommonDirectory ¶
GreatestCommonDirectory computes the greatest common part of the given paths. The resulting string must be the prefix of all the given paths.
func IsArchitectureARMWith32Bit ¶
func IsArchitectureARMWith32Bit() bool
IsArchitectureARMWith32Bit returns wheter the operating system runs on ARM with 32 bits.
func IsArchitectureARMWith64Bit ¶
func IsArchitectureARMWith64Bit() bool
IsArchitectureARMWith64Bit returns wheter the operating system runs on ARM with 64 bits.
func IsArchitectureX86With32Bit ¶
func IsArchitectureX86With32Bit() bool
IsArchitectureX86With32Bit returns wheter the operating system runs on x86 with 32 bits.
func IsArchitectureX86With64Bit ¶
func IsArchitectureX86With64Bit() bool
IsArchitectureX86With64Bit returns wheter the operating system runs on x86 with 64 bits.
func IsEnvEnabled ¶
IsEnvEnabled checks if the environment variable is enabled. By default an environment variable is considered enabled if it is set to "1", "true", "on" or "yes". Further such values can be provided as well. Capitalization is ignored.
func MakeFileCopyTargets ¶
func MakeFileCopyTargets(sourceMakefilePath string, destinationMakefilePath string, makeTargets []string) (err error)
MakeFileCopyTargets copyies Make targets of a Makefile to another Makefile that can have a manually-writen parts until a `# REMARK Do not edit` line.
func MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error.
func ProgressBar ¶
func ProgressBar(stream io.Writer, max int, description ...string) (progress *progressbar.ProgressBar)
ProgressBar returns a progress bar for counting items with sane defaults that prints its updates to the given writer.
func ProgressBarBytes ¶
func ProgressBarBytes(stream io.Writer, length int, description ...string) (progress *progressbar.ProgressBar)
ProgressBarBytes returns a progress bar for counting bytes with sane defaults that prints its updates to the given writer.
func RemoveFileIfExists ¶
RemoveFileIfExists checks if a file exists, and removes the file if it does exist. Symlinks are not followed, since they are files and should be removable by this function.
func RemoveFromEnvironmentPathBySearchTerm ¶
RemoveFromEnvironmentPathBySearchTerm returns the content of the "PATH" environment variable where file paths containing the given search terms are removed.
func RemoveTemporaryDirectory ¶
func RemoveTemporaryDirectory(directoryPath string)
RemoveTemporaryDirectory removes the given temporary directory path from disk with special handling for Windows. The reason we need special handling is because Windows seems to be colossally stupid when it comes to handling the open-ess of files and directories. https://$INTERNAL/symflower/symflower/-/merge_requests/2399#note_293837.
func ReplaceVariablesInFile ¶
ReplaceVariablesInFile replaces all variables in a file. A variable in a file has the syntax `{{$key}}` and which is then replaced by its value.
func RequireEnv ¶
RequireEnv returns the environment variable with the given key, or an error if the key is not defined.
func RewriteStaticIndexFile ¶
RewriteStaticIndexFile rewrites a `github.com/bouk/staticfiles` index file to be extendable by replacing inlined code to common code.
func SetRLimitFiles ¶
SetRLimitFiles temporarily changes the file descriptor resource limit while calling the given function.
func TarExtract ¶
func TarExtract(stream io.Reader, destinationPath string, compressionType CompressionType) (err error)
TarExtract reads the gzip-compressed tar file from the reader and writes it into the destination path.
func TarExtractFile ¶
TarExtractFile extracts a compressed TAR file to a given path.
func TestCapture ¶
func TestCaptureRecursive ¶
func TestCaptureWithCGo ¶
func TestCaptureWithPanic ¶
func Uncompress ¶
Uncompress extracts the given archive into the given destination.
func ValidateChecksumForPath ¶
ValidateChecksumForPath computes a checksum of a file or directory and returns an error if it does not match the checksum stored in the given file.
func WriteChecksumForPath ¶
WriteChecksumForPath computes a checksum of a file or directory and writes it to the given file.
func ZipExtractFile ¶
ZipExtractFile extracts a zipped file to a given path.
Types ¶
type FilePathsByHierarchy ¶
type FilePathsByHierarchy []string
FilePathsByHierarchy sorts file paths by their hierarchy.
func (FilePathsByHierarchy) Len ¶
func (s FilePathsByHierarchy) Len() int
Len is the number of elements in the collection.
func (FilePathsByHierarchy) Less ¶
func (s FilePathsByHierarchy) Less(i, j int) bool
Less reports whether the element with index i must sort before the element with index j.
func (FilePathsByHierarchy) Swap ¶
func (s FilePathsByHierarchy) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type InMemoryStream ¶
type InMemoryStream struct {
// contains filtered or unexported fields
}
InMemoryStream allows to read and write to an in-memory stream.
func NewInMemoryStream ¶
func NewInMemoryStream(reader io.ReadCloser, writer io.WriteCloser) *InMemoryStream
type ProcessTreeLimits ¶
type ProcessTreeLimits struct { // MaxMemoryInMiB holds the limit for the memory usage of the current process and all descendants in 1024-based mebibytes. // Zero means no limit. MaxMemoryInMiB uint // OnOutOfMemory may or may not run when the memory limit is reached, depending on the enforcement strategy. If it runs, the process will not be killed automatically and the function should end the process. OnMemoryLimitReached func(currentMemoryInMiB uint, maxMemoryInMiB uint) // WatchdogInterval holds the amount of time to sleep between checks if the limits have been exceeded, if a watchdog strategy is used. // The default is two seconds. WatchdogInterval time.Duration }
ProcessTreeLimits holds limits to apply to the current process's resource usage, including the resource usage of its descendant processes.
type StandardStream ¶
type StandardStream struct{}
StandardStream allows to read from STDIN and write to STDOUT.
type StaticFile ¶
type StaticFile struct { Data string Mime string Mtime time.Time // Size is the size before compression. // If 0, it means the data is uncompressed. Size int // Hash is a SHA-256 hash of the file contents, which is used for the Etag, and useful for caching. Hash string // Directory determines if this file is a directory. Directory bool }
StaticFile holds a single file or directory in-memory.
Source Files ¶
- archive.go
- capture_linux.go
- capture_test_linux.go
- capture_testwrapper_linux.go
- chdir.go
- checksum.go
- conversion.go
- copy.go
- directory.go
- download.go
- env.go
- exists.go
- exists_notwindows.go
- files.go
- files_notwindows.go
- info_linux.go
- io.go
- limits.go
- limits_linux.go
- makefile.go
- os.go
- path_notwindows.go
- path_operator.go
- permission.go
- platform_notwindows.go
- progress.go
- remove.go
- static.go
- variables.go