示例#1
0
文件: yum.c 项目: akozumpl/librepo
int
lr_yum_perform(lr_Handle handle, lr_Result result)
{
    int rc = LRE_OK;
    lr_YumRepo repo;
    lr_YumRepoMd repomd;

    assert(handle);

    if (!result)
        return LRE_BADFUNCARG;

    if (!handle->baseurl && !handle->mirrorlist)
        return LRE_NOURL;

    if (handle->local && !handle->baseurl)
        return LRE_NOURL;

    if (handle->update) {
        /* Download/Locate only specified files */
        if (!result->yum_repo || !result->yum_repomd)
            return LRE_INCOMPLETERESULT;
    } else {
        /* Download/Locate from scratch */
        if (result->yum_repo || result->yum_repomd)
            return LRE_ALREADYUSEDRESULT;
        result->yum_repo = lr_yum_repo_init();
        result->yum_repomd = lr_yum_repomd_init();
    }

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

    if (handle->local) {
        /* Do not duplicate repository, just use the existing local one */
        rc = lr_yum_use_local(handle, result);
        if (rc != LRE_OK)
            return rc;
        if (handle->checks & LR_CHECK_CHECKSUM)
            rc = lr_yum_check_repo_checksums(repo, repomd);
    } else {
        /* Download remote/Duplicate local repository */
        rc = lr_yum_download_remote(handle, result);
        /* All checksums are checked while downloading */
    }

    return rc;
}
示例#2
0
文件: yum.c 项目: sourcejedi/librepo
gboolean
lr_yum_perform(LrHandle *handle, LrResult *result, GError **err)
{
    int ret = TRUE;
    LrYumRepo *repo;
    LrYumRepoMd *repomd;

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

    if (!result) {
        g_set_error(err, LR_YUM_ERROR, LRE_BADFUNCARG,
                    "Missing result parameter");
        return FALSE;
    }

    if (!handle->urls && !handle->mirrorlisturl && !handle->metalinkurl) {
        g_set_error(err, LR_YUM_ERROR, LRE_NOURL,
                "No LRO_URLS, LRO_MIRRORLISTURL nor LRO_METALINKURL specified");
        return FALSE;
    }

    if (handle->local && (!handle->urls || !handle->urls[0])) {
        g_set_error(err, LR_YUM_ERROR, LRE_NOURL,
                    "Localrepo specified, but no LRO_URLS set");
        return FALSE;
    }

    if (handle->update) {
        // Download/Locate only specified files
        if (!result->yum_repo || !result->yum_repomd) {
            g_set_error(err, LR_YUM_ERROR, LRE_INCOMPLETERESULT,
                    "Incomplete result object - "
                    "Cannot update on this result object");
            return FALSE;
        }
    } else {
        // Download/Locate from scratch
        if (result->yum_repo || result->yum_repomd) {
            g_set_error(err, LR_YUM_ERROR, LRE_ALREADYUSEDRESULT,
                        "This result object is not clear - "
                        "Already used result object");
            return FALSE;
        }
        result->yum_repo = lr_yum_repo_init();
        result->yum_repomd = lr_yum_repomd_init();
    }

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

    if (handle->local) {
        // Do not duplicate repository, just use the existing local one

        ret = lr_yum_use_local(handle, result, err);
        if (!ret)
            return FALSE;

        if (handle->checks & LR_CHECK_CHECKSUM)
            ret = lr_yum_check_repo_checksums(repo, repomd, err);
    } else {
        // Download remote/Duplicate local repository
        // Note: All checksums are checked while downloading

        ret = lr_yum_download_remote(handle, result, err);
    }

    return ret;
}
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");
  
  
  
  
}