Module: Fontist::Utils::Locking
- Included in:
- SystemIndex, SystemIndexFontCollection, Cache
- Defined in:
- lib/fontist/utils/locking.rb
Instance Method Summary collapse
Instance Method Details
#lock(lock_path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fontist/utils/locking.rb', line 4 def lock(lock_path) File.dirname(lock_path).tap do |dir| FileUtils.mkdir_p(dir) end f = File.open(lock_path, File::CREAT | File::WRONLY) raise "Failed to open lock file: #{lock_path}" unless f f.flock(File::LOCK_EX) yield ensure f&.flock(File::LOCK_UN) f&.close end |