utilio

package
v0.1.24-rc.18 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRedirectNoHTTPSDowngrade

func CheckRedirectNoHTTPSDowngrade(req *http.Request, via []*http.Request) error

CheckRedirectNoHTTPSDowngrade rejects redirects from an HTTPS source to an insecure destination while allowing redirects that preserve or improve the transport scheme.

func CleanDir

func CleanDir(path string) (retErr error)

CleanDir removes everything in a directory, but not the directory itself.

func ExtractTar

func ExtractTar(body io.Reader, destDir string) error

ExtractTar extracts a tar or gzip-compressed tar stream into destDir. Only directories and regular files are accepted.

func InstallFile

func InstallFile(filename string, r io.Reader, perm os.FileMode) error

InstallFile writes the content from the provided reader to a local file with specified permissions. It limits the size of the content to 1 GiB and returns an error if the limit is exceeded. It ensures that the target directory exists and handles the file writing atomically.

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

func IsDirEmpty

func IsDirEmpty(dir string) (bool, error)

IsDirEmpty reports whether dir is empty or does not exist.

func IsExecutable

func IsExecutable(filePath string) bool

func ProbeRemoteHTTPObject added in v0.1.20

func ProbeRemoteHTTPObject(ctx context.Context, source string) error

ProbeRemoteHTTPObject checks that an HTTP artifact object is reachable without downloading the full object. It first tries HEAD, then falls back to a ranged GET for servers that do not support or incorrectly reject HEAD.

func ProbeWritableDir added in v0.1.20

func ProbeWritableDir(dir string) error

ProbeWritableDir verifies that dir accepts file creation and removal without leaving durable state behind.

func RedactHTTPError

func RedactHTTPError(err error) error

RedactHTTPError removes query parameters from URL errors returned by the Go HTTP client while preserving the underlying transport error.

func RedactURLQuery

func RedactURLQuery(rawURL string) string

RedactURLQuery removes query parameters from rawURL before it is logged or included in an error message.

func URLWithoutQuery

func URLWithoutQuery(rawURL string) string

URLWithoutQuery removes query parameters from rawURL. It returns a redacted placeholder when rawURL cannot be parsed safely.

func UpdateSymlink(linkPath, targetPath string) error

UpdateSymlink atomically updates linkPath to point at targetPath.

func WriteFile

func WriteFile(filename string, content []byte, perm os.FileMode) error

WriteFile writes the provided content to a local file with specified permissions. It ensures that the target directory exists and handles the file writing atomically. The temp file is created in the same directory as the destination to preserve the correct SELinux label (avoiding the user_tmp_t label from /tmp).

NOTE: we assume the filename is trusted and cleaned without path traversal characters.

Types

type TarFile

type TarFile struct {
	Name string
	Size int64
	Body io.Reader
}

type TarFileSeq added in v0.1.21

type TarFileSeq = iter.Seq2[*TarFile, error]

func DecompressTarGz added in v0.1.21

func DecompressTarGz(body io.Reader) TarFileSeq

DecompressTarGz returns an iterator that yields the files contained in a gzip-compressed tar stream.

func DecompressTarGzFromRemote

func DecompressTarGzFromRemote(ctx context.Context, url string) TarFileSeq

DecompressTarGzFromRemote returns an iterator that yields the files contained in a .tar.gz file located at the given HTTP(S) URL.

Jump to

Keyboard shortcuts

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