Documentation
¶
Index ¶
- Variables
- func Copy(srcFile, dstFile string) error
- func CopyDirectory(srcDir, dest string) error
- func Exists(path string) (bool, error)
- func IsDir(path string) bool
- func SafeCreate(root, path string, mode int64) (*os.File, error)
- func SafeOpen(root, path string) (*os.File, error)
- func SafeOpenFile(root, path string, flag int, mode int64) (*os.File, error)
- func SafePath(root, path string) (string, error)
- func SafeReadFile(root, path string) ([]byte, error)
- func ValidMode(mode int64) (os.FileMode, error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CopyDirectory ¶
CopyDirectory copies a directory from src to dest
func SafeCreate ¶
SafeCreate creates or truncates a file with the specified mode. It uses SafeOpenFile with write-only, create and truncate flags.
func SafeOpen ¶
SafeOpen opens a file for read-only access in a secure manner. It uses SafeOpenFile with read-only flag and default permissions.
func SafeOpenFile ¶
SafeOpenFile opens a file with the specified path, base directory, flags, and mode. It ensures the file operation is secure by validating the mode and path. Returns a file handle and any error encountered.
func SafePath ¶
SafePath ensures the given path is safe to use within the specified root directory. It returns the cleaned absolute path and an error if the path is unsafe. The function performs the following checks and operations: 1. Validates that the path is not empty and does not contain null bytes. 2. Cleans and converts both the root and input paths to absolute paths. 3. Resolves any symlinks in the input path, even if the path does not exist. 4. Ensures the resolved path is within the root directory to prevent path traversal attacks. 5. Works on both Windows and Unix-like systems, handling platform-specific path separators and case sensitivity.
Parameters: - root: The root directory within which the path must be contained. - path: The input path to be validated and resolved. It can be either an absolute or relative path.
func SafeReadFile ¶
SafeReadFile reads the entire contents of a file securely. It ensures the file path is safe before reading. Returns the file contents and any error encountered.
Types ¶
This section is empty.