Esempio n. 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;
}
Esempio n. 2
0
File: repo.c Progetto: 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 ssds_download(int answer, GSList *install, GSList *update, GSList *erase)
{
	int rc = OK;
	GSList  *install_list = NULL,
			*update_list = NULL;

	/***********************************************************/
	/* Downloading packages part                               */
	/***********************************************************/
	
	ssds_log(logDEBUG, "Begin downloading part.\n");
	
	// required variables for downloading
	gboolean return_status;
	LrHandle *handler;
	LrPackageTarget *target;
	GError *error = NULL;
	
	for(guint i = 1; i < g_slist_length(install); i++){
	   SsdsJsonPkg* inst = (SsdsJsonPkg*)g_slist_nth_data(install, i);
	   ssds_log(logMESSAGE, "Downloading preparation for package: %s\n", inst->pkg_name);
	
	   ssds_log(logDEBUG, "Downloading preparation.\n");
	   handler = lr_handle_init();
	   ssds_log(logDEBUG, "Download handler initied.\n");
	   lr_handle_setopt(handler, NULL, LRO_METALINKURL, inst->metalink);
	   ssds_log(logDEBUG, "Array of URLs is set.\n");
	   lr_handle_setopt(handler, NULL, LRO_REPOTYPE, LR_YUMREPO);
	   ssds_log(logDEBUG, "Repo type is set.\n");
	   lr_handle_setopt(handler, NULL, LRO_PROGRESSCB, progress_callback);
	   ssds_log(logDEBUG, "Progress callback is set.\n");
	
	   // Prepare list of target
	   target = lr_packagetarget_new_v2(handler, inst->pkg_loc, DOWNLOAD_TARGET,
	                                    LR_CHECKSUM_UNKNOWN, NULL, 0, inst->base_url, TRUE,
	                                    progress_callback, inst->pkg_name, end_callback, NULL, &error);
	   install_list = g_slist_append(install_list, target);
	}
	
	for(guint i = 1; i < g_slist_length(update); i++){
	   SsdsJsonPkg* inst = (SsdsJsonPkg*)g_slist_nth_data(update, i);
	   ssds_log(logMESSAGE, "Downloading preparation for package: %s\n", inst->pkg_name);
	
	   ssds_log(logDEBUG, "Downloading preparation.\n");
	   handler = lr_handle_init();
	   ssds_log(logDEBUG, "Download handler initied.\n");
	   lr_handle_setopt(handler, NULL, LRO_METALINKURL, inst->metalink);
	   ssds_log(logDEBUG, "Array of URLs is set.\n");
	   lr_handle_setopt(handler, NULL, LRO_REPOTYPE, LR_YUMREPO);
	   ssds_log(logDEBUG, "Repo type is set.\n");
	   lr_handle_setopt(handler, NULL, LRO_PROGRESSCB, progress_callback);
	   ssds_log(logDEBUG, "Progress callback is set.\n");
	
	   // Prepare list of target
	   target = lr_packagetarget_new_v2(handler, inst->pkg_loc, DOWNLOAD_TARGET,
	                                    LR_CHECKSUM_UNKNOWN, NULL, 0, inst->base_url, TRUE,
	                                    progress_callback, inst->pkg_name, end_callback, NULL, &error);
	   update_list = g_slist_append(update_list, target);
	}
	
	// Download all packages        
	ssds_log(logMESSAGE, "Downloading packages.\n");
	return_status = lr_download_packages(install_list, LR_PACKAGEDOWNLOAD_FAILFAST, &error);
	
	if(!return_status || error != NULL){
	
	  ssds_log(logERROR, "%d: %s\n", error->code, error->message);
	  rc = DOWNLOAD_ERROR;
	
	}else{
	
	 	return_status = lr_download_packages(update_list, LR_PACKAGEDOWNLOAD_FAILFAST, &error);
	
		if(!return_status || error != NULL){
	
	  		ssds_log(logERROR, "%d: %s\n", error->code, error->message);
	  		rc = DOWNLOAD_ERROR;
	
		}else{
			ssds_log(logMESSAGE, "All packages were downloaded successfully.\n");
			if(answer == DOWNLOAD)
			{
				ssds_log(logMESSAGE, "Packages are in %s.\n", DOWNLOAD_TARGET);
			}else{
				rc = ssds_rpm_process(install_list, update_list, erase);
			}
		}
	}

	if(error != NULL){
		g_error_free(error);
	}
	g_slist_free_full(install_list, (GDestroyNotify) lr_packagetarget_free);
	g_slist_free_full(update_list, (GDestroyNotify) lr_packagetarget_free);
	
	return rc;
}
Esempio n. 4
0
uint32_t
TDNFDownloadPackage(
    PTDNF pTdnf,
    HyPackage hPkg,
    const char* pszRpmCacheDir
    )
{
    uint32_t dwError = 0;
    LrHandle *pRepoHandle = NULL;
    GError* pError = NULL;
    gboolean bRet = FALSE;
    char* ppszUrls[] = {NULL, NULL};
    const char* pszPackage = NULL;
    const char* pszRepo = NULL;
    char* pszUserPass = NULL;
    
    if(!pTdnf || !hPkg || IsNullOrEmptyString(pszRpmCacheDir))
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pRepoHandle = lr_handle_init();

    if(!pRepoHandle)
    {
        //TODO: Add repo specific
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Get package details
    pszPackage = hy_package_get_location(hPkg);
    pszRepo = hy_package_get_reponame(hPkg);

    dwError = TDNFRepoGetBaseUrl(pTdnf, pszRepo, &ppszUrls[0]);
    BAIL_ON_TDNF_ERROR(dwError);

    lr_handle_setopt(pRepoHandle, NULL, LRO_URLS, ppszUrls);
    lr_handle_setopt(pRepoHandle, NULL, LRO_REPOTYPE, LR_YUMREPO);
    lr_handle_setopt(pRepoHandle, NULL, LRO_SSLVERIFYPEER, 1);
    lr_handle_setopt(pRepoHandle, NULL, LRO_SSLVERIFYHOST, 2);

    dwError = TDNFRepoGetUserPass(pTdnf, pszRepo, &pszUserPass);
    BAIL_ON_TDNF_ERROR(dwError);

    if(!IsNullOrEmptyString(pszUserPass))
    {
        lr_handle_setopt(pRepoHandle, NULL, LRO_USERPWD, pszUserPass);
    }
    bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSCB, lrProgressCB);
    if(bRet == FALSE)
    {
        //TODO: Add repo specific
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    bRet = lr_download_package (
                         pRepoHandle,
                         pszPackage,
                         pszRpmCacheDir,
                         LR_CHECKSUM_UNKNOWN,
                         NULL,
                         0, 
                         NULL, 
                         TRUE,
                         &pError);

    if(bRet == FALSE)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    fprintf(stdout, "\n");
cleanup:
    if(pRepoHandle)
    {
        lr_handle_free(pRepoHandle);
    }
    return dwError;

error:
    if(pError)
    {
        fprintf(
            stderr,
            "Error during download: %d: %s\n",
            pError->code,
            pError->message
            );
        g_error_free(pError);
    }
    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");
  
  
  
  
}