Sha256: 314cd267a9eb96da77f9044f13cb8d4fe4b28de99245f0147d5175d674c3813f
Contents?: true
Size: 770 Bytes
Versions: 15
Compression:
Stored size: 770 Bytes
Contents
module Ro class Lock def initialize(path) @path = path.to_s @fd = false end def lock(&block) open! if block begin lock! block.call ensure unlock! end else self end end def open! @fd ||= ( fd = begin open(@path, 'ab+') rescue unless test(?e, @path) FileUtils.mkdir_p(@path) FileUtils.touch(@path) end open(@path, 'ab+') end fd.close_on_exec = true fd ) end def lock! open! @fd.flock File::LOCK_EX end def unlock! open! @fd.flock File::LOCK_UN end end end
Version data entries
15 entries across 15 versions & 1 rubygems