filecheck

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 4 Imported by: 39

Documentation

Overview

Package filecheck provides a means of checking that certain constraints apply to a file-system object. There are checks on the existence of the file and on it's status. The caller can opt to apply the checks to the object itself or, if it is a symbolic link, to the object being linked to. The default behaviour will check the status of the linked-to object.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShouldExistButDoesNot = errors.New("should exist but does not")
	ErrShouldNotExistButDoes = errors.New("should not exist but does")
)

Functions

This section is empty.

Types

type Exists

type Exists uint

Exists records whether the file-system object should exist or not. In each case the check is only valid at the time the check is made and so any code using this should be aware of this

const (
	// Optional indicates that no existence check should be made
	Optional Exists = iota
	// MustExist indicates that the object must exist
	MustExist
	// MustNotExist indicates that the object must not exist
	MustNotExist
)

type Provisos

type Provisos struct {
	Existence          Exists
	Checks             []check.FileInfo
	DontFollowSymlinks bool
}

Provisos records the expectations of the file-system object. You can specify whether the object should or shouldn't exist and whether, if it's a symlink, you should follow the link. You can also perform a number of checks on the status of the file system object.

func DirExists added in v1.1.0

func DirExists() Provisos

DirExists returns a Provisos that will check that the value refers to a directory, which must exist. This is a common Provisos value and this func is provided to simplify your code.

func FileExists added in v1.1.0

func FileExists() Provisos

FileExists returns a Provisos that will check that the value refers to a regular file, which must exist. This is a common Provisos value and this func is provided to simplify your code.

func FileNonEmpty added in v1.1.0

func FileNonEmpty() Provisos

FileNonEmpty returns a Provisos that will check that the value refers to a regular file, which must exist and must not be empty. This is a common Provisos value and this func is provided to simplify your code.

func IsNew added in v1.1.0

func IsNew() Provisos

IsNew returns a Provisos that will check that the value refers to a non-existent file/directory. This is a common Provisos value and this func is provided to simplify your code.

func (Provisos) GetFileInfo added in v1.2.0

func (p Provisos) GetFileInfo(name string) (os.FileInfo, error)

GetFileInfo gets the file information respecting the DontFollowSymlinks flag from the Provisos.

func (Provisos) StatusCheck

func (p Provisos) StatusCheck(name string) error

StatusCheck checks that the file system object called 'name' satisfies the constraints. It returns a non-nil error if the constraint is not met. Note that if the file does not exist and it is not expected to exist then no further checks are performed (this may be obvious to you)

func (Provisos) String

func (p Provisos) String() string

String returns a string describing the Provisos

Jump to

Keyboard shortcuts

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