Beispiel #1
0
int
lr_yum_download_repomd(lr_Handle handle,
                       lr_Metalink metalink,
                       int fd)
{
    int rc = LRE_OK;
    lr_ChecksumType checksum_type = LR_CHECKSUM_UNKNOWN;
    char *checksum = NULL;


    DPRINTF("%s: Downloading repomd.xml via mirrorlist\n", __func__);

    if (metalink && (handle->checks & LR_CHECK_CHECKSUM)) {
        /* Select the best checksum type */
        for (int x = 0; x < metalink->noh; x++) {
            lr_ChecksumType mtype;
            lr_MetalinkHash mhash = metalink->hashes[x];

            if (!mhash->type || !mhash->value)
                continue;

            mtype = lr_checksum_type(mhash->type);
            if (mtype != LR_CHECKSUM_UNKNOWN && mtype > checksum_type) {
                checksum_type = mtype;
                checksum = mhash->value;
            }
        }

        DPRINTF("%s: selected repomd.xml checksum to check: (%s) %s\n",
                __func__, lr_checksum_type_to_str(checksum_type), checksum);
    }

    rc = lr_curl_single_mirrored_download(handle,
                                          "repodata/repomd.xml",
                                          fd,
                                          checksum_type,
                                          checksum);

    if (rc != LRE_OK) {
        /* Download of repomd.xml was not successful */
        DPRINTF("%s: repomd.xml download was unsuccessful\n", __func__);
        return rc;
    }

    return LRE_OK;
}
Beispiel #2
0
static gboolean
lr_yum_download_repomd(LrHandle *handle,
                       LrMetalink *metalink,
                       int fd,
                       GError **err)
{
    int ret = TRUE;
    GError *tmp_err = NULL;

    assert(!err || *err == NULL);

    g_debug("%s: Downloading repomd.xml via mirrorlist", __func__);

    GSList *checksums = NULL;
    if (metalink && (handle->checks & LR_CHECK_CHECKSUM)) {
        // Select best checksum

        gboolean ret;
        LrChecksumType ch_type;
        gchar *ch_value;

        // From the metalink itself
        ret = lr_best_checksum(metalink->hashes, &ch_type, &ch_value);
        if (ret) {
            LrDownloadTargetChecksum *dtch;
            dtch = lr_downloadtargetchecksum_new(ch_type, ch_value);
            checksums = g_slist_prepend(checksums, dtch);
            g_debug("%s: Expected checksum for repomd.xml: (%s) %s",
                    __func__, lr_checksum_type_to_str(ch_type), ch_value);
        }

        // From the alternates entries
        for (GSList *elem = metalink->alternates; elem; elem = g_slist_next(elem)) {
            LrMetalinkAlternate *alt = elem->data;
            ret = lr_best_checksum(alt->hashes, &ch_type, &ch_value);
            if (ret) {
                LrDownloadTargetChecksum *dtch;
                dtch = lr_downloadtargetchecksum_new(ch_type, ch_value);
                checksums = g_slist_prepend(checksums, dtch);
                g_debug("%s: Expected alternate checksum for repomd.xml: (%s) %s",
                        __func__, lr_checksum_type_to_str(ch_type), ch_value);
            }
        }
    }

    CbData *cbdata = NULL;
    if (handle->hmfcb) {
        cbdata = cbdata_new(handle->user_data,
                            NULL,
                            handle->hmfcb,
                            "repomd.xml");
    }

    LrDownloadTarget *target = lr_downloadtarget_new(handle,
                                                     "repodata/repomd.xml",
                                                     NULL,
                                                     fd,
                                                     NULL,
                                                     checksums,
                                                     0,
                                                     0,
                                                     NULL,
                                                     cbdata,
                                                     NULL,
                                                     (cbdata) ? hmfcb : NULL,
                                                     NULL,
                                                     0,
                                                     0);

    ret = lr_download_target(target, &tmp_err);
    assert((ret && !tmp_err) || (!ret && tmp_err));

    if (cbdata)
        cbdata_free(cbdata);

    if (tmp_err) {
        g_propagate_prefixed_error(err, tmp_err,
                                   "Cannot download repomd.xml: ");
    } else if (target->err) {
        assert(0); // This should not happen since failfast should be TRUE
        ret = FALSE;
        g_set_error(err, LR_DOWNLOADER_ERROR, target->rcode,
                    "Cannot download repomd.xml: %s",target->err);
    } else {
        // Set mirror used for download a repomd.xml to the handle
        // TODO: Get rid of use_mirror attr
        lr_free(handle->used_mirror);
        handle->used_mirror = g_strdup(target->usedmirror);
    }

    lr_downloadtarget_free(target);

    if (!ret) {
        /* Download of repomd.xml was not successful */
        g_debug("%s: repomd.xml download was unsuccessful", __func__);
    }

    return ret;
}