Class: StoreAgent::Node::DirectoryObject
- Defined in:
- lib/store_agent/node/object/directory_object.rb
Overview
ディレクトリ
Instance Attribute Summary
Attributes inherited from Object
Instance Method Summary collapse
-
#children ⇒ Object
現在のディレクトリの直下にあるオブジェクトの一覧を返す.
- #chown(identifier: nil, recursive: false) ⇒ Object
- #copy(dest_path = nil) ⇒ Object
- #create ⇒ Object
-
#default_metadata ⇒ Object
:nodoc:.
- #delete ⇒ Object
-
#directory(path) ⇒ Object
現在のパスからの相対パスで、ディレクトリオブジェクトのインスタンスを返す.
-
#directory? ⇒ Boolean
:nodoc:.
-
#directory_file_count ⇒ Object
ディレクトリ直下にあるファイル数.
-
#directory_metadata ⇒ Object
:nodoc:.
-
#file(path) ⇒ Object
現在のパスからの相対パスで、ファイルオブジェクトのインスタンスを返す.
-
#find_object(path) ⇒ Object
引数を現在のパスからの相対パスとして解釈し、オブジェクトのインスタンスを返す.
-
#get_metadata ⇒ Object
:nodoc:.
-
#get_permissions ⇒ Object
:nodoc:.
-
#initialize(params) ⇒ DirectoryObject
constructor
:nodoc:.
- #move(dest_path = nil) ⇒ Object
- #read(revision: nil) ⇒ Object
- #set_permission(identifier: nil, permission_values: {}, recursive: false) ⇒ Object
- #touch(recursive: false) ⇒ Object
-
#tree_file_count ⇒ Object
ディレクトリ以下のツリー全体でのファイル数.
- #unset_permission(identifier: nil, permission_names: [], recursive: false) ⇒ Object
- #update ⇒ Object
-
#virtual(path) ⇒ Object
:nodoc:.
Methods inherited from Object
#exists?, #file?, #filetype, #initial_metadata, #initial_owner, #initial_owner=, #initial_permission, #initial_permission=, #metadata, #parent_directory, #permission, #revisions, #root?, #storage_object_path
Methods included from Validator
#validates_to_be_excluded_slash!, #validates_to_be_not_guest_identifier!, #validates_to_be_not_nil_value!, #validates_to_be_not_superuser_identifier!, #validates_to_be_string_or_symbol!
Constructor Details
#initialize(params) ⇒ DirectoryObject
:nodoc:
21 22 23 24 25 26 |
# File 'lib/store_agent/node/object/directory_object.rb', line 21 def initialize(params) # :nodoc: super if !@path.end_with?("/") @path = "#{@path}/" end end |
Instance Method Details
#children ⇒ Object
現在のディレクトリの直下にあるオブジェクトの一覧を返す
177 178 179 180 181 |
# 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) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
80 81 82 83 84 85 86 87 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 |
# 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 |
#default_metadata ⇒ Object
:nodoc:
183 184 185 |
# File 'lib/store_agent/node/object/directory_object.rb', line 183 def # :nodoc: super.merge() end |
#delete ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
現在のパスからの相対パスで、ディレクトリオブジェクトのインスタンスを返す
167 168 169 |
# 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? ⇒ Boolean
:nodoc:
209 210 211 |
# File 'lib/store_agent/node/object/directory_object.rb', line 209 def directory? # :nodoc: true end |
#directory_file_count ⇒ Object
ディレクトリ直下にあるファイル数
200 201 202 |
# File 'lib/store_agent/node/object/directory_object.rb', line 200 def directory_file_count ["directory_file_count"] end |
#directory_metadata ⇒ Object
:nodoc:
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/store_agent/node/object/directory_object.rb', line 187 def # :nodoc: { "is_dir" => true, "directory_size" => StoreAgent::Node::Metadata.datasize_format(initial_bytesize), "directory_bytes" => initial_bytesize, "directory_size_limit" => StoreAgent::Node::Metadata.datasize_format(StoreAgent.config.default_directory_bytesize_limit), "directory_bytes_limit" => StoreAgent.config.default_directory_bytesize_limit, "directory_file_count" => 0, "tree_file_count" => 0 } end |
#file(path) ⇒ Object
現在のパスからの相対パスで、ファイルオブジェクトのインスタンスを返す
172 173 174 |
# 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) ⇒ Object
引数を現在のパスからの相対パスとして解釈し、オブジェクトのインスタンスを返す
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# 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 |
#get_metadata ⇒ Object
:nodoc:
107 108 109 110 |
# File 'lib/store_agent/node/object/directory_object.rb', line 107 def (*) # :nodoc: super do end end |
#get_permissions ⇒ Object
:nodoc:
112 113 114 115 |
# File 'lib/store_agent/node/object/directory_object.rb', line 112 def (*) # :nodoc: super do end end |
#move(dest_path = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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 = .disk_usage file_count = directory_file_count FileUtils.mv(storage_object_path, dest_directory.storage_object_path) FileUtils.mv(.base_path, dest_directory..base_path) FileUtils.mv(.base_path, dest_directory..base_path) dest_directory.touch(recursive: true) dest_directory.parent_directory..update(disk_usage: disk_usage, directory_file_count: 1, tree_file_count: file_count + 1, recursive: true) parent_directory..update(disk_usage: -disk_usage, directory_file_count: -1, tree_file_count: -(file_count + 1), recursive: true) [storage_object_path, .base_path, .base_path].each do |dir_path| workspace.version_manager.remove(dir_path, directory: true) end end end |
#read(revision: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/store_agent/node/object/directory_object.rb', line 127 def (identifier: nil, permission_values: {}, recursive: false) super do if recursive success, errors = call_for_children do |child| child.(identifier: identifier, permission_values: ) end end end end |
#touch(recursive: false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
ディレクトリ以下のツリー全体でのファイル数
205 206 207 |
# File 'lib/store_agent/node/object/directory_object.rb', line 205 def tree_file_count ["tree_file_count"] end |
#unset_permission(identifier: nil, permission_names: [], recursive: false) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/store_agent/node/object/directory_object.rb', line 137 def (identifier: nil, permission_names: [], recursive: false) super do if recursive success, errors = call_for_children do |child| child.(identifier: identifier, permission_names: ) end end end end |
#update ⇒ Object
50 51 52 |
# File 'lib/store_agent/node/object/directory_object.rb', line 50 def update raise "cannot update directory" end |
#virtual(path) ⇒ Object
:nodoc:
162 163 164 |
# File 'lib/store_agent/node/object/directory_object.rb', line 162 def virtual(path) # :nodoc: StoreAgent::Node::VirtualObject.new(workspace: workspace, path: namespaced_absolute_path(path)) end |