def set_permissions_and_owner(tarinfo, permissions, uid=0, username='root'):
    """
    Sets the given permissions and owner for the given tarinfo.

    :param tarinfo: The tarinfo to set information for
    :type tarinfo: tarfile.Tarinfo
    :param permissions: The permission bits to set for the given tarinfo
    :param uid: The user id to set for the given tarinfo
    :param username: The owner of the given tarinfo
    """
    tarinfo.uid = uid
    tarinfo.gid = uid
    tarinfo.uname = username
    tarinfo.gname = username
    tarinfo.mode = permissions
