示例#1
0
 def read(port):
     # This method should either return a valid Metadata object,
     # return None if there was no information at all (just a
     # _rec_tag_end), throw EOFError if there was nothing at all to
     # read, or throw an Exception if a valid object could not be
     # read completely.
     tag = vint.read_vuint(port)
     if tag == _rec_tag_end:
         return None
     try: # From here on, EOF is an error.
         result = Metadata()
         while True: # only exit is error (exception) or _rec_tag_end
             if tag == _rec_tag_path:
                 result._load_path_rec(port)
             elif tag == _rec_tag_common:
                 result._load_common_rec(port)
             elif tag == _rec_tag_symlink_target:
                 result._load_symlink_target_rec(port)
             elif tag == _rec_tag_hardlink_target:
                 result._load_hardlink_target_rec(port)
             elif tag == _rec_tag_posix1e_acl:
                 result._load_posix1e_acl_rec(port)
             elif tag ==_rec_tag_nfsv4_acl:
                 result._load_nfsv4_acl_rec(port)
             elif tag == _rec_tag_linux_attr:
                 result._load_linux_attr_rec(port)
             elif tag == _rec_tag_linux_xattr:
                 result._load_linux_xattr_rec(port)
             elif tag == _rec_tag_end:
                 return result
             else: # unknown record
                 vint.skip_bvec(port)
             tag = vint.read_vuint(port)
     except EOFError:
         raise Exception("EOF while reading Metadata")
示例#2
0
 def read(port):
     # This method should either: return a valid Metadata object;
     # throw EOFError if there was nothing at all to read; throw an
     # Exception if a valid object could not be read completely.
     tag = vint.read_vuint(port)
     try: # From here on, EOF is an error.
         result = Metadata()
         while True: # only exit is error (exception) or _rec_tag_end
             if tag == _rec_tag_path:
                 result._load_path_rec(port)
             elif tag == _rec_tag_common:
                 result._load_common_rec(port)
             elif tag == _rec_tag_symlink_target:
                 result._load_symlink_target_rec(port)
             elif tag == _rec_tag_posix1e_acl:
                 result._load_posix1e_acl_rec(port)
             elif tag ==_rec_tag_nfsv4_acl:
                 result._load_nfsv4_acl_rec(port)
             elif tag == _rec_tag_linux_attr:
                 result._load_linux_attr_rec(port)
             elif tag == _rec_tag_linux_xattr:
                 result._load_linux_xattr_rec(port)
             elif tag == _rec_tag_end:
                 return result
             else: # unknown record
                 vint.skip_bvec(port)
             tag = vint.read_vuint(port)
     except EOFError:
         raise Exception("EOF while reading Metadata")
示例#3
0
 def read(port):
     # This method should either return a valid Metadata object,
     # return None if there was no information at all (just a
     # _rec_tag_end), throw EOFError if there was nothing at all to
     # read, or throw an Exception if a valid object could not be
     # read completely.
     tag = vint.read_vuint(port)
     if tag == _rec_tag_end:
         return None
     try:  # From here on, EOF is an error.
         result = Metadata()
         while True:  # only exit is error (exception) or _rec_tag_end
             if tag == _rec_tag_path:
                 result._load_path_rec(port)
             elif tag == _rec_tag_common_v2:
                 result._load_common_rec(port)
             elif tag == _rec_tag_symlink_target:
                 result._load_symlink_target_rec(port)
             elif tag == _rec_tag_hardlink_target:
                 result._load_hardlink_target_rec(port)
             elif tag == _rec_tag_posix1e_acl:
                 result._load_posix1e_acl_rec(port)
             elif tag == _rec_tag_linux_attr:
                 result._load_linux_attr_rec(port)
             elif tag == _rec_tag_linux_xattr:
                 result._load_linux_xattr_rec(port)
             elif tag == _rec_tag_end:
                 return result
             elif tag == _rec_tag_common:  # Should be very rare.
                 result._load_common_rec(port, legacy_format=True)
             else:  # unknown record
                 vint.skip_bvec(port)
             tag = vint.read_vuint(port)
     except EOFError:
         raise Exception("EOF while reading Metadata")
示例#4
0
 def _load_linux_xattr_rec(self, file):
     data = vint.read_bvec(file)
     memfile = BytesIO(data)
     result = []
     for i in range(vint.read_vuint(memfile)):
         key = vint.read_bvec(memfile)
         value = vint.read_bvec(memfile)
         result.append((key, value))
     self.linux_xattr = result
示例#5
0
 def _load_linux_xattr_rec(self, file):
     data = vint.read_bvec(file)
     memfile = StringIO(data)
     result = []
     for i in range(vint.read_vuint(memfile)):
         key = vint.read_bvec(memfile)
         value = vint.read_bvec(memfile)
         result.append((key, value))
     self.linux_xattr = result
示例#6
0
文件: vfs.py 项目: bup/bup
def read_resolution(port):
    n = read_vuint(port)
    result = []
    for i in range(n):
        name = read_bvec(port)
        have_item = ord(port.read(1))
        assert have_item in (0, 1)
        item = read_item(port) if have_item else None
        result.append((name, item))
    return tuple(result)
示例#7
0
文件: vfs.py 项目: NeatNerdPrime/bup
def read_resolution(port):
    n = read_vuint(port)
    result = []
    for i in range(n):
        name = read_bvec(port)
        have_item = ord(port.read(1))
        assert have_item in (0, 1)
        item = read_item(port) if have_item else None
        result.append((name, item))
    return tuple(result)
示例#8
0
def path_info(conn, junk):
    _init_session()
    n = vint.read_vuint(conn)
    paths = []
    for i in range(n):
        paths.append(vint.read_bvec(conn))
    result = vfs.path_info(paths, vfs.RefList(None))
    assert(len(result) == len(paths))
    for item in result:
        if item:
            name, id, type = item
            vint.write_bvec(conn, vint.pack('sss', name, id, type))
        else:
            vint.write_bvec(conn, '')
    conn.ok()
示例#9
0
 def read(self, offset=None):
     assert self.mode == 'r'
     self.offset = offset or self.headerlen
     self.file.seek(self.offset)
     vuint_cs = libnacl.crypto_stream(MAX_ENC_BLOB_VUINT_LEN,
                                      self.nonce(NONCE_LEN, write=False),
                                      self.box.sk)
     sz = read_vuint(
         EncryptedVuintReader(self.file, vuint_cs, self._blobsize))
     assert sz <= MAX_ENC_BLOB
     data = self.file.read(sz)
     assert len(data) == sz
     data = self.box.decrypt(data, self.nonce(NONCE_DATA, write=False))
     data = zlib.decompress(data)
     objtype = struct.unpack('B', data[:1])[0]
     return objtype, data[1:]
示例#10
0
文件: tvint.py 项目: dataReactive/bup
def encode_and_decode_vuint(x):
    f = BytesIO()
    vint.write_vuint(f, x)
    return vint.read_vuint(BytesIO(f.getvalue()))
示例#11
0
def encode_and_decode_vuint(x):
    f = BytesIO()
    vint.write_vuint(f, x)
    return vint.read_vuint(BytesIO(f.getvalue()))
示例#12
0
文件: vfs.py 项目: bup/bup
 def read_m(port, has_meta):
     if has_meta:
         m = Metadata.read(port)
         return m
     return read_vuint(port)
示例#13
0
文件: vfs.py 项目: bup/bup
def read_ioerror(port):
    mask = read_vuint(port)
    no = read_vint(port) if 1 & mask else None
    msg = read_bvec(port).decode('utf-8') if 2 & mask else None
    term = read_resolution(port) if 4 & mask else None
    return IOError(errno=no, message=msg, terminus=term)
示例#14
0
文件: vfs.py 项目: NeatNerdPrime/bup
def read_ioerror(port):
    mask = read_vuint(port)
    no = read_vint(port) if 1 & mask else None
    msg = read_bvec(port).decode('utf-8') if 2 & mask else None
    term = read_resolution(port) if 4 & mask else None
    return IOError(errno=no, message=msg, terminus=term)
示例#15
0
文件: tvint.py 项目: 3v/bup
def encode_and_decode_vuint(x):
    f = StringIO()
    vint.write_vuint(f, x)
    return vint.read_vuint(StringIO(f.getvalue()))
示例#16
0
文件: vfs.py 项目: NeatNerdPrime/bup
 def read_m(port, has_meta):
     if has_meta:
         m = Metadata.read(port)
         return m
     return read_vuint(port)
示例#17
0
def encode_and_decode_vuint(x):
    f = StringIO()
    vint.write_vuint(f, x)
    return vint.read_vuint(StringIO(f.getvalue()))