コード例 #1
0
static alpm_handle_t *
pk_backend_config_configure_alpm (PkBackendConfig *config, GError **error)
{
	alpm_handle_t *handle;

	g_return_val_if_fail (config != NULL, FALSE);

	handle = pk_backend_config_initialize_alpm (config, error);
	if (handle == NULL) {
		return NULL;
	}

	alpm_option_set_checkspace (handle, config->checkspace);
	alpm_option_set_usesyslog (handle, config->usesyslog);
	alpm_option_set_arch (handle, config->arch);
	alpm_option_set_deltaratio (handle, config->deltaratio);

	/* backend takes ownership */
	g_free (xfercmd);
	xfercmd = config->xfercmd;
	config->xfercmd = NULL;

	if (xfercmd != NULL) {
		alpm_option_set_fetchcb (handle, pk_backend_fetchcb);
	} else {
		alpm_option_set_fetchcb (handle, NULL);
	}

	/* backend takes ownership */
	FREELIST (holdpkgs);
	holdpkgs = config->holdpkgs;
	config->holdpkgs = NULL;

	/* alpm takes ownership */
	alpm_option_set_ignoregroups (handle, config->ignoregroups);
	config->ignoregroups = NULL;

	/* alpm takes ownership */
	alpm_option_set_ignorepkgs (handle, config->ignorepkgs);
	config->ignorepkgs = NULL;

	/* alpm takes ownership */
	alpm_option_set_noextracts (handle, config->noextracts);
	config->noextracts = NULL;

	/* alpm takes ownership */
	alpm_option_set_noupgrades (handle, config->noupgrades);
	config->noupgrades = NULL;

	pk_backend_config_configure_repos (config, handle, error);

	return handle;
}
コード例 #2
0
ファイル: ipacman.c プロジェクト: sonald/isoft-os-installer
int ipacman_init(const char* rootdir, alpm_cb_progress cb)
{
	int ret = 0;
	alpm_errno_t err;

	/* Configure root path first. If it is set and dbpath/logfile were not
	 * set, then set those as well to reside under the root. */
	char path[PATH_MAX];
	snprintf(path, PATH_MAX, "%s/var/lib/pacman/", rootdir);

	if(access(path, F_OK) != 0) {
		mkdirp(path, 0755);
	}

	/* initialize library */
	handle = alpm_initialize(rootdir, path, &err);
	if(!handle) {
		printf("failed to initialize alpm library (%s)\n", alpm_strerror(err));
		if(err == ALPM_ERR_DB_VERSION) {
			printf("  try running pacman-db-upgrade\n");
		}
		return -1;
	}

	alpm_option_set_dlcb(handle, cb_dl_progress);
	alpm_option_set_eventcb(handle, cb_event);
	alpm_option_set_questioncb(handle, cb_question);
	alpm_option_set_progresscb(handle, cb?cb:cb_progress);

	snprintf(path, PATH_MAX, "%s/var/log/pacman.log", rootdir);
	ret = alpm_option_set_logfile(handle, path);
	if(ret != 0) {
		printf("problem setting logfile '%s' (%s)\n", path, alpm_strerror(alpm_errno(handle)));
		return ret;
	}

	/* Set GnuPG's home directory.  This is not relative to rootdir, even if
	 * rootdir is defined. Reasoning: gpgdir contains configuration data. */
	snprintf(path, PATH_MAX, "%s/etc/pacman.d/gnupg/", rootdir);
	ret = alpm_option_set_gpgdir(handle, path);
	if(ret != 0) {
		printf("problem setting gpgdir '%s' (%s)\n", path, alpm_strerror(alpm_errno(handle)));
		return ret;
	}

	/* add a default cachedir if one wasn't specified */
	snprintf(path, PATH_MAX, "%s/var/cache/pacman/pkg/", rootdir);
	alpm_option_add_cachedir(handle, path);
    //specialized for installer
	/*alpm_option_add_cachedir(handle, "/PKGS");*/

	alpm_option_set_default_siglevel(handle, ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL |
			ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL);


	alpm_option_set_local_file_siglevel(handle, ALPM_SIG_USE_DEFAULT);
	alpm_option_set_remote_file_siglevel(handle, ALPM_SIG_USE_DEFAULT);

	alpm_option_set_totaldlcb(handle, cb_dl_total);

	struct utsname un;
	uname(&un);
	if (strcmp(un.machine, "mips64") == 0)
		alpm_option_set_arch(handle, "mipsel");
	else
		alpm_option_set_arch(handle, un.machine);

	alpm_option_set_checkspace(handle, 1);
	alpm_option_set_usesyslog(handle, 1);
	alpm_option_set_deltaratio(handle, 0.7);

	/* the follow function use alpm_list_t* as arguments
	 * use alpm_list_add()
	 */
	/*
	alpm_option_set_ignorepkgs(handle, ignorepkg);
	alpm_option_set_ignoregroups(handle, ignoregrp);
	alpm_option_set_noupgrades(handle, noupgrade);
	alpm_option_set_noextracts(handle, noextract);
	*/
	return 0;
}
コード例 #3
0
ファイル: conf.c プロジェクト: ABaumgaertner/MSYS2-pacman
/** Sets up libalpm global stuff in one go. Called after the command line
 * and initial config file parsing. Once this is complete, we can see if any
 * paths were defined. If a rootdir was defined and nothing else, we want all
 * of our paths to live under the rootdir that was specified. Safe to call
 * multiple times (will only do anything the first time).
 */
static int setup_libalpm(void)
{
	int ret = 0;
	alpm_errno_t err;
	alpm_handle_t *handle;
	alpm_list_t *i;

	pm_printf(ALPM_LOG_DEBUG, "setup_libalpm called\n");

	/* Configure root path first. If it is set and dbpath/logfile were not
	 * set, then set those as well to reside under the root. */
	if(config->rootdir) {
		char path[PATH_MAX];
		if(!config->dbpath) {
			snprintf(path, PATH_MAX, "%s/%s", config->rootdir, DBPATH + 1);
			config->dbpath = strdup(path);
		}
		if(!config->logfile) {
			snprintf(path, PATH_MAX, "%s/%s", config->rootdir, LOGFILE + 1);
			config->logfile = strdup(path);
		}
	} else {
		config->rootdir = strdup(ROOTDIR);
		if(!config->dbpath) {
			config->dbpath = strdup(DBPATH);
		}
	}

	/* initialize library */
	handle = alpm_initialize(config->rootdir, config->dbpath, &err);
	if(!handle) {
		pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library\n(%s: %s)\n"),
		        alpm_strerror(err), config->dbpath);
		if(err == ALPM_ERR_DB_VERSION) {
			fprintf(stderr, _("try running pacman-db-upgrade\n"));
		}
		return -1;
	}
	config->handle = handle;

	alpm_option_set_logcb(handle, cb_log);
	alpm_option_set_dlcb(handle, cb_dl_progress);
	alpm_option_set_eventcb(handle, cb_event);
	alpm_option_set_questioncb(handle, cb_question);
	alpm_option_set_progresscb(handle, cb_progress);

	config->logfile = config->logfile ? config->logfile : strdup(LOGFILE);
	ret = alpm_option_set_logfile(handle, config->logfile);
	if(ret != 0) {
		pm_printf(ALPM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
				config->logfile, alpm_strerror(alpm_errno(handle)));
		return ret;
	}

	/* Set GnuPG's home directory. This is not relative to rootdir, even if
	 * rootdir is defined. Reasoning: gpgdir contains configuration data. */
	config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR);
	ret = alpm_option_set_gpgdir(handle, config->gpgdir);
	if(ret != 0) {
		pm_printf(ALPM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"),
				config->gpgdir, alpm_strerror(alpm_errno(handle)));
		return ret;
	}

	/* add a default cachedir if one wasn't specified */
	if(config->cachedirs == NULL) {
		alpm_option_add_cachedir(handle, CACHEDIR);
	} else {
		alpm_option_set_cachedirs(handle, config->cachedirs);
	}

	alpm_option_set_default_siglevel(handle, config->siglevel);

	config->localfilesiglevel = merge_siglevel(config->siglevel,
			config->localfilesiglevel, config->localfilesiglevel_mask);
	config->remotefilesiglevel = merge_siglevel(config->siglevel,
			config->remotefilesiglevel, config->remotefilesiglevel_mask);

	alpm_option_set_local_file_siglevel(handle, config->localfilesiglevel);
	alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel);

	for(i = config->repos; i; i = alpm_list_next(i)) {
		register_repo(i->data);
	}

	if(config->xfercommand) {
		alpm_option_set_fetchcb(handle, download_with_xfercommand);
	} else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER)) {
		pm_printf(ALPM_LOG_WARNING, _("no '%s' configured\n"), "XferCommand");
	}

	if(config->totaldownload) {
		alpm_option_set_totaldlcb(handle, cb_dl_total);
	}

	alpm_option_set_arch(handle, config->arch);
	alpm_option_set_checkspace(handle, config->checkspace);
	alpm_option_set_usesyslog(handle, config->usesyslog);
	alpm_option_set_deltaratio(handle, config->deltaratio);

	alpm_option_set_ignorepkgs(handle, config->ignorepkg);
	alpm_option_set_ignoregroups(handle, config->ignoregrp);
	alpm_option_set_noupgrades(handle, config->noupgrade);
	alpm_option_set_noextracts(handle, config->noextract);

	for(i = config->assumeinstalled; i; i = i->next) {
		char *entry = i->data;
		alpm_depend_t *dep = alpm_dep_from_string(entry);
		if(!dep) {
			return 1;
		}
		pm_printf(ALPM_LOG_DEBUG, "parsed assume installed: %s %s\n", dep->name, dep->version);

		ret = alpm_option_add_assumeinstalled(handle, dep);
		if(ret) {
			pm_printf(ALPM_LOG_ERROR, _("Failed to pass %s entry to libalpm"), "assume-installed");
			alpm_dep_free(dep);
			return ret;
		}
	 }

	return 0;
}
コード例 #4
0
/**
 * pacman_manager_set_use_syslog:
 * @manager: A #PacmanManager.
 * @value: %TRUE or %FALSE.
 *
 * Sets UseSyslog to @value. See pacman_manager_get_use_syslog().
 */
void pacman_manager_set_use_syslog (PacmanManager *manager, gboolean value) {
	g_return_if_fail (manager != NULL);
	
	alpm_option_set_usesyslog (value);
}