utils

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package utils implements helper functions

Index

Constants

This section is empty.

Variables

View Source
var ErrEndTarWalk = errors.New("end walking tar contents")

ErrEndTarWalk allows early stopping inspecting the tar file

View Source
var MaxDecompressionSize int64 = 8 * 1024 * 1024 * 1024

MaxDecompressionSize established a high enough maximum tar size to decompres to prevent decompression bombs (8GB)

Functions

func CopyDir

func CopyDir(src, dest string) error

CopyDir copies the directory src to dest, including its contents

func CopyFile

func CopyFile(src, dest string) error

CopyFile file copies src to dest, preserving permissions

func ExecuteWithRetry

func ExecuteWithRetry(retries int, cb func(try int, prevErr error) error) error

ExecuteWithRetry executes a function retrying until it succeeds or the number of retries is reached

func FileExists

func FileExists(filename string) bool

FileExists checks if filename exists

func FindFileInTar

func FindFileInTar(ctx context.Context, tarFilename string, path string, operation func(tr *tar.Reader) error, cfg TarConfig) error

FindFileInTar finds path in the tarFilename contents and processes it via the provided operation

func IsTarFile

func IsTarFile(filename string) (bool, error)

IsTarFile checks if the specified filename is a tar.gz file

func RelocateImageURL

func RelocateImageURL(url string, prefix string, includeIndentifier bool) (string, error)

RelocateImageURL rewrites the provided image url by replacing its prefix

func SafeWriteFile

func SafeWriteFile(filename string, data []byte, perm os.FileMode) error

SafeWriteFile writes data into the specified filename by first creating it, and then renaming to the final destination to minimize breaking the file

func Tar

func Tar(sourceDir string, filename string, cfg TarConfig) error

Tar calls TarContext with a Background context

func TarContext

func TarContext(parentCtx context.Context, sourceDir string, filename string, cfg TarConfig) error

TarContext compresses the provided sourceDir directory into the .tar.gz specified in filename, adding prefix to the added files.

func TruncateStringWithEllipsis

func TruncateStringWithEllipsis(text string, maxLength int) string

TruncateStringWithEllipsis returns a truncated version of text

func Untar

func Untar(filename string, outputDir string, cfg TarConfig) error

Untar decompresses the provided filename into the outputDir Simplified implementation taken from: golang.org/x/build/internal/untar (BSD license)

func UntarContext

func UntarContext(ctx context.Context, filename string, outputDir string, cfg TarConfig) error

UntarContext decompresses the provided filename into the outputDir Simplified implementation taken from: golang.org/x/build/internal/untar (BSD license)

func WalkTarFile

func WalkTarFile(ctx context.Context, filename string, operation func(tr *tar.Reader, header *tar.Header) error) error

WalkTarFile iterates over the list of tar entries and applies the provided operation

func YamlFileSet

func YamlFileSet(file string, values map[string]string) error

YamlFileSet sets the list of key-value specified in values in the YAML file. The keys are in jsonpath format

func YamlSet

func YamlSet(data []byte, values map[string]string) ([]byte, error)

YamlSet sets the list of key-value specified in values in the YAML data. The keys are in jsonpath format

Types

type TarConfig

type TarConfig struct {
	Prefix          string
	StripComponents int
	Skip            func(f string) bool
}

TarConfig defines the Tar char opts

Jump to

Keyboard shortcuts

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