fsutil

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirExists

func DirExists(path string) (bool, error)

DirExists returns true if the given path exists and is a directory

func EmptyDir

func EmptyDir(path string) error

EmptyDir will recursively remove the contents of a directory at the given path

func EnsureDir

func EnsureDir(path string) error

EnsureDir will create a directory at the given path if it doesn't already exist

func EnsureDirAll

func EnsureDirAll(path string) error

EnsureDirAll will create a directory at the given path along with any necessary parents if they don't already exist

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if the given path exists and is a file. This function returns false and the error encountered if the call to os.Stat fails.

func FindInPaths

func FindInPaths(paths []string, baseName string) string

FindInPaths returns the path to baseName in the first path where it exists from paths.

func GetHomeDirectory

func GetHomeDirectory() string

GetHomeDirectory returns the path of the user's home directory. ~ on Unix and C:\Users\UserName on Windows

func GetIntraDir

func GetIntraDir(pattern string, depth, length int) string

GetIntraDir returns a string that can be added to filepath.Join to implement directory depth, "" on error eg given a pattern of 0af63ce3c99162e9df23a997f62621c5 and a depth of 2 length of 3 returns 0af/63c or 0af\63c ( dependin on os) that can be later used like this filepath.Join(directory, intradir, basename)

func GetNameFromPath

func GetNameFromPath(path string, stripExtension bool) string

GetNameFromPath returns the name of a file from its path if stripExtension is true the extension is omitted from the name

func IsFsPathCaseSensitive

func IsFsPathCaseSensitive(path string) (bool, error)

IsFsPathCaseSensitive checks the fs of the given path to see if it is case sensitive if the case sensitivity can not be determined false and an error != nil are returned

func IsPathInDir

func IsPathInDir(dir, pathToCheck string) bool

IsPathInDir returns true if pathToCheck is within dir.

func IsPathInDirs added in v0.17.0

func IsPathInDirs(dirs []string, pathToCheck string) bool

IsPathInDirs returns true if pathToCheck is within anys of the paths in dirs.

func MatchExtension

func MatchExtension(path string, extensions []string) bool

MatchExtension returns true if the extension of the provided path matches any of the provided extensions.

func RemoveDir

func RemoveDir(path string) error

RemoveDir removes the given dir (if it exists) along with all of its contents

func SafeMove

func SafeMove(src, dst string) error

SafeMove attempts to move the file with path src to dest using os.Rename. If this fails, then it copies src to dest, then deletes src.

func SanitiseBasename added in v0.17.0

func SanitiseBasename(v string) string

SanitiseBasename returns a file basename removing any characters that are illegal or problematic to use in the filesystem.

func SymWalk

func SymWalk(path string, walkFn filepath.WalkFunc) error

SymWalk extends filepath.Walk to also follow symlinks

func Touch

func Touch(path string) error

Touch creates an empty file at the given path if it doesn't already exist

func WriteFile

func WriteFile(path string, file []byte) error

WriteFile writes file to path creating parent directories if needed

Types

type Cancellable added in v0.15.0

type Cancellable interface {
	Cancel()
}

type LockContext added in v0.15.0

type LockContext struct {
	context.Context
	// contains filtered or unexported fields
}

func (*LockContext) AttachCommand added in v0.15.0

func (c *LockContext) AttachCommand(cmd *exec.Cmd)

func (*LockContext) Cancel added in v0.15.0

func (c *LockContext) Cancel()

type ReadLockManager added in v0.15.0

type ReadLockManager struct {
	// contains filtered or unexported fields
}

ReadLockManager manages read locks on file paths.

func NewReadLockManager added in v0.15.0

func NewReadLockManager() *ReadLockManager

NewReadLockManager creates a new ReadLockManager.

func (*ReadLockManager) Cancel added in v0.15.0

func (m *ReadLockManager) Cancel(fn string)

Cancel cancels all read lock contexts associated with fn.

func (*ReadLockManager) ReadLock added in v0.15.0

func (m *ReadLockManager) ReadLock(ctx context.Context, fn string) *LockContext

ReadLock adds a pending file read lock for fn to its storage, returning a context and cancel function. Per standard WithCancel usage, cancel must be called when the lock is freed.

Jump to

Keyboard shortcuts

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