helpers

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PathExpanderFunc = func(path string) (string, error) {
	if strings.HasPrefix(path, "~") {
		homeDir, err := userHomeDirFunc()
		if err != nil {
			return "", fmt.Errorf("could not get user home directory: %w", err)
		}
		return filepath.Join(homeDir, path[1:]), nil
	}
	return path, nil
}

PathExpanderFunc is a variable that can be overridden in tests to mock path expansion.

Functions

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies the contents of the source directory (src) into the destination directory (dst). If dst does not exist, it will be created with the same permission bits as src. Subdirectories and files will be copied recursively. If src is not a directory, an error is returned.

Note: This function does not preserve symlinks as symlinks—it follows them (via os.ReadDir’s behavior). Extended file attributes (xattrs) or other metadata beyond basic permissions are not preserved.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a single file from src to dst. The destination file is created (or truncated if it exists) with the same permission bits as the source. If any I/O error occurs, the function returns an error. Note: Extended file attributes (xattrs), ACLs, or other metadata beyond basic UNIX permissions are not preserved by this approach.

func CopyReader

func CopyReader(src io.Reader, dst string, mode os.FileMode, fileSizeLimit int64) error

CopyReader copies from an arbitrary io.Reader (src) to a file at path dst. The newly created or truncated file is opened with the specified mode (OS file permissions). If fileSizeLimit > 0, only up to fileSizeLimit bytes are read from src. After the copy, the mode is applied to the file.

func ExpandPath

func ExpandPath(path string) (string, error)

func GetDirectorySize

func GetDirectorySize(dir string) (int64, error)

GetDirectorySize returns the total size of all regular files (in bytes) contained in the specified directory (recursively). If the path starts with "~", it will be expanded via ExpandPath. If the path is invalid or an error occurs during traversal, an error is returned.

Note: This function counts the sizes of files within the directory. It does not handle special file types (e.g. device files, symlinks to large directories) in a special manner—they’re counted or followed as normal by filepath.Walk.

Types

This section is empty.

Jump to

Keyboard shortcuts

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