fileutils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0, LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fileutils provides utility functions for file operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChownRecursiveFrom

func ChownRecursiveFrom(root string, uidArgs *ChownUIDArgs, gidArgs *ChownGIDArgs) error

ChownRecursiveFrom changes ownership of files and directories under the specified root directory from the current UID/GID (fromUID, fromGID) to the new UID/GID (toUID, toGID).

It mirrors the behavior of chown_tree from shadow-utils: https://github.com/shadow-maint/shadow/blob/e7ccd3df6845c184d155a2dd573f52d239c94337/lib/chowndir.c#L129-L141

Symlinks are not followed.

If uidArgs/gidArgs is nil, change of ownership for UID/GID is skipped. If both uidArgs and gidArgs are nil, an error is returned.

func CopyFile

func CopyFile(srcPath, destPath string) error

CopyFile copies a file from a source to a destination path, preserving the file mode.

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if a file exists at the given path.

func IsDirEmpty

func IsDirEmpty(path string) (bool, error)

IsDirEmpty checks if the specified directory is empty.

func LockDir

func LockDir(dir string) (func() error, error)

LockDir creates a lock file in the specified directory and acquires an exclusive lock on it. It blocks until the lock is available and returns an unlock function to release the lock.

func Lrename

func Lrename(oldPath, newPath string) error

Lrename renames a file or directory, resolving symlinks in the destination path. If the symlink resolution fails, it returns a SymlinkResolutionError.

func Touch

func Touch(path string) error

Touch creates an empty file at the given path, if it doesn't already exist.

Types

type ChownGIDArgs

type ChownGIDArgs struct {
	FromGID uint32
	ToGID   uint32
}

ChownGIDArgs is used to specify the GID to change group ownership from and to.

type ChownUIDArgs

type ChownUIDArgs struct {
	FromUID uint32
	ToUID   uint32
}

ChownUIDArgs is used to specify the UID to change ownership from and to.

type SymlinkResolutionError

type SymlinkResolutionError struct {
	// contains filtered or unexported fields
}

SymlinkResolutionError is the error returned when symlink resolution fails.

func (SymlinkResolutionError) Error

func (e SymlinkResolutionError) Error() string

func (SymlinkResolutionError) Is

func (e SymlinkResolutionError) Is(target error) bool

Is makes this error insensitive to the internal values.

func (SymlinkResolutionError) Unwrap

func (e SymlinkResolutionError) Unwrap() error

Jump to

Keyboard shortcuts

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