fsutil

package
v12.23.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: Apache-2.0 Imports: 12 Imported by: 110

Documentation

Overview

Package fsutil provides methods for working with files on POSIX compatible systems

Package fsutil provides methods for working with files on POSIX compatible systems

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyPath = errors.New("Path is empty")

ErrEmptyPath can be returned by different methods if given path is empty and can't be used

Functions

func CheckPerms

func CheckPerms(props, path string) bool

CheckPerms checks many props at once

F - is file D - is directory X - is executable L - is link W - is writable R - is readable B - is block device C - is character device S - not empty (only for files)

func CopyDir

func CopyDir(from, to string) error

CopyDir copies directory content recursively to target directory

func CopyFile

func CopyFile(from, to string, perms ...os.FileMode) error

CopyFile copies file using bufio

func GetATime

func GetATime(path string) (time.Time, error)

GetATime returns time of last access

func GetCTime

func GetCTime(path string) (time.Time, error)

GetCTime returns time of creation

func GetMTime

func GetMTime(path string) (time.Time, error)

GetMTime returns time of modification

func GetMode

func GetMode(path string) os.FileMode

GetMode returns file mode bits

func GetOwner

func GetOwner(path string) (int, int, error)

GetOwner returns object owner UID and GID

func GetSize

func GetSize(path string) int64

GetSize returns file size in bytes

func GetTimes

func GetTimes(path string) (time.Time, time.Time, time.Time, error)

GetTimes returns time of access, modification, and creation at once

func GetTimestamps

func GetTimestamps(path string) (int64, int64, int64, error)

GetTimestamps returns time of access, modification, and creation at once as unix timestamp

func IsBlockDevice

func IsBlockDevice(path string) bool

IsBlockDevice returns true if the given object is a device

func IsCharacterDevice

func IsCharacterDevice(path string) bool

IsCharacterDevice returns true if the given object is a character device

func IsDir

func IsDir(path string) bool

IsDir returns true if the given object is a directory

func IsEmptyDir

func IsEmptyDir(path string) bool

IsEmptyDir returns true if given directory es empty

func IsExecutable

func IsExecutable(path string) bool

IsExecutable returns true if given object is executable by current user

func IsExecutableByUser

func IsExecutableByUser(path, userName string) bool

IsExecutableByUser returns true if given object is executable by some user

func IsExist

func IsExist(path string) bool

IsExist returns true if the given object is exist

func IsLink(path string) bool

IsLink returns true if the given object is a link

func IsNonEmpty

func IsNonEmpty(path string) bool

IsNonEmpty returns true if given file is not empty

func IsReadable

func IsReadable(path string) bool

IsReadable returns true if given object is readable by current user

func IsReadableByUser

func IsReadableByUser(path, userName string) bool

IsReadableByUser returns true if given object is readable by some user

func IsRegular

func IsRegular(path string) bool

IsRegular returns true if the given object is a regular file

func IsSocket

func IsSocket(path string) bool

IsSocket returns true if the given object is a socket

func IsWritable

func IsWritable(path string) bool

IsWritable returns true if given object is writable by current user

func IsWritableByUser

func IsWritableByUser(path, userName string) bool

IsWritableByUser returns true if given object is writable by some user

func LineCount

func LineCount(file string) int

LineCount return number of lines in file

func List

func List(dir string, ignoreHidden bool, filters ...ListingFilter) []string

List is lightweight method for listing directory

func ListAll

func ListAll(dir string, ignoreHidden bool, filters ...ListingFilter) []string

ListAll is lightweight method for listing all files and directories

func ListAllDirs

func ListAllDirs(dir string, ignoreHidden bool, filters ...ListingFilter) []string

ListAllDirs is lightweight method for listing all directories

func ListAllFiles

func ListAllFiles(dir string, ignoreHidden bool, filters ...ListingFilter) []string

ListAllFiles is lightweight method for listing all files

func ListToAbsolute

func ListToAbsolute(path string, list []string)

ListToAbsolute converts slice with relative paths to slice with absolute paths

func MoveFile

func MoveFile(from, to string, perms ...os.FileMode) error

MoveFile moves file

func Pop

func Pop() string

Pop changes current working directory to previous in stack

func ProperPath

func ProperPath(props string, paths []string) string

ProperPath returns the first proper path from a given slice

func Push

func Push(dir string) string

Push changes current working directory and add previous working directory to stack

func ValidatePerms

func ValidatePerms(props, path string) error

ValidatePerms validates permissions for file or directory

Types

type ListingFilter

type ListingFilter struct {
	MatchPatterns    []string // Slice with shell file name patterns
	NotMatchPatterns []string // Slice with shell file name patterns

	ATimeOlder   int64 // Files with ATime less or equal to defined timestamp (BEFORE date)
	ATimeYounger int64 // Files with ATime greater or equal to defined timestamp (AFTER date)
	CTimeOlder   int64 // Files with CTime less or equal to defined timestamp (BEFORE date)
	CTimeYounger int64 // Files with CTime greater or equal to defined timestamp (AFTER date)
	MTimeOlder   int64 // Files with MTime less or equal to defined timestamp (BEFORE date)
	MTimeYounger int64 // Files with MTime greater or equal to defined timestamp (AFTER date)

	SizeLess    int64 // Files with size less than defined
	SizeGreater int64 // Files with size greater than defined
	SizeEqual   int64 // Files with size equals than defined
	SizeZero    bool  // Empty files

	Perms    string // Permission (see fsutil.CheckPerms for more info)
	NotPerms string // Permission (see fsutil.CheckPerms for more info)
}

ListingFilter is struct with properties for filtering listing output

Jump to

Keyboard shortcuts

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