fshelper

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 16 Imported by: 23

Documentation

Index

Constants

View Source
const (
	SYS_Statx = 332
)

Variables

This section is empty.

Functions

func Symlinkat

func Symlinkat(cwd, file, linkTo string) error

Symlinkat creates symlink relative to cwd rather actual working dir ref: https://man7.org/linux/man-pages/man2/symlink.2.html

Types

type CwdGetFunc added in v0.10.0

type CwdGetFunc = func(op Op, name string) (string, error)

op and name are operation and path value triggered this func, return value is the absolute path of current working dir

when operation involves more than one path value (e.g. Op_Symlink), name is the old path value

type FindOp added in v0.10.0

type FindOp uint32

FindOp is the bitset of find operations

const (
	FindOp_CheckDepth FindOp = 1 << iota

	// set FindOptions.FileType to filter
	FindOp_CheckTypeNotFile // not regular file (e.g. dir, symlink)

	// FindOptions.FileType is ignored, and file should report is regular file
	FindOp_CheckTypeIsFile // is regular file

	FindOp_CheckPerm // TODO: currently not implementd

	// set both FindOptions.{Min, Max}Size to filter
	FindOp_CheckSize

	FindOp_CheckUserInvalid // no unix implementation

	// set FindOptions.UnixUID or FindOptions.WindowsOrPlan9User to filter
	FindOp_CheckUser

	// set FindOptions.UnixGID or FindOptions.WindowsOrPlan9Group to filter
	FindOp_CheckGroup

	// set both FindOptions.{Min, Max}CreationTime to filter
	FindOp_CheckCreationTime // btime (birth time)

	// set both FindOptions.{Min, Max}Ctime to filter
	FindOp_CheckLastMetadataChangeTime // ctime

	// set both FindOptions.{Min, Max}Atime to filter
	FindOp_CheckLastAccessTime // atime

	// set both FindOptions.{Min, Max}Mtime to filter
	FindOp_CheckLastContentUpdatedTime // mtime

	// set FindOptions.NamePattern to filter
	FindOp_CheckName

	// set FindOptions.NamePatternFollowSymlink to filter
	FindOp_CheckNameFollowSymlink

	// set FindOptions.NamePatternLower to filter
	FindOp_CheckNameIgnoreCase

	// set FindOptions.NamePatternLowerFollowSymlink to filter
	FindOp_CheckNameIgnoreCaseFollowSymlink

	// set FindOptions.PathPattern to filter
	FindOp_CheckPath

	// set FindOptions.PathPatternLower to filter
	FindOp_CheckPathIgnoreCase

	// set FindOptions.RegExpr to filter
	FindOp_CheckRegex

	// set FindOptions.RegExprNoCase to filter
	FindOp_CheckRegexNoCase
)

type FindOptions added in v0.10.0

type FindOptions struct {
	Ops FindOp

	FileType fs.FileMode
	Perm     fs.FileMode // TODO: currently not used

	MinDepth, MaxDepth int32
	MinSize, MaxSize   int64

	// unix timestamps (seconds since unix epoch)
	MinCreationTime, MaxCreationTime int64
	MinAtime, MaxAtime               int64
	MinCtime, MaxCtime               int64
	MinMtime, MaxMtime               int64

	RegExpr, RegExprNoCase regexp.Regexp

	UnixUID, UnixGID uint32
	// windows SID of user & group or plan9 user & group name
	WindowsOrPlan9User, WindowsOrPlan9Group string

	PathPattern,

	PathPatternLower string

	NamePattern,
	NamePatternFollowSymlink,

	NamePatternLower,

	NamePatternLowerFollowSymlink string

	// Run on each matched path
	OnMatch func(path string, d fs.DirEntry)
}

type OSFS

type OSFS struct {
	// Strict when set to true, adhere to io/fs.FS path value requirements
	// otherwise accepts all system path values
	Strict bool

	// used to determine current working dir, the string return value should be valid system
	// file path
	GetCwd CwdGetFunc

	// LookupFHS is the custom handler for unix style path on windows
	LookupFHS func(string) (string, error)
}

OSFS is a context aware filesystem abstration for afero.FS and io/fs.FS

func NewOSFS

func NewOSFS(strictIOFS bool, getCwd CwdGetFunc) *OSFS

NewOSFS creates a new filesystem abstraction for real filesystem set strictIOFS to true to only allow fs path value

getCwd is

func (*OSFS) Abs

func (ofs *OSFS) Abs(name string) (path string, err error)

Abs is the filepath.Abs equivalent

func (*OSFS) Chmod

func (ofs *OSFS) Chmod(name string, mode fs.FileMode) error

Chmod is the os.Chmod equivalent

func (*OSFS) Chown

func (ofs *OSFS) Chown(name string, uid, gid int) error

Chown is the os.Chown equivalent

func (*OSFS) Chtimes

func (ofs *OSFS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes is the os.Chtimes equivalent

func (*OSFS) Create

func (ofs *OSFS) Create(name string) (fs.File, error)

Create is the os.Create equivalent

func (*OSFS) Find added in v0.10.0

func (ofs *OSFS) Find(fopts *FindOptions, startpath string) (ret []string, err error)

Find all matched files by walking from startpath

func (*OSFS) Glob

func (ofs *OSFS) Glob(pattern string) ([]string, error)

Glob implements fs.GlobFS with `**` support

func (*OSFS) Lstat

func (ofs *OSFS) Lstat(name string) (fs.FileInfo, error)

Lstat is the os.Lstat equivalent

func (*OSFS) Mkdir

func (ofs *OSFS) Mkdir(name string, perm fs.FileMode) error

Mkdir is the os.Mkdir equivalent

func (*OSFS) MkdirAll

func (ofs *OSFS) MkdirAll(name string, perm fs.FileMode) error

MkdirAll is the os.MkdirAll equivalent

func (*OSFS) Open

func (ofs *OSFS) Open(name string) (fs.File, error)

Open is the os.Open equivalent implements fs.FS

func (*OSFS) OpenFile

func (ofs *OSFS) OpenFile(name string, flag int, perm fs.FileMode) (fs.File, error)

OpenFile is the os.OpenFile equivalent

func (*OSFS) ReadDir

func (ofs *OSFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir is the os.ReadDir equivalent implements fs.ReadDirFS

func (*OSFS) ReadFile

func (ofs *OSFS) ReadFile(name string) ([]byte, error)

ReadFile is the os.ReadFile equivalent implements fs.ReadFileFS

func (ofs *OSFS) Readlink(name string) (string, error)

Readlink is the os.Readlink equivalent

func (*OSFS) Remove

func (ofs *OSFS) Remove(name string) error

Remove is the os.Remove equivalent

func (*OSFS) RemoveAll

func (ofs *OSFS) RemoveAll(name string) error

RemoveAll is the os.RemoveAll equivalent

func (*OSFS) Rename

func (ofs *OSFS) Rename(oldname, newname string) error

Rename is the os.Rename equivalent

func (*OSFS) Stat

func (ofs *OSFS) Stat(name string) (fs.FileInfo, error)

Stat is the os.Stat equivalent

func (*OSFS) Sub

func (ofs *OSFS) Sub(dir string) (fs.FS, error)

Sub implements fs.SubFS

func (ofs *OSFS) Symlink(oldname, newname string) error

Symlink is the os.Symlink equivalent

func (*OSFS) TryMatch added in v0.10.0

func (ofs *OSFS) TryMatch(opts *FindOptions, slashPath string, d fs.DirEntry) (matched bool, err error)

TryMatch checks whether DirEntry d satisfies FindOptions

slashPath (a slash separated path) and d should match fs.WalkFunc definition

func (*OSFS) WriteFile

func (ofs *OSFS) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile is the os.WriteFile equivalent

type Op added in v0.10.0

type Op uint32
const (
	Op_Unknown Op = iota

	Op_Abs // operation to get absolute path
	Op_Sub // operation to create sub fs

	Op_Create  // operation to create file
	Op_Symlink // operation to create symlink

	Op_Mkdir    // operation to create dir
	Op_MkdirAll // operation to create dir recursively

	Op_OpenFile // operation to open file with options
	Op_Open     // operation to open file for reading

	Op_Lstat // operation to lstat
	Op_Stat  // operation to stat

	Op_ReadFile // operation to read file content
	Op_ReadDir  // operation to read dir file list
	Op_Readlink // operation to read link destination

	Op_WriteFile // operation to write content to file

	Op_Chmod   // operation to change permission flags of file
	Op_Chown   // operation to change owner flags of file
	Op_Chtimes // operation to change time values of file

	Op_Rename // operation to rename file

	Op_Remove    // operation to remove file
	Op_RemoveAll // operation to remove files recursively
)

Jump to

Keyboard shortcuts

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