class Ole::Storage::RangesIOMigrateable

like RangesIOResizeable, but Ole::Storage::Dirent specific. provides for migration between bats based on size, and updating the dirent.

Attributes

dirent[R]

Public Class Methods

new(dirent, mode='r') click to toggle source
# File lib/ole/storage/base.rb, line 634
def initialize dirent, mode='r'
  @dirent = dirent
  super @dirent.ole.bat_for_size(@dirent.size), mode,
    :first_block => @dirent.first_block, :size => @dirent.size
end

Public Instance Methods

first_block() click to toggle source

forward this to the dirent

# File lib/ole/storage/base.rb, line 669
def first_block
  @dirent.first_block
end
first_block=(val) click to toggle source
# File lib/ole/storage/base.rb, line 673
def first_block= val
  @dirent.first_block = val
end
truncate(size) click to toggle source
# File lib/ole/storage/base.rb, line 640
def truncate size
  bat = @dirent.ole.bat_for_size size
  if bat.class != @bat.class
    # bat migration needed! we need to backup some data. the amount of data
    # should be <= @ole.header.threshold, so we can just hold it all in one buffer.
    # backup this
    pos = [@pos, size].min
    self.pos = 0
    keep = read [@size, size].min
    # this does a normal truncate to 0, removing our presence from the old bat, and
    # rewrite the dirent's first_block
    super 0
    @bat = bat
    # just change the underlying io from right under everyone :)
    @io = bat.io
    # important to do this now, before the write. as the below write will always
    # migrate us back to sbat! this will now allocate us +size+ in the new bat.
    super
    self.pos = 0
    write keep
    self.pos = pos
  else
    super
  end
  # now just update the file
  @dirent.size = size
end