def read_item(port): def read_m(port, has_meta): if has_meta: m = Metadata.read(port) return m return read_vuint(port) kind, has_meta = vint.recv(port, 'sV') if kind == b'Item': oid, meta = read_bvec(port), read_m(port, has_meta) return Item(oid=oid, meta=meta) if kind == b'Chunky': oid, meta = read_bvec(port), read_m(port, has_meta) return Chunky(oid=oid, meta=meta) if kind == b'RevList': oid, meta = read_bvec(port), read_m(port, has_meta) return RevList(oid=oid, meta=meta) if kind == b'Root': return Root(meta=read_m(port, has_meta)) if kind == b'Tags': return Tags(meta=read_m(port, has_meta)) if kind == b'Commit': oid, coid = vint.recv(port, 'ss') meta = read_m(port, has_meta) return Commit(oid=oid, coid=coid, meta=meta) if kind == b'FakeLink': target, meta = read_bvec(port), read_m(port, has_meta) return FakeLink(target=target, meta=meta) assert False
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
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
def test_bvec(): values = ('', 'x', 'foo', '\0', '\0foo', 'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, BytesIO()) outf = BytesIO() for x in ('foo', 'bar', 'baz', 'bax'): vint.write_bvec(outf, x) inf = BytesIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), 'foo') WVPASSEQ(vint.read_bvec(inf), 'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), 'bax')
def test_bvec(): values = ('', 'x', 'foo', '\0', '\0foo', 'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, StringIO()) outf = StringIO() for x in ('foo', 'bar', 'baz', 'bax'): vint.write_bvec(outf, x) inf = StringIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), 'foo') WVPASSEQ(vint.read_bvec(inf), 'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), 'bax')
def test_bvec(): with no_lingering_errors(): values = (b'', b'x', b'foo', b'\0', b'\0foo', b'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, BytesIO()) outf = BytesIO() for x in (b'foo', b'bar', b'baz', b'bax'): vint.write_bvec(outf, x) inf = BytesIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), b'foo') WVPASSEQ(vint.read_bvec(inf), b'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), b'bax')
def _load_posix1e_acl_rec(self, port): if not posix1e: return data = vint.read_bvec(port) acl_reps = vint.unpack('ssss', data) if acl_reps[2] == '': acl_reps = acl_reps[:2] self.posix1e_acl = [posix1e.ACL(text=x) for x in acl_reps]
def resolve(conn, args): _init_session() (flags, ) = args.split() flags = int(flags) want_meta = bool(flags & 1) follow = bool(flags & 2) have_parent = bool(flags & 4) parent = vfs.read_resolution(conn) if have_parent else None path = vint.read_bvec(conn) if not len(path): raise Exception('Empty resolve path') try: res = list( vfs.resolve(repo, path, parent=parent, want_meta=want_meta, follow=follow)) except vfs.IOError as ex: res = ex if isinstance(res, vfs.IOError): conn.write(b'\x00') # error vfs.write_ioerror(conn, res) else: conn.write(b'\x01') # success vfs.write_resolution(conn, res) conn.ok()
def _load_common_rec(self, port, version=3): if version == 3: # Added trailing size to v2, negative when None. unpack_fmt = 'vvsvsvvVvVvVv' elif version == 2: unpack_fmt = 'vvsvsvvVvVvV' elif version == 1: unpack_fmt = 'VVsVsVvVvVvV' else: raise Exception('unexpected common_rec version %d' % version) data = vint.read_bvec(port) values = vint.unpack(unpack_fmt, data) if version == 3: (self.mode, self.uid, self.user, self.gid, self.group, self.rdev, self.atime, atime_ns, self.mtime, mtime_ns, self.ctime, ctime_ns, size) = values if size >= 0: self.size = size else: (self.mode, self.uid, self.user, self.gid, self.group, self.rdev, self.atime, atime_ns, self.mtime, mtime_ns, self.ctime, ctime_ns) = values self.atime = xstat.timespec_to_nsecs((self.atime, atime_ns)) self.mtime = xstat.timespec_to_nsecs((self.mtime, mtime_ns)) self.ctime = xstat.timespec_to_nsecs((self.ctime, ctime_ns))
def _load_symlink_target_rec(self, port): target = vint.read_bvec(port) self.symlink_target = target if self.size is None: self.size = len(target) else: assert(self.size == len(target))
def _load_common_rec(self, port): data = vint.read_bvec(port) (self.mode, self.uid, self.user, self.gid, self.group, self.rdev, self.atime, atime_ns, self.mtime, mtime_ns, self.ctime, ctime_ns) = vint.unpack('VVsVsVvVvVvV', data) self.atime = xstat.timespec_to_nsecs((self.atime, atime_ns)) self.mtime = xstat.timespec_to_nsecs((self.mtime, mtime_ns)) self.ctime = xstat.timespec_to_nsecs((self.ctime, ctime_ns))
def _load_common_rec(self, port): data = vint.read_bvec(port) (self.mode, self.uid, self.owner, self.gid, self.group, self.rdev, self.atime, atime_ns, self.mtime, mtime_ns, self.ctime, ctime_ns) = vint.unpack('VVsVsVvVvVvV', data) self.atime = FSTime.from_timespec((self.atime, atime_ns)) self.mtime = FSTime.from_timespec((self.mtime, mtime_ns)) self.ctime = FSTime.from_timespec((self.ctime, ctime_ns))
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)
def _load_common_rec(self, port, legacy_format=False): unpack_fmt = 'vvsvsvvVvVvV' if legacy_format: unpack_fmt = 'VVsVsVvVvVvV' data = vint.read_bvec(port) (self.mode, self.uid, self.user, self.gid, self.group, self.rdev, self.atime, atime_ns, self.mtime, mtime_ns, self.ctime, ctime_ns) = vint.unpack(unpack_fmt, data) self.atime = xstat.timespec_to_nsecs((self.atime, atime_ns)) self.mtime = xstat.timespec_to_nsecs((self.mtime, mtime_ns)) self.ctime = xstat.timespec_to_nsecs((self.ctime, ctime_ns))
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()
def path_info(self, paths): self.check_busy() self.conn.write('path-info\n') if not isinstance(paths, list): # FIXME: check for "not oneshot". paths = list(paths) vint.write_vuint(self.conn, len(paths)) for path in paths: vint.write_bvec(self.conn, path) result = [] for path in paths: data = vint.read_bvec(self.conn) if data: result.append(vint.unpack('sss', data)) else: result.append(None) self.check_ok() return result
def resolve(self, args): self.init_session() (flags, ) = args.split() flags = int(flags) want_meta = bool(flags & 1) follow = bool(flags & 2) have_parent = bool(flags & 4) parent = read_resolution(self.conn) if have_parent else None path = read_bvec(self.conn) if not len(path): raise Exception('Empty resolve path') try: res = list(self.repo.resolve(path, parent, want_meta, follow)) except vfs.IOError as ex: res = ex if isinstance(res, vfs.IOError): self.conn.write(b'\0') # error write_ioerror(self.conn, res) else: self.conn.write(b'\1') # success write_resolution(self.conn, res) self.conn.ok()
def _load_path_rec(self, port): self.path = vint.unpack("s", vint.read_bvec(port))[0]
def encode_and_decode_bvec(x): f = BytesIO() vint.write_bvec(f, x) return vint.read_bvec(BytesIO(f.getvalue()))
def _load_linux_attr_rec(self, port): data = vint.read_bvec(port) self.linux_attr = vint.unpack('V', data)[0]
def _load_posix1e_acl_rec(self, port): acl_rep = vint.unpack('ssss', vint.read_bvec(port)) if acl_rep[2] == b'': acl_rep = acl_rep[:2] self.posix1e_acl = acl_rep
def _load_hardlink_target_rec(self, port): self.hardlink_target = vint.read_bvec(port)
def _load_posix1e_acl_rec(self, port): data = vint.read_bvec(port) acl_reps = vint.unpack("ssss", data) if acl_reps[2] == "": acl_reps = acl_reps[:2] self.posix1e_acl = [posix1e.ACL(text=x) for x in acl_reps]
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)
def encode_and_decode_bvec(x): f = StringIO() vint.write_bvec(f, x) return vint.read_bvec(StringIO(f.getvalue()))
def _load_posix1e_acl_rec(self, port): acl_rep = vint.unpack("ssss", vint.read_bvec(port)) if acl_rep[2] == "": acl_rep = acl_rep[:2] self.posix1e_acl = acl_rep
def _load_posix1e_acl_rec(self, port): data = vint.read_bvec(port) acl_reps = vint.unpack('ssss', data) if acl_reps[2] == '': acl_reps = acl_reps[:2] self.posix1e_acl = [posix1e.ACL(text=x) for x in acl_reps]
def _load_symlink_target_rec(self, port): self.symlink_target = vint.read_bvec(port)
def _load_linux_attr_rec(self, port): data = vint.read_bvec(port) self.linux_attr = vint.unpack("V", data)[0]
def _load_symlink_target_rec(self, port): target = vint.read_bvec(port) self.symlink_target = target self.size = len(target)
def _load_path_rec(self, port): self.path = vint.unpack('s', vint.read_bvec(port))[0]