Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 GetDirectorySize ¶
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.