Module: MultiGit::Ref::Locking

Included in:
FileUpdater, MultiGit::RuggedBackend::Ref::Updater
Defined in:
lib/multi_git/ref.rb

Instance Method Summary collapse

Instance Method Details

#acquire_lockObject



81
82
83
84
85
# File 'lib/multi_git/ref.rb', line 81

def acquire_lock
  f = ::File.open(lock_file_path, ::File::CREAT | ::File::RDWR | ::File::EXCL )
  f.flock(::File::LOCK_EX)
  return f
end

#ensure_dir!Object



93
94
95
# File 'lib/multi_git/ref.rb', line 93

def ensure_dir!
  FileUtils.mkdir_p(::File.dirname(lock_file_path))
end

#file_pathObject



97
98
99
# File 'lib/multi_git/ref.rb', line 97

def file_path
  ::File.join(repository.git_dir, name)
end

#lock_file_pathObject



77
78
79
# File 'lib/multi_git/ref.rb', line 77

def lock_file_path
  ::File.join(repository.git_dir, name + '.lock')
end

#release_lock(lock) ⇒ Object



87
88
89
90
91
# File 'lib/multi_git/ref.rb', line 87

def release_lock(lock)
  ::File.unlink(lock.path)
  lock.flock(::File::LOCK_UN)
  lock.close
end