file

package
v1.12.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 6 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPermissionsTooOpen = goerrors.New("file permissions are too open")
	ErrNilParam           = goerrors.New("got nil parameter")
)

Functions

func MoveFileWithReplacement added in v1.10.1

func MoveFileWithReplacement(src, dst string) error

MoveFileWithReplacement copies the file contents at `src` to `dst`. and deletes `src` on success.

If the file at `dst` already exists, it will be truncated and its contents overwritten.

func RenameFile

func RenameFile(oldpath, newpath string) error

RenameFile renames oldpath to newpath, returning an error if newpath already exists. If this function returns successfully, the contents of newpath will be identical to oldpath, and oldpath will be removed.

func RenameFileWithReplacement added in v1.10.1

func RenameFileWithReplacement(oldpath, newpath string) error

RenameFileWithReplacement will replace any existing file at newpath with the contents of oldpath. It works also if it the rename spans over several file systems.

If no file already exists at newpath, newpath will be created using the contents of oldpath. If this function returns successfully, the contents of newpath will be identical to oldpath, and oldpath will be removed.

func SyncDir

func SyncDir(dirName string) error

func VerifyFileInfoPermissiveness

func VerifyFileInfoPermissiveness(info os.FileInfo, maxPerms os.FileMode, path string) error

VerifyFileInfoPermissiveness checks if permissions on info are as restrictive or more restrictive than maxPerms. If not, then an error is returned. path is only used to provide better messages. If path is empty, then info.Name() is used for error messages.

func VerifyFilePermissivenessF

func VerifyFilePermissivenessF(f *os.File, maxPerms os.FileMode) error

VerifyFilePermissivenessF checks if permissions on f are as restrictive or more restrictive than maxPerms. if not, then an error is returned. For security reasons, there is no VerifyFilePermissiveness function that allows passing a path. This is to prevent TOCTOU (Time-of-Check-Time-of-Use) issues because of race conditions on checking file permissions versus opening the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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