class StoreAgent::Node::DirectoryObject
ディレクトリ
Public Instance Methods
children()
click to toggle source
現在のディレクトリの直下にあるオブジェクトの一覧を返す
# File lib/store_agent/node/object/directory_object.rb, line 177 def children (current_children_filenames - StoreAgent.reserved_filenames).map{|filename| find_object(filename) } end
chown(*, identifier: nil, recursive: false)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#chown
# File lib/store_agent/node/object/directory_object.rb, line 117 def chown(*, identifier: nil, recursive: false) super do if recursive success, errors = call_for_children do |child| child.chown(identifier: identifier, recursive: recursive) end end end end
copy(dest_path = nil, *)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#copy
# File lib/store_agent/node/object/directory_object.rb, line 80 def copy(dest_path = nil, *) super do dest_directory = build_dest_directory(dest_path).create success, errors = call_for_children do |child| child.copy("#{dest_directory.path}#{File.basename(child.path)}") end end end
create() { |self| ... }
click to toggle source
Calls superclass method
StoreAgent::Node::Object#create
# File lib/store_agent/node/object/directory_object.rb, line 28 def create super do if block_given? yield self end FileUtils.mkdir(storage_object_path) workspace.version_manager.add("#{storage_object_path}.keep") end end
delete(*)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#delete
# File lib/store_agent/node/object/directory_object.rb, line 54 def delete(*) super do success, errors = call_for_children do |child| child.delete(recursive: false) end if success FileUtils.remove_dir(storage_object_path) else raise StoreAgent::PermissionDeniedError.new(errors: errors) end workspace.version_manager.remove(storage_object_path, directory: true) end end
directory(path)
click to toggle source
現在のパスからの相対パスで、ディレクトリオブジェクトのインスタンスを返す
# File lib/store_agent/node/object/directory_object.rb, line 167 def directory(path) StoreAgent::Node::DirectoryObject.new(workspace: workspace, path: namespaced_absolute_path(path)) end
directory_file_count()
click to toggle source
ディレクトリ直下にあるファイル数
# File lib/store_agent/node/object/directory_object.rb, line 200 def directory_file_count metadata["directory_file_count"] end
file(path)
click to toggle source
現在のパスからの相対パスで、ファイルオブジェクトのインスタンスを返す
# File lib/store_agent/node/object/directory_object.rb, line 172 def file(path) StoreAgent::Node::FileObject.new(workspace: workspace, path: namespaced_absolute_path(path)) end
find_object(path)
click to toggle source
引数を現在のパスからの相対パスとして解釈し、オブジェクトのインスタンスを返す
# File lib/store_agent/node/object/directory_object.rb, line 148 def find_object(path) object = StoreAgent::Node::Object.new(workspace: workspace, path: namespaced_absolute_path(path)) case object.exists? && object.filetype when false virtual(path) when "directory" directory(path) when "file" file(path) else raise "unknown filetype" end end
move(dest_path = nil, *)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#move
# File lib/store_agent/node/object/directory_object.rb, line 89 def move(dest_path = nil, *) super do dest_directory = build_dest_directory(dest_path) disk_usage = metadata.disk_usage file_count = directory_file_count FileUtils.mv(storage_object_path, dest_directory.storage_object_path) FileUtils.mv(metadata.base_path, dest_directory.metadata.base_path) FileUtils.mv(permission.base_path, dest_directory.permission.base_path) dest_directory.touch(recursive: true) dest_directory.parent_directory.metadata.update(disk_usage: disk_usage, directory_file_count: 1, tree_file_count: file_count + 1, recursive: true) parent_directory.metadata.update(disk_usage: -disk_usage, directory_file_count: -1, tree_file_count: -(file_count + 1), recursive: true) [storage_object_path, metadata.base_path, permission.base_path].each do |dir_path| workspace.version_manager.remove(dir_path, directory: true) end end end
read(revision: nil)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#read
# File lib/store_agent/node/object/directory_object.rb, line 38 def read(revision: nil) super do filenames = if revision.nil? current_children_filenames else workspace.version_manager.read(path: storage_object_path, revision: revision) end filenames - StoreAgent.reserved_filenames end end
set_permission(identifier: nil, permission_values: {}, recursive: false)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#set_permission
# File lib/store_agent/node/object/directory_object.rb, line 127 def set_permission(identifier: nil, permission_values: {}, recursive: false) super do if recursive success, errors = call_for_children do |child| child.set_permission(identifier: identifier, permission_values: permission_values) end end end end
touch(*, recursive: false)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#touch
# File lib/store_agent/node/object/directory_object.rb, line 68 def touch(*, recursive: false) super do FileUtils.touch("#{storage_object_path}.keep") workspace.version_manager.add("#{storage_object_path}.keep") if recursive success, errors = call_for_children do |child| child.touch(recursive: true) end end end end
tree_file_count()
click to toggle source
ディレクトリ以下のツリー全体でのファイル数
# File lib/store_agent/node/object/directory_object.rb, line 205 def tree_file_count metadata["tree_file_count"] end
unset_permission(identifier: nil, permission_names: [], recursive: false)
click to toggle source
Calls superclass method
StoreAgent::Node::Object#unset_permission
# File lib/store_agent/node/object/directory_object.rb, line 137 def unset_permission(identifier: nil, permission_names: [], recursive: false) super do if recursive success, errors = call_for_children do |child| child.unset_permission(identifier: identifier, permission_names: permission_names) end end end end
update()
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 50 def update raise "cannot update directory" end
Private Instance Methods
build_dest_directory(dest_path)
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 223 def build_dest_directory(dest_path) dest_object = workspace.find_object(dest_path) case when dest_object.file? raise InvalidNodeTypeError.new(src_object: self, dest_object: dest_object) when dest_object.directory? sub_directory_object = dest_object.find_object(File.basename(path)) if sub_directory_object.exists? raise InvalidPathError, "object already exists: #{sub_directory_object.path}" end dest_object.directory(File.basename(path)) else workspace.directory(dest_path) end end
call_for_children() { |child| ... }
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 245 def call_for_children errors = [] children.each do |child| begin yield child rescue StoreAgent::PermissionDeniedError => e errors << e end end return errors.empty?, errors end
current_children_filenames()
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 239 def current_children_filenames FileUtils.cd(storage_object_path) do return Dir.glob("*", File::FNM_DOTMATCH) end end
initial_bytesize()
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 219 def initial_bytesize File.size(storage_object_path) end
namespaced_absolute_path(path)
click to toggle source
# File lib/store_agent/node/object/directory_object.rb, line 215 def namespaced_absolute_path(path) "#{@path}#{sanitize_path(path)}" end