def resolve(self, path, parent=None, want_meta=True, follow=False): self._require_command(b'resolve') self.check_busy() self._busy = b'resolve' conn = self.conn conn.write(b'resolve %d\n' % ((1 if want_meta else 0) | (2 if follow else 0) | (4 if parent else 0))) if parent: vfs.write_resolution(conn, parent) write_bvec(conn, path) success = ord(conn.read(1)) assert success in (0, 1) if success: result = vfs.read_resolution(conn) else: result = vfs.read_ioerror(conn) # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy() if isinstance(result, vfs.IOError): raise result return result
def resolve(self, path, parent=None, want_meta=True, follow=False): self._require_command('resolve') self.check_busy() self._busy = 'resolve' conn = self.conn conn.write('resolve %d\n' % ((1 if want_meta else 0) | (2 if follow else 0) | (4 if parent else 0))) if parent: vfs.write_resolution(conn, parent) write_bvec(conn, path) success = ord(conn.read(1)) assert success in (0, 1) if success: result = vfs.read_resolution(conn) else: result = vfs.read_ioerror(conn) # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy() if isinstance(result, vfs.IOError): raise result return result
def write_resolution(port, resolution): write_vuint(port, len(resolution)) for name, item in resolution: write_bvec(port, name) if item: port.write(b'\x01') write_item(port, item) else: port.write(b'\x00')
def write_resolution(port, resolution): write_vuint(port, len(resolution)) for name, item in resolution: write_bvec(port, name) if item: port.write(b'\1') write_item(port, item) else: port.write(b'\0')
def write_ioerror(port, ex): assert isinstance(ex, IOError) write_vuint(port, (1 if ex.errno is not None else 0) | (2 if ex.strerror is not None else 0) | (4 if ex.terminus is not None else 0)) if ex.errno is not None: write_vint(port, ex.errno) if ex.strerror is not None: write_bvec(port, ex.strerror.encode('utf-8')) if ex.terminus is not None: write_resolution(port, ex.terminus)
def write(self, port, include_path=True): records = include_path and [(_rec_tag_path, self._encode_path())] or [] records.extend([(_rec_tag_common, self._encode_common()), (_rec_tag_symlink_target, self._encode_symlink_target()), (_rec_tag_posix1e_acl, self._encode_posix1e_acl()), (_rec_tag_linux_attr, self._encode_linux_attr()), (_rec_tag_linux_xattr, self._encode_linux_xattr())]) for tag, data in records: if data: vint.write_vuint(port, tag) vint.write_bvec(port, data) vint.write_vuint(port, _rec_tag_end)
def write_ioerror(port, ex): assert isinstance(ex, IOError) write_vuint(port, (1 if ex.errno is not None else 0) | (2 if ex.message is not None else 0) | (4 if ex.terminus is not None else 0)) if ex.errno is not None: write_vint(port, ex.errno) if ex.message is not None: write_bvec(port, ex.message.encode('utf-8')) if ex.terminus is not None: write_resolution(port, ex.terminus)
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(): 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(): 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 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 encode_and_decode_bvec(x): f = StringIO() vint.write_bvec(f, x) return vint.read_bvec(StringIO(f.getvalue()))
def encode_and_decode_bvec(x): f = BytesIO() vint.write_bvec(f, x) return vint.read_bvec(BytesIO(f.getvalue()))