class Node
Constants
- CHUNK_SIZE
Public Instance Methods
content_size()
click to toggle source
selected_chunks[1...-1].each do |chunk| num = chunk.chunk_number - num_start chunk.content = buf[num*CHUNK_SIZE...(num+1)*CHUNK_SIZE] end end print "\n" selected_chunks.each do |chunk| rechunk = Chunk.find chunk.id rechunk.content = chunk.content.to_s print "set_content #{chunk.chunk_number} :: #{chunk.content}\n" rechunk.save! end print "\n" end
end
# File lib/gitroom/models/node.rb, line 175 def content_size if chunks.count == 0 0 else (chunks.count - 1) * CHUNK_SIZE + chunks.order('chunk_number asc').last.content.size end end
get_chunk(number, offset = 0, right = CHUNK_SIZE - 1)
click to toggle source
# File lib/gitroom/models/node.rb, line 43 def get_chunk(number, offset = 0, right = CHUNK_SIZE - 1) chunk = chunks.where(:chunk_number => number).first chunk && chunk.content[offset..right] || '' end
get_chunk_cached(chunk, offset = 0, right = CHUNK_SIZE - 1)
click to toggle source
# File lib/gitroom/models/node.rb, line 48 def get_chunk_cached(chunk, offset = 0, right = CHUNK_SIZE - 1) chunk && chunk.content[offset..right] || '' end
get_content(offset, size)
click to toggle source
# File lib/gitroom/models/node.rb, line 66 def get_content(offset, size) num_start = offset / CHUNK_SIZE offset_start = offset % CHUNK_SIZE num_end = (offset + size - 1) / CHUNK_SIZE offset_end = (offset + size - 1) % CHUNK_SIZE content = '' cached_chunks = chunks.where('chunk_number >= ? and chunk_number <= ?', num_start, num_end).order('chunk_number asc') # (num_start..num_end).to_a.each do |num| cached_chunks.each do |chunk| num = chunk.chunk_number offset = num == num_start ? offset_start : 0 right = num == num_end ? offset_end : (CHUNK_SIZE - 1) content += get_chunk_cached chunk, offset, right end content end
get_full_content()
click to toggle source
# File lib/gitroom/models/node.rb, line 83 def get_full_content chunks.order('chunk_number asc').pluck(:content).join end
getxattr(name)
click to toggle source
# File lib/gitroom/models/node.rb, line 23 def getxattr(name) JSON.parse(xattrs)[name] end
listxattr()
click to toggle source
# File lib/gitroom/models/node.rb, line 39 def listxattr JSON.parse(xattrs).keys end
removexattr(name)
click to toggle source
# File lib/gitroom/models/node.rb, line 33 def removexattr(name) json = JSON.parse(xattrs) json.delete name xattrs = json.to_s end
set_chunk(number, buf, offset = 0)
click to toggle source
# File lib/gitroom/models/node.rb, line 52 def set_chunk(number, buf, offset = 0) chunk = chunks.where(:chunk_number => number).first unless chunk chunk = chunks.create! :chunk_number => number, :node_id => id, :content => "" end if chunk.content.size < offset+buf.size chunk.content += "\0" * (offset + buf.size - chunk.content.size) end chunk.content[offset...offset+buf.size] = buf rechunk = Chunk.find chunk.id rechunk.content = chunk.content.to_s rechunk.save! end
set_content(offset, buf)
click to toggle source
# File lib/gitroom/models/node.rb, line 87 def set_content(offset, buf) size = buf.size num_start = offset / CHUNK_SIZE offset_start = offset % CHUNK_SIZE num_end = (offset + size - 1) / CHUNK_SIZE offset_end = (offset + size - 1) % CHUNK_SIZE (num_start..num_end).to_a.each do |num| offset = num == num_start ? offset_start : 0 data_offset = num == num_start ? 0 : ((num - num_start) * CHUNK_SIZE - offset_start) data_right = num == num_end ? -1 : (data_offset + CHUNK_SIZE - 1) set_chunk num, buf[data_offset..data_right], offset end buf.size end
setxattr(name, value, flag)
click to toggle source
# File lib/gitroom/models/node.rb, line 27 def setxattr(name, value, flag) json = JSON.parse(xattrs) json[name] = value xattrs = json.to_s end
stat()
click to toggle source
# File lib/gitroom/models/node.rb, line 13 def stat if directory RFuse::Stat.directory mode,:uid => uid, :gid => gid, :atime => updated_at, :mtime => updated_at, :size => 48 else RFuse::Stat.file mode,:uid => uid, :gid => gid, :atime => updated_at, :mtime => updated_at, :size => content_size end end
truncate_content(offset)
click to toggle source
# File lib/gitroom/models/node.rb, line 183 def truncate_content(offset) Chunk.transaction do num_end = (offset) / CHUNK_SIZE offset_end = (offset) % CHUNK_SIZE selected_chunks = chunks.where('chunk_number > ?', num_end) selected_chunks.each { |chunk| chunk.destroy } last_chunk = chunks.last last_chunk.content = last_chunk.content[0..offset_end] last_chunk.save end end