def chdir(patch, path):
    """Change the current working directory to path."""
    global CWD
    ap = os.path.abspath(os.path.join(CWD, path))
    manager = get_manager()
    fsi, relpath, readonly = manager.get_fsi(ap)
    if fsi is None:
        if not os.path.exists(ap):
            raise os.error("[Errno 2] No such file or directory: '/{p}/'".format(p=path))
        elif not os.path.isdir(ap):
            raise os.error("[Errno 20] Not a directory: '{p}'".format(p=path))
        else:
            CWD = ap
            _org_chdir(ap)
            # reset paths
            for p, fs, readonly in manager.get_mounts():
                try:
                    fs.cd("/")
                except:
                    pass
    else:
        try:
            fsi.cd(relpath)
            CWD = ap
        except IsFile:
            raise os.error("[Errno 20] Not a directory: '{p}'".format(p=path))
        except OperationFailure:
            raise os.error("[Errno 2] No such file or directory: '/{p}/'".format(p=path))
Change the current working directory to path.
lib/mlpatches/mount_base.py