예제 #1
0
gboolean
lr_repoutil_yum_check_repo(const char *path, GError **err)
{
    gboolean ret;
    LrHandle *h;
    LrResult *result;

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

    h = lr_handle_init();

    if (!lr_handle_setopt(h, err, LRO_REPOTYPE, LR_YUMREPO)) {
        lr_handle_free(h);
        return FALSE;
    }

    if (!lr_handle_setopt(h, err, LRO_URLS, path)) {
        lr_handle_free(h);
        return FALSE;
    }

    if (!lr_handle_setopt(h, err, LRO_CHECKSUM, 1)) {
        lr_handle_free(h);
        return FALSE;
    }

    if (!lr_handle_setopt(h, err, LRO_LOCAL, 1)) {
        lr_handle_free(h);
        return FALSE;
    }

    result = lr_result_init();
    ret = lr_handle_perform(h, result, err);
    lr_result_free(result);
    lr_handle_free(h);

    return ret;
}
예제 #2
0
파일: repo.c 프로젝트: toliaqat/tdnf
//Download repo metadata and initialize
uint32_t
TDNFInitRepo(
    PTDNF pTdnf,
    PTDNF_REPO_DATA pRepoData,
    HyRepo* phRepo
    )
{
    uint32_t dwError = 0;
    gboolean bRet = 0;
    LrHandle* hLibRepo = NULL;
    LrResult* pResult = NULL;
    LrYumRepo* pRepo = NULL;
    int nLocalOnly = 0;
    char* pszRepoCacheDir = NULL;
    char* pszRepoDataDir = NULL;
    char* pszUserPass = NULL;

    char* ppszRepoUrls[] = {NULL, NULL};
    char* ppszLocalUrls[] = {NULL, NULL};
    char* ppszDownloadList[] = {"primary", "filelists", "updateinfo", NULL};
    PTDNF_CONF pConf = NULL;

    HyRepo hRepo = NULL;

    if(!pTdnf || !pTdnf->pConf || !pRepoData || !phRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pConf = pTdnf->pConf;

    pszRepoCacheDir = g_build_path(
                           G_DIR_SEPARATOR_S,
                           pConf->pszCacheDir,
                           pRepoData->pszId,
                           NULL);
    if(!pszRepoCacheDir)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszRepoDataDir = g_build_path(
                           G_DIR_SEPARATOR_S,
                           pszRepoCacheDir,
                           TDNF_REPODATA_DIR_NAME,
                           NULL);
    if(!pszRepoDataDir)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    ppszRepoUrls[0] = pRepoData->pszBaseUrl;
    ppszLocalUrls[0] = pszRepoCacheDir;

    hLibRepo = lr_handle_init();
    if(!hLibRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pResult = lr_result_init();
    if(!pResult)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Look for repodata dir - this is auto created
    //during last refresh so skip download if present
    if(!access(pszRepoDataDir, F_OK))
    {
        nLocalOnly = 1;
        lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszLocalUrls);
        lr_handle_setopt(hLibRepo, NULL, LRO_IGNOREMISSING, 1);
    }
    else
    {
        //Look for the repo root cache dir. If not there,
        //try to create and download into it.
        if(access(pszRepoCacheDir, F_OK))
        {
            if(errno != ENOENT)
            {
                dwError = errno;
            }
            BAIL_ON_TDNF_SYSTEM_ERROR(dwError);

            if(mkdir(pszRepoCacheDir, 755))
            {
                dwError = errno;
                BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
            }
        }

        lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszRepoUrls);
        lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYPEER, 1);
        lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYHOST, 2);
        lr_handle_setopt(hLibRepo, NULL, LRO_DESTDIR, pszRepoCacheDir);
        lr_handle_setopt(hLibRepo, NULL, LRO_YUMDLIST, ppszDownloadList);
        if(!IsNullOrEmptyString(pRepoData->pszUser) && 
           !IsNullOrEmptyString(pRepoData->pszPass))
        {
            dwError = TDNFAllocateStringPrintf(
                          &pszUserPass,
                          "%s:%s",
                          pRepoData->pszUser,
                          pRepoData->pszPass);
            BAIL_ON_TDNF_ERROR(dwError);
            lr_handle_setopt(
                hLibRepo,
                NULL,
                LRO_USERPWD,
                pszUserPass);
        }
    }

    lr_handle_setopt(hLibRepo, NULL, LRO_REPOTYPE, LR_YUMREPO);
    lr_handle_setopt(hLibRepo, NULL, LRO_LOCAL, nLocalOnly);

    
    bRet = lr_handle_perform(hLibRepo, pResult, NULL);
    if(!bRet)
    {
        dwError = ERROR_TDNF_REPO_PERFORM;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    bRet = lr_result_getinfo(pResult, NULL, LRR_YUM_REPO, &pRepo);
    if(!bRet)
    {
        dwError = ERROR_TDNF_REPO_GETINFO;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Create and set repo properties   
    hRepo = hy_repo_create(pRepoData->pszId);
    if(!hRepo)
    {
        dwError = ERROR_TDNF_HAWKEY_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = TDNFInitRepoFromMetaData(hRepo, pRepo);
    BAIL_ON_TDNF_ERROR(dwError);

    *phRepo = hRepo;
cleanup:
    if(pszRepoDataDir)
    {
        g_free(pszRepoDataDir);
    }
    if(pszRepoCacheDir)
    {
        g_free(pszRepoCacheDir);
    }

    if(pResult)
    {
        lr_result_free(pResult);
    }
    if(hLibRepo)
    {
        lr_handle_free(hLibRepo);
    }
    return dwError;

error:
    //If there is an error during init, log the error
    //remove any cache data that could be potentially corrupt.
    if(pRepoData)
    {
        fprintf(
            stderr,
            "Error: Failed to synchronize cache for repo '%s' from '%s'\n",
            pRepoData->pszName,
            pRepoData->pszBaseUrl);

        if(pTdnf)
        {
            TDNFRepoRemoveCache(pTdnf, pRepoData->pszId);
        }
    }
    if(phRepo)
    {
        *phRepo = NULL;
    }
    if(hRepo)
    {
       hy_repo_free(hRepo);
    }
    goto cleanup;
}
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");
  
  
  
  
}