file

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Index

Constants

View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
	TB
)

Variables

This section is empty.

Functions

func File

func File(path string, opts Options) error

File performs the file checks

Types

type Create added in v1.0.2

type Create struct {
	Path     string      // Path stores where the resource will be created
	Kind     CreateKind  // Kind requires either IfNotExists or another CreateKind
	FileMode os.FileMode // FileMode allows you to set os.ModePerm etc.
	OpenFlag int         // OpenFlag allows you to use os.O_CREATE|os.O_TRUNC|os.O_WRONLY
	Size     int64       // Size allows you to fill a file with zeros, throws error if applied to a directory
}

Create is used to describe the File you wish to Create, you are not required to set the Path, but you can if you wish to change it

func (*Create) Run added in v1.0.2

func (create *Create) Run() error

type CreateKind added in v1.0.2

type CreateKind int8
const (
	// NoAction will perform no action against the Create structure
	NoAction CreateKind = iota

	// IfNotExists CreateKind will perform an action on the Create structure if the path doesn't exist
	IfNotExists CreateKind = iota

	// IfExists CreateKind will perform an action on the Create structure if the path exists
	// This is intended to be a DESTRUCTIVE act when used since it removes the file first before Create.Run() is called.
	IfExists CreateKind = iota
)

type ErrCheckBadBaseDir

type ErrCheckBadBaseDir struct{ Path, BaseDir string }

func (*ErrCheckBadBaseDir) Error

func (e *ErrCheckBadBaseDir) Error() string

type ErrCheckBadGroup

type ErrCheckBadGroup struct{ Path, Expected, Actual string }

func (*ErrCheckBadGroup) Error

func (e *ErrCheckBadGroup) Error() string

type ErrCheckBadOwner

type ErrCheckBadOwner struct{ Path, Expected, Actual string }

func (*ErrCheckBadOwner) Error

func (e *ErrCheckBadOwner) Error() string

type ErrCheckNoWritePermissions

type ErrCheckNoWritePermissions struct{ Path string }

func (*ErrCheckNoWritePermissions) Error

type ErrCheckOpenPermissions

type ErrCheckOpenPermissions struct{ Path string }

func (*ErrCheckOpenPermissions) Error

func (e *ErrCheckOpenPermissions) Error() string

type Options

type Options struct {
	CreatedBefore      time.Time   // Check file creation time
	ModifiedBefore     time.Time   // Check file modified time
	IsLessThan         int64       // Check if the size is less than
	IsSize             int64       // Check the file size
	IsGreaterThan      int64       // Check if the size is greater than
	RequireExt         string      // Check if the file is of an extension
	RequirePrefix      string      // Check if the file name begins with a prefix
	RequireOwner       string      // Check if the file has a specific owner
	RequireGroup       string      // Check if the file has a specific group
	RequireBaseDir     string      // Check if the file is inside a specific base directory
	IsFileMode         os.FileMode // Check the os.FileMode value
	MorePermissiveThan os.FileMode // Check if mode is at least this permissive (e.g., >= 0444)
	LessPermissiveThan os.FileMode // Check if mode is less permissive than this (e.g., <= 0400)
	IsBaseNameLen      int         // Check if the file name length
	RequireWrite       bool        // Check if the file is writable
	ReadOnly           bool        // Check if the file is read-only
	WriteOnly          bool        // Check if the file is write-only
	Exists             bool        // Check if the file exists
	Create             Create      // Allow the user to create the file
}

Jump to

Keyboard shortcuts

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