Beispiel #1
0
    def cloned(self) -> ContextManager['FS']:
        """
        Create a copy of this FS, emulating what happens after fork.
        """

        client = SyncClient(self.client.path)
        client.start()
        try:
            fs = FS(client=client, root_mount=self.root_mount)
            for fd, handle in self.handles.items():
                fs._clone_handle(fd, handle)
            yield fs
        finally:
            client.stop()
Beispiel #2
0
def main():
    demos = {
        'simple': simple,
        'append': append,
        'shared_handle': shared_handle,
    }

    if len(sys.argv) != 2 or sys.argv[1] not in demos:
        print(f'Usage: {sys.argv[0]} demo_name')
        print('Demo names:', ', '.join(demos.keys()))
        print('(read demo.py for details)')
        sys.exit(1)

    demo = demos[sys.argv[1]]

    setup_logging()

    temp_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tmp')
    shutil.rmtree(temp_dir)
    os.mkdir(temp_dir)
    socket_path = temp_dir + '/server.sock'

    with ExitStack() as exit:
        # Start server
        server = SyncServer(socket_path)
        server_thread = Thread(name='Server', target=server.run)
        server_thread.start()
        exit.callback(server_thread.join)
        exit.callback(server.socket_server.shutdown)

        # Start client
        client = SyncClient(socket_path)
        client.start()
        exit.callback(client.stop)

        # Create objects
        mount = Mount('tmp', temp_dir)
        fs = FS(client, mount)

        # Run demo
        demo(fs)
Beispiel #3
0
                handle.sync.data = handle.pos
                handle.sync.modified = True
        return result

    @trace
    def stat(self, path: str):
        with self._find_dentry(path) as dentry:
            if dentry.file_type is None:
                return None
            return {
                'type': dentry.file_type.name,
                'size': dentry.size,
            }

    @trace
    def seek(self, fd: int, pos: int):
        handle = self.handles[fd]
        with handle.sync.use(shared=False):
            handle.pos = pos
            handle.sync.data = pos
            handle.sync.modified = True


if __name__ == '__main__':
    setup_logging()

    client = SyncClient('server.sock')
    client.start()
    mount = Mount('tmp', '/tmp/demo')
    fs = FS(client, mount)