file

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

ModeBits are the bits a configured mode sets: the rwx bits, and the setuid, setgid and sticky flags a 4 digit mode such as 2750 adds. FileMode.Perm() keeps the rwx bits only, so comparing it with such a mode never matches.

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")
)
View Source
var (
	ErrNotSame = errors.New("not same files")
)

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 DirPermFromFilePerm

func DirPermFromFilePerm(fp fs.FileMode) fs.FileMode

func Edit

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

Edit has the user edit a copy of the file src, and installs it once validate accepts it.

The copy is judged against the installed file: a copy identical to it holds nothing to recover, so it is not an edit pending, and an edit leaving it identical changed nothing. A copy holding changes is kept when the editor fails or validate refuses it, for an edit with --recover to go on from it, or one with --discard to drop it.

func EditCopy

func EditCopy(src string) string

EditCopy is the copy of the file src an edit is made in, which the edit installs once validated, and keeps while it is not, for a --recover.

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 Move

func Move(src, dst string) error

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.

func VerifySameMajorMinorAndInode

func VerifySameMajorMinorAndInode(p1, p2 string) error

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