Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chdir ¶
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 ¶
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.
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 ¶
NewFileMutex creates a new FileMutex using the given file as a file lock.
func (*FileMutex) Lock ¶
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 ¶
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.