Ejemplo n.º 1
0
Archivo: repo.c Proyecto: toliaqat/tdnf
uint32_t
TDNFInitRepoFromMetaData(
    HyRepo hRepo,
    LrYumRepo* pRepo
    )
{
    uint32_t dwError = 0;
    const char* pszValue = NULL;
    
    if(!pRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    hy_repo_set_string(hRepo, HY_REPO_MD_FN, pRepo->repomd);
    pszValue = lr_yum_repo_path(pRepo, "primary");
    if(pszValue)
    {
        hy_repo_set_string(hRepo, HY_REPO_PRIMARY_FN, pszValue);
    }
    pszValue = lr_yum_repo_path(pRepo, "filelists");
    if(pszValue != NULL)
    {
        hy_repo_set_string(hRepo, HY_REPO_FILELISTS_FN, pszValue);
    }
    pszValue = lr_yum_repo_path(pRepo, "updateinfo");
    if(pszValue != NULL)
    {
        hy_repo_set_string (hRepo, HY_REPO_UPDATEINFO_FN, pszValue);
    }

cleanup:
    return dwError;

error:
    goto cleanup;
}
Ejemplo n.º 2
0
int
lr_yum_check_repo_checksums(lr_YumRepo repo, lr_YumRepoMd repomd)
{
    for (int x=0; x < repomd->nor; x++) {
        int ret;
        lr_YumRepoMdRecord record  = repomd->records[x];
        char *path = lr_yum_repo_path(repo, record->type);
        ret = lr_yum_check_checksum_of_md_record(record, path);
        DPRINTF("%s: Checksum rc: %d (%s)\n", __func__, ret, record->type);
        if (ret != LRE_OK)
            return ret;
    }

    return LRE_OK;
}
Ejemplo n.º 3
0
static gboolean
lr_yum_check_repo_checksums(LrYumRepo *repo,
                            LrYumRepoMd *repomd,
                            GError **err)
{
    assert(!err || *err == NULL);

    for (GSList *elem = repomd->records; elem; elem = g_slist_next(elem)) {
        gboolean ret;
        LrYumRepoMdRecord *record = elem->data;

        assert(record);

        const char *path = lr_yum_repo_path(repo, record->type);
        ret = lr_yum_check_checksum_of_md_record(record, path, err);
        if (!ret)
            return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 4
0
/* Do not duplicate repoata, just locate the local one */
static gboolean
lr_yum_use_local(LrHandle *handle, LrResult *result, GError **err)
{
    char *baseurl;
    LrYumRepo *repo;
    LrYumRepoMd *repomd;

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

    g_debug("%s: Locating repo..", __func__);

    // Shortcuts
    repo   = result->yum_repo;
    repomd = result->yum_repomd;
    baseurl = handle->urls[0];

    // Skip "file://" prefix if present
    if (g_str_has_prefix(baseurl, "file://"))
        baseurl += 7;
    else if (g_str_has_prefix(baseurl, "file:"))
        baseurl += 5;

    // Check sanity
    if (strstr(baseurl, "://")) {
        g_set_error(err, LR_YUM_ERROR, LRE_NOTLOCAL,
                    "URL: %s doesn't seem to be a local repository",
                    baseurl);
        return FALSE;
    }

    if (!handle->update) {
        // Load repomd.xml and mirrorlist+metalink if locally available
        if (!lr_yum_use_local_load_base(handle, result, repo, repomd, baseurl, err))
            return FALSE;
    }

    // Locate rest of metadata files
    for (GSList *elem = repomd->records; elem; elem = g_slist_next(elem)) {
        _cleanup_free_ char *path = NULL;
        LrYumRepoMdRecord *record = elem->data;

        assert(record);

        if (!lr_yum_repomd_record_enabled(handle, record->type))
            continue; // Caller isn't interested in this record type
        if (lr_yum_repo_path(repo, record->type))
            continue; // This path already exists in repo

        path = lr_pathconcat(baseurl, record->location_href, NULL);
        if (access(path, F_OK) == -1) {
            // A repo file is missing
            if (!handle->ignoremissing) {
                g_debug("%s: Incomplete repository - %s is missing",
                        __func__, path);
                g_set_error(err, LR_YUM_ERROR, LRE_INCOMPLETEREPO,
                            "Incomplete repository - %s is missing",
                            path);
                return FALSE;
            }

            continue;
        }

        lr_yum_repo_append(repo, record->type, path);
    }

    g_debug("%s: Repository was successfully located", __func__);
    return TRUE;
}
Ejemplo n.º 5
0
int
lr_yum_use_local(lr_Handle handle, lr_Result result)
{
    char *path;
    int rc = LRE_OK;
    int fd;
    char *baseurl;
    lr_YumRepo repo;
    lr_YumRepoMd repomd;

    DPRINTF("%s: Locating repo..\n", __func__);

    repo   = result->yum_repo;
    repomd = result->yum_repomd;
    baseurl = handle->baseurl;

    /* Do not duplicate repoata, just locate the local one */
    if (strncmp(baseurl, "file://", 7)) {
        if (strstr(baseurl, "://"))
            return LRE_NOTLOCAL;
    } else {
        /* Skip file:// in baseurl */
        baseurl = baseurl+7;
    }

    if (!handle->update) {
        /* Open and parse repomd */
        char *sig;

        path = lr_pathconcat(baseurl, "repodata/repomd.xml", NULL);
        fd = open(path, O_RDONLY);
        if (fd < 0) {
            DPRINTF("%s: open(%s): %s\n", __func__, path, strerror(errno));
            lr_free(path);
            return LRE_IO;
        }

        DPRINTF("%s: Parsing repomd.xml\n", __func__);
        rc = lr_yum_repomd_parse_file(repomd, fd);
        if (rc != LRE_OK) {
            DPRINTF("%s: Parsing unsuccessful (%d)\n", __func__, rc);
            lr_free(path);
            return rc;
        }

        close(fd);

        /* Fill result object */
        result->destdir = lr_strdup(baseurl);
        repo->destdir = lr_strdup(baseurl);
        repo->repomd = path;

        /* Check if signature file exists */
        sig = lr_pathconcat(baseurl, "repodata/repomd.xml.asc", NULL);
        if (access(sig, F_OK) == 0)
            repo->signature = sig;  // File with key exists
        else
            lr_free(sig);

        /* Signature checking */
        if (handle->checks & LR_CHECK_GPG && repo->signature) {
            rc = lr_gpg_check_signature(repo->signature, repo->repomd, NULL);
            if (rc != LRE_OK) {
                DPRINTF("%s: GPG signature verification failed\n", __func__);
                return rc;
            }
        }


        DPRINTF("%s: Repomd revision: %s\n", __func__, repomd->revision);
    }

    /* Locate rest of metadata files */
    for (int x = 0; x < repomd->nor; x++) {
        char *path;
        lr_YumRepoMdRecord record = repomd->records[x];

        if (!lr_yum_repomd_record_enabled(handle, record->type))
            continue;
        if (lr_yum_repo_path(repo, record->type))
            continue; /* This path already exists in repo */

        path = lr_pathconcat(baseurl, record->location_href, NULL);
        if (path) {
            if (access(path, F_OK) == -1) {
                /* A repo file is missing */
                if (!handle->ignoremissing) {
                    DPRINTF("%s: Incomplete repository\n", __func__);
                    lr_free(path);
                    return LRE_INCOMPLETEREPO;
                }
            } else
                lr_yum_repo_append(repo, record->type, path);
            lr_free(path);
        }
    }

    DPRINTF("%s: Repository was successfully located\n", __func__);
    return LRE_OK;
}
int main()
{
  LrHandleOption type;
  GError *tmp_err = NULL;
  
  // Download only this metadata
  //char *download_list[] = { "primary", "filelists", NULL};
  LrHandle *h = lr_handle_init();
  LrResult *r = lr_result_init();
  //repo->urls[repo->count] = NULL;
  
  //find type of url in vector
//   switch(repo->type)
//   {
//     case 1:
//       type = LRO_URLS;
//       lr_handle_setopt(h, NULL, type, repo->urls);
//       break;
//     case 2:
//       type = LRO_MIRRORLISTURL;
//       lr_handle_setopt(h, NULL, type, repo->urls[0]);
//       break;
//     case 3:
//       type = LRO_METALINKURL;
//       lr_handle_setopt(h, NULL, type, repo->urls[0]);
//       break;
//   }
  char* full_path = "/tmp/ssds/pokus";
  char* urls[2] = {"http://copr-be.cloud.fedoraproject.org/results/dvratil/plasma-5/fedora-21-x86_64/", NULL};
  lr_handle_setopt(h, NULL, LRO_URLS, urls);
  lr_handle_setopt(h, NULL, LRO_REPOTYPE, LR_YUMREPO);
  lr_handle_setopt(h, NULL, LRO_CONNECTTIMEOUT, (long)10);
  lr_handle_setopt(h, NULL, LRO_DESTDIR, full_path);
//   lr_handle_setopt(h, NULL, LRO_PROGRESSCB, metadata_progress);  
//   lr_handle_setopt(h, NULL, LRO_PROGRESSDATA, repo->name);
  
  gboolean ret = lr_handle_perform(h, r, &tmp_err);
  char *destdir;
  lr_handle_getinfo(h, NULL, LRI_DESTDIR, &destdir);
  
  
  if (ret) {
    printf("Metadata download successfull (Destination dir: %s).\n", destdir);
    
    LrYumRepo* lrRepo = lr_yum_repo_init();
    lr_result_getinfo(r, &tmp_err, LRR_YUM_REPO, &lrRepo);
    
//     SsdsMetadataFilesLoc* loc = (SsdsMetadataFilesLoc*)ssds_malloc(sizeof(SsdsMetadataFilesLoc));
    
//     loc->repomd = destdir;
    printf("Repomd is in %s/repomd.xml.\n", destdir);
//     loc->filelists = strdup(lr_yum_repo_path(lrRepo,"filelists"));
    printf("Filelists are in %s.\n", lr_yum_repo_path(lrRepo,"filelists"));
//     loc->primary = strdup(lr_yum_repo_path(lrRepo,"primary"));
    printf("Primary is in %s.\n", lr_yum_repo_path(lrRepo,"primary"));
//     loc->repo_name = strdup(repo->urls[0]);
    
//     list->files_locations = g_slist_append(list->files_locations, loc);
    lr_yum_repo_free(lrRepo);
    printf("lr_yum_repo_free went OK\n");
  } else {
    fprintf(stderr, "Error encountered: %s.\n", tmp_err->message);
    g_error_free(tmp_err);
  }
  
 lr_result_free(r);
 printf("lr_result_free went OK\n");
 lr_handle_free(h);
 printf("lr_handle_free went OK\n");
  
  
  
  
}