示例#1
0
gboolean
lr_download_package(LrHandle *handle,
                    const char *relative_url,
                    const char *dest,
                    LrChecksumType checksum_type,
                    const char *checksum,
                    gint64 expectedsize,
                    const char *base_url,
                    gboolean resume,
                    GError **err)
{
    LrPackageTarget *target;

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

    // XXX: Maybe remove in future
    if (!dest)
        dest = handle->destdir;

    // XXX: Maybe remove usage of handle callback in future

    target = lr_packagetarget_new(handle, relative_url, dest, checksum_type,
                                  checksum, expectedsize, base_url, resume,
                                  handle->user_cb, handle->user_data, err);
    if (!target)
        return FALSE;

    GSList *targets = NULL;
    targets = g_slist_append(targets, target);

    gboolean ret = lr_download_packages(targets,
                                        LR_PACKAGEDOWNLOAD_FAILFAST,
                                        err);

    g_slist_free_full(targets, (GDestroyNotify)lr_packagetarget_free);

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