import time


def repo_list(client, repo_name, expected_count, repo_path=None):
    """
    Nexus doesn't show uploaded files when you list the contents immediately
    after an upload. This helper retries it 3 times with increasing back-off.
    """
    def _list():
        file_list = client.list(repo_name)

        files = []
        for f in iter(file_list):
            f = f[len(repo_path)+1:] if repo_path else f
            files.append(f)

        return files

    attempt = 1
    file_set = set(_list())
    while len(file_set) != expected_count and attempt < 4:
        attempt += 1
        time.sleep(2 * attempt)
        file_set = set(_list())

    # let it fail if we run out of attempts
    return file_set