file

package
v3.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEditPending  = errors.New(`the configuration is already being edited (--discard to edit from the installed configuration or --recover to edit the unapplied config)`)
	ErrEditValidate = errors.New("configuration validation error")
)

Functions

func Copy

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

Copy copies the file content from src file path to dst file path. If dst does not exist, it is created.

func Copy2

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

Copy2 is Identical to Copy() except that Copy2() also attempts to preserve file metadata.

func CopyMeta

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

CopyMeta clones the uid, gid, mtime and mode from src to dst

func CopyOwnership

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

func CopyTo

func CopyTo(src string, w *os.File) (err error)

func Diff

func Diff(a, b string) (string, error)

func Edit

func Edit(src string, mode EditMode, validate func(dst string) error) error

func Exists

func Exists(path string) bool

Exists returns true if the file path exists.

func ExistsAndDir

func ExistsAndDir(path string) (bool, error)

ExistsAndDir returns true if the file path exists and is a directory.

func ExistsAndRegular

func ExistsAndRegular(path string) (bool, error)

ExistsAndRegular returns true if the file path exists and is a regular file.

func ExistsAndSymlink(path string) (bool, error)

ExistsAndSymlink returns true if the file path exists and is a symbolic link.

func ExistsNotDir

func ExistsNotDir(path string) (bool, error)

ExistsNotDir returns true if the file path exists and is not a directory.

func HaveSameMD5

func HaveSameMD5(opts ...interface{}) bool

HaveSameMD5 accepts a variadic list of options. Each option can be either a []byte format md5 or a file path. In the latter case, the md5 is computed inline to compare with the previous known md5.

HaveSameMD5 returns true if all options refer directly or indirectly to the same md5 checksum.

func IsBlockDevice

func IsBlockDevice(p string) (bool, error)

func IsCharDevice

func IsCharDevice(p string) (bool, error)

func IsDevice

func IsDevice(p string) (bool, error)

func IsFilePath

func IsFilePath(path string) bool

func IsMode

func IsMode(p string, mode os.FileMode) (bool, error)

IsMode returns true if the file current mode is the same as the target mode.

func IsNotDir

func IsNotDir(err error) bool

func IsPerm

func IsPerm(p string, perm os.FileMode) (bool, error)

IsPerm returns true if the file current permissions are the same as the target.

func IsProtected

func IsProtected(fpath string) bool

IsProtected returns true if the file is too critical to alter or remove

func MD5

func MD5(p string) ([]byte, error)

MD5 returns the []byte format md5 of the content of the file at path p.

func MD5Reader

func MD5Reader(r io.Reader) ([]byte, error)

func ModTime

func ModTime(p string) (mtime time.Time)

ModTime returns the file modification time or a zero time.

func Mode

func Mode(p string) (os.FileMode, error)

Mode returns the FileMode of the file.

func Ownership

func Ownership(p string) (uid, gid int, err error)

Ownership returns the uid and gid owning the file

func Sync

func Sync(p string) error

Sync attempts to synchronize a file's in-memory state to the storage device. This ensures that the file data is safely written to disk.

func Touch

func Touch(p string, tm time.Time) error

Touch updates the atime and mtime of an existing file, or creates the file if it does not exist yet.

Types

type EditMode

type EditMode int
const (
	EditModeNormal EditMode = iota
	EditModeDiscard
	EditModeRecover
)

Jump to

Keyboard shortcuts

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