Class: FDB::DirectoryLayer
- Inherits:
-
Object
- Object
- FDB::DirectoryLayer
- Defined in:
- lib/fdbdirectory.rb
Constant Summary collapse
- @@SUBDIRS =
0
- @@VERSION =
[1,0,0]
Instance Attribute Summary collapse
- #path ⇒ Object readonly
Instance Method Summary collapse
- #create(db_or_tr, path, options = {}) ⇒ Object
- #create_or_open(db_or_tr, path, options = {}) ⇒ Object
- #exists?(db_or_tr, path = []) ⇒ Boolean
-
#initialize(options = {}) ⇒ DirectoryLayer
constructor
A new instance of DirectoryLayer.
- #layer ⇒ Object
- #list(db_or_tr, path = []) ⇒ Object
- #move(db_or_tr, old_path, new_path) ⇒ Object
- #move_to(db_or_tr, new_absolute_path) ⇒ Object
- #open(db_or_tr, path, options = {}) ⇒ Object
- #remove(db_or_tr, path = []) ⇒ Object
- #remove_if_exists(db_or_tr, path = []) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DirectoryLayer
Returns a new instance of DirectoryLayer.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/fdbdirectory.rb', line 146 def initialize(={}) defaults = { :node_subspace => Subspace.new([], "\xfe"), :content_subspace =>Subspace.new, :allow_manual_prefixes => false } = defaults.merge() @content_subspace = [:content_subspace] @node_subspace = [:node_subspace] @allow_manual_prefixes = [:allow_manual_prefixes] @root_node = @node_subspace[@node_subspace.key] @allocator = HighContentionAllocator.new(@root_node['hca']) @path = [] @layer = '' end |
Instance Attribute Details
#path ⇒ Object
164 165 166 |
# File 'lib/fdbdirectory.rb', line 164 def path return @path.dup end |
Instance Method Details
#create(db_or_tr, path, options = {}) ⇒ Object
183 184 185 |
# File 'lib/fdbdirectory.rb', line 183 def create(db_or_tr, path, ={}) create_or_open_internal(db_or_tr, path, true, false, ) end |
#create_or_open(db_or_tr, path, options = {}) ⇒ Object
175 176 177 |
# File 'lib/fdbdirectory.rb', line 175 def create_or_open(db_or_tr, path, ={}) create_or_open_internal(db_or_tr, path, true, true, ) end |
#exists?(db_or_tr, path = []) ⇒ Boolean
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/fdbdirectory.rb', line 264 def exists?(db_or_tr, path=[]) db_or_tr.transact do |tr| check_version(tr, false) path = to_unicode_path(path) node = find(tr, path).(tr) next false if !node.exists? if node.is_in_partition? next node.get_contents(self).exists?(tr, node.get_partition_subpath) end true end end |
#layer ⇒ Object
168 169 170 |
# File 'lib/fdbdirectory.rb', line 168 def layer return @layer.dup end |
#list(db_or_tr, path = []) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/fdbdirectory.rb', line 247 def list(db_or_tr, path=[]) db_or_tr.transact do |tr| check_version(tr, false) path = to_unicode_path(path) node = find(tr, path).(tr) raise ArgumentError, 'The directory does not exist.' unless node.exists? if node.is_in_partition?(nil, true) next node.get_contents(self).list(tr, node.get_partition_subpath) end subdir_names_and_nodes(tr, node.subspace).map { |name, node| name } end end |
#move(db_or_tr, old_path, new_path) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/fdbdirectory.rb', line 191 def move(db_or_tr, old_path, new_path) db_or_tr.transact do |tr| check_version(tr, true) old_path = to_unicode_path(old_path) new_path = to_unicode_path(new_path) if old_path == new_path[0...old_path.length] raise ArgumentError, 'The desination directory cannot be a subdirectory of the source directory.' end old_node = find(tr, old_path).(tr) new_node = find(tr, new_path).(tr) raise ArgumentError, 'The source directory does not exist.' unless old_node.exists? if old_node.is_in_partition? || new_node.is_in_partition? if !old_node.is_in_partition? || !new_node.is_in_partition? || old_node.path != new_node.path then raise ArgumentError, 'Cannot move between partitions' end next new_node .get_contents(self) .move(tr, old_node.get_partition_subpath, new_node.get_partition_subpath) end if new_node.exists? raise ArgumentError, 'The destination directory already exists. Remove it first.' end parent_node = find(tr, new_path[0...-1]) if !parent_node.exists? raise ArgumentError, 'The parent directory of the destination directory does not exist. Create it first.' end tr[parent_node.subspace[@@SUBDIRS][new_path[-1]]] = @node_subspace.unpack(old_node.subspace.key)[0] remove_from_parent(tr, old_path) contents_of_node(old_node.subspace, new_path, old_node.layer) end end |
#move_to(db_or_tr, new_absolute_path) ⇒ Object
187 188 189 |
# File 'lib/fdbdirectory.rb', line 187 def move_to(db_or_tr, new_absolute_path) raise 'The root directory cannot be moved.' end |
#open(db_or_tr, path, options = {}) ⇒ Object
179 180 181 |
# File 'lib/fdbdirectory.rb', line 179 def open(db_or_tr, path, ={}) create_or_open_internal(db_or_tr, path, false, true, ) end |
#remove(db_or_tr, path = []) ⇒ Object
239 240 241 |
# File 'lib/fdbdirectory.rb', line 239 def remove(db_or_tr, path=[]) remove_internal(db_or_tr, path, true) end |
#remove_if_exists(db_or_tr, path = []) ⇒ Object
243 244 245 |
# File 'lib/fdbdirectory.rb', line 243 def remove_if_exists(db_or_tr, path=[]) remove_internal(db_or_tr, path, false) end |