15 lines
309 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
module Utils
module_function
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def file_locked?(file)
unlocked = File.open(file).flock(File::LOCK_EX | File::LOCK_NB)
# revert lock if file was unlocked before check
File.open(file).flock(File::LOCK_UN) if unlocked
!unlocked
rescue
true
end
2016-08-18 22:11:42 +03:00
end
end