def METHOD_NAME(path, d):
    if os.path.exists(path):
        dst = shutil.move(path, d)
        try:
            yield dst
        finally:
            try:
                os.replace(dst, path)
            except OSError:  # no cov
                shutil.move(dst, path)
    else:
        try:
            yield
        finally:
            remove_path(path)