Пример #1
0
 def write(self, ctx):
   """
   Write the info of the current dir to database
   """
   packer = PackerStream.PackerOStream(self.backup, Container.CODE_DIR)
   # sorting is an optimization to make everybody access files in the same
   # order.
   # TODO: measure if this really makes things faster
   # (probably will with a btree db)
   for child in self.children:
     Format.write_int(packer, child.get_type())
     Format.write_string(packer, child.get_name().encode('utf8'))
     packer.write(child.get_digest())
     packer.write(IntegerEncodings.binary_encode_int_varlen(child.get_level()))
     stats_str = serialize_stats(child.get_stats())
     packer.write(stats_str)
   
   self.digest = packer.get_digest()
   self.level = packer.get_level()
   return (packer.get_num_new_blocks(), packer.get_size_new_blocks())
Пример #2
0
def serialize_stats(stats):
  file = StringIO.StringIO()
  for mode in STAT_PRESERVED_MODES:
    Format.write_int(file, stats[mode])
  return file.getvalue()