Exemplo n.º 1
0
func unlock(lock lockfile.Lockfile) error {
	locksMu.Lock()
	defer locksMu.Unlock()

	if _, ok := locks[lock]; !ok {
		return nil
	}

	delete(locks, lock)
	return lock.Unlock()
}
Exemplo n.º 2
0
func tryLock(lock lockfile.Lockfile) error {
	locksMu.Lock()
	defer locksMu.Unlock()

	if _, ok := locks[lock]; ok {
		return errors.New("file in use")
	}

	if err := lock.TryLock(); err != nil {
		return err
	}

	locks[lock] = struct{}{}
	return nil
}