fsutil

package
v2.2.2-0...-17ad7ea Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chdir

func Chdir(pwd string) (func(), error)

Chdir changes the directory so that all operations from now on are relative to the project we are working with. It returns a function that, when run, restores the old working directory.

func CopyFile

func CopyFile(dst string, src string, excl map[string]bool) error

CopyFile is a braindead simple function that copies a src file to a dst file. Note that it is not general purpose: it doesn't handle symbolic links, it doesn't try to be efficient, it doesn't handle copies where src and dst overlap, and it makes no attempt to preserve file permissions. It is what we need for this utility package, no more, no less.

func QnamePath

func QnamePath(nm tokens.QName) string

QnamePath just cleans a name and makes sure it's appropriate to use as a path.

func WalkUp

func WalkUp(path string, walkFn func(string) bool, visitParentFn func(string) bool) (string, error)

WalkUp walks each file in path, passing the full path to `walkFn`. If walkFn returns true, this method returns the path that was passed to walkFn. Before visiting the parent directory, visitParentFn is called, if that returns false, WalkUp stops its search

Types

type FileMutex

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

FileMutex is a mutex that serializes both within and across processes. When acquired, it can be assumed that the caller holds exclusive access over te protected resources, even if there are other consumers both within and outside of the same process.

func NewFileMutex

func NewFileMutex(path string) *FileMutex

NewFileMutex creates a new FileMutex using the given file as a file lock.

func (*FileMutex) Lock

func (fm *FileMutex) Lock() error

Lock locks the file mutex. It does this in two phases: first, it locks the process lock, which when held guarantees exclusive access to the resource within the current process. Second, with the process lock held, it locks the file lock. The flock system call operates on a process granularity and, if one process attempts to lock the same file multiple times, flock will consider the lock to be held by the process even if different threads are acquiring the lock.

Because of this, the two-pronged approach to locking guarantees exclusive access to the resource by locking a process shared mutex and a global shared mutex. Once this method returns without an error, callers can be sure that the calling goroutine completely owns the resource.

func (*FileMutex) Unlock

func (fm *FileMutex) Unlock() error

Unlock unlocks the file mutex. It first unlocks the file lock, which allows other processes to lock the file lock, after which it unlocks the proc lock. Unlocking the file lock first ensures that it is not possible for two goroutines to lock or unlock the file mutex without first holding the proc lock.

Jump to

Keyboard shortcuts

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