module StoreAgent::Node::Locker
オブジェクトの読み書き時にファイルをロックするモジュール
Public Instance Methods
chown(*)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 75 def chown(*) lock!(lock_mode: File::LOCK_EX, recursive: false) do super end end
copy(dest_path = nil, *)
click to toggle source
TODO コピー元を共有ロック、コピー先を排他ロックする
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 53 def copy(dest_path = nil, *) super end
create(*)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 21 def create(*) lock!(lock_mode: File::LOCK_EX, recursive: true) do super end end
delete(*, recursive: true)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 39 def delete(*, recursive: true) lock!(lock_mode: File::LOCK_EX, recursive: recursive) do super end end
move(dest_path = nil, *)
click to toggle source
TODO 移動元と移動先を排他ロックする
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 59 def move(dest_path = nil, *) super end
read(*)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 27 def read(*) lock!(lock_mode: File::LOCK_SH, recursive: true) do super end end
set_permission(*)
click to toggle source
TODO 親階層のファイルをロックする
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 83 def set_permission(*) lock!(lock_mode: File::LOCK_EX, recursive: false) do super end end
touch(*)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 45 def touch(*) lock!(lock_mode: File::LOCK_SH, recursive: true) do super end end
unset_permission(*)
click to toggle source
TODO 親階層のファイルをロックする
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 91 def unset_permission(*) lock!(lock_mode: File::LOCK_EX, recursive: false) do super end end
update(*)
click to toggle source
Calls superclass method
# File lib/store_agent/node/prepend_module/locker.rb, line 33 def update(*) lock!(lock_mode: File::LOCK_EX, recursive: true) do super end end
Protected Instance Methods
lock!(lock_mode: File::LOCK_SH, recursive: false) { || ... }
click to toggle source
# File lib/store_agent/node/prepend_module/locker.rb, line 104 def lock!(lock_mode: File::LOCK_SH, recursive: false, &block) proc = Proc.new do if !File.exists?(dirname = File.dirname(lock_file_path)) FileUtils.mkdir(dirname) end open(lock_file_path, File::RDWR | File::CREAT) do |f| timeout(StoreAgent.config.lock_timeout) do f.flock(lock_mode) end f.truncate(0) yield end end if recursive && !root? parent_directory.lock!(lock_mode: lock_mode, recursive: recursive, &proc) else proc.call end end
lock_file_path()
click to toggle source
TODO
# File lib/store_agent/node/prepend_module/locker.rb, line 100 def lock_file_path "#{metadata.file_path}.lock" end