Class | Ole::Storage::RangesIOMigrateable |
In: |
lib/ole/storage/base.rb
|
Parent: | RangesIOResizeable |
like RangesIOResizeable, but Ole::Storage::Dirent specific. provides for migration between bats based on size, and updating the dirent.
dirent | [R] |
# File lib/ole/storage/base.rb, line 626 626: def initialize dirent, mode='r' 627: @dirent = dirent 628: super @dirent.ole.bat_for_size(@dirent.size), mode, 629: :first_block => @dirent.first_block, :size => @dirent.size 630: end
forward this to the dirent
# File lib/ole/storage/base.rb, line 661 661: def first_block 662: @dirent.first_block 663: end
# File lib/ole/storage/base.rb, line 665 665: def first_block= val 666: @dirent.first_block = val 667: end
# File lib/ole/storage/base.rb, line 632 632: def truncate size 633: bat = @dirent.ole.bat_for_size size 634: if bat.class != @bat.class 635: # bat migration needed! we need to backup some data. the amount of data 636: # should be <= @ole.header.threshold, so we can just hold it all in one buffer. 637: # backup this 638: pos = [@pos, size].min 639: self.pos = 0 640: keep = read [@size, size].min 641: # this does a normal truncate to 0, removing our presence from the old bat, and 642: # rewrite the dirent's first_block 643: super 0 644: @bat = bat 645: # just change the underlying io from right under everyone :) 646: @io = bat.io 647: # important to do this now, before the write. as the below write will always 648: # migrate us back to sbat! this will now allocate us +size+ in the new bat. 649: super 650: self.pos = 0 651: write keep 652: self.pos = pos 653: else 654: super 655: end 656: # now just update the file 657: @dirent.size = size 658: end