fs

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainedRelPath

func ContainedRelPath(base, path string) string

ContainedRelPath returns a path relative to the base path, or the base if the path cannot be made relative.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst, preserving the file's permissions. It returns an error if the source file cannot be opened, if the destination file cannot be created (e.g., if it already exists), or if the copy operation fails.

func IsSubPath

func IsSubPath(parent, child string) bool

IsSubPath checks if the child path is a subpath of the parent path.

func SanitizePathError

func SanitizePathError(err error, workDir string) error

SanitizePathError sanitizes the path in a path error to be relative to the work directory. If the path cannot be made relative, the filename is used instead.

This is useful for making error messages more user-friendly, as the work directory is typically a temporary directory that the user does not care about.

func SimpleAtomicMove

func SimpleAtomicMove(src, dst string) error

SimpleAtomicMove performs an atomic move operation from src to dst. If the destination already exists, it removes it before attempting the move. It returns an error if the move operation fails for any reason, including if the source file does not exist or if the destination cannot be created.

func ValidateSymlinks(root, dir string, maxDepth int) error

ValidateSymlinks checks for symlinks in the specified directory that point outside the specified root path. It avoids infinite recursion by limiting the depth of recursion. If a symlink is found that points outside the root path, or if the maximum recursion depth is exceeded, an error is returned.

To allow for any depth of recursion, set maxDepth to -1.

Types

This section is empty.

Jump to

Keyboard shortcuts

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