Module: MultiGit::Ref::Locking
- Included in:
- FileUpdater, MultiGit::RuggedBackend::Ref::Updater
- Defined in:
- lib/multi_git/ref.rb
Instance Method Summary collapse
- #acquire_lock ⇒ Object
- #ensure_dir! ⇒ Object
- #file_path ⇒ Object
- #lock_file_path ⇒ Object
- #release_lock(lock) ⇒ Object
Instance Method Details
#acquire_lock ⇒ Object
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_path ⇒ Object
97 98 99 |
# File 'lib/multi_git/ref.rb', line 97 def file_path ::File.join(repository.git_dir, name) end |
#lock_file_path ⇒ Object
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 |