Example #1
0
static gboolean
disabled_repos_configure (GHashTable *disabled, GError **error)
{
	const PacmanList *databases;

	g_return_val_if_fail (pacman != NULL, FALSE);

	g_debug ("pacman: reading config from %s", PACMAN_CONFIG_FILE);

	/* read configuration from pacman config file */
	if (!pacman_manager_configure (pacman, PACMAN_CONFIG_FILE, error)) {
		return FALSE;
	}

	local_database = pacman_manager_get_local_database (pacman);

	/* disable disabled repos */
	for (databases = pacman_manager_get_sync_databases (pacman); databases != NULL; databases = pacman_list_next (databases)) {
		PacmanDatabase *database = (PacmanDatabase *) pacman_list_get (databases);
		const gchar *repo = pacman_database_get_name (database);

		if (g_hash_table_lookup (disabled, repo) != NULL) {
			if (!pacman_manager_unregister_database (pacman, database, error)) {
				return FALSE;
			}

			/* start again as the list gets invalidated */
			databases = pacman_manager_get_sync_databases (pacman);
		}
	}

	return TRUE;
}
Example #2
0
static gchar *
pacman_package_make_replaces_ids (PacmanPackage *package)
{
	const PacmanList *list;
	GString *string = NULL;

	g_return_val_if_fail (local_database != NULL, NULL);
	g_return_val_if_fail (package != NULL, NULL);

	/* make a list of the packages that package replaces */
	for (list = pacman_package_get_replaces (package); list != NULL; list = pacman_list_next (list)) {
		const gchar *name = pacman_list_get (list);
		PacmanPackage *replaces = pacman_database_find_package (local_database, name);

		if (replaces != NULL) {
			gchar *package_id = pacman_package_make_id (replaces);
			if (string == NULL) {
				string = g_string_new (package_id);
			} else {
				g_string_append_printf (string, "&%s", package_id);
			}
			g_free (package_id);
		}
	}

	if (string != NULL) {
		return g_string_free (string, FALSE);
	} else {
		return NULL;
	}
}
Example #3
0
static gboolean
pacman_package_should_ignore (PacmanPackage *package)
{
	const PacmanList *groups;
	const PacmanList *ignore_packages;
	const PacmanList *ignore_groups;

	g_return_val_if_fail (pacman != NULL, TRUE);
	g_return_val_if_fail (package != NULL, TRUE);

	ignore_packages = pacman_manager_get_ignore_packages (pacman);

	/* check if package is an IgnorePkg */
	if (pacman_list_find_string (ignore_packages, pacman_package_get_name (package)) != NULL) {
		return TRUE;
	}

	ignore_groups = pacman_manager_get_ignore_groups (pacman);

	/* check if package is in an IgnoreGroup */
	for (groups = pacman_package_get_groups (package); groups != NULL; groups = pacman_list_next (groups)) {
		if (pacman_list_find_string (ignore_groups, (const gchar *) pacman_list_get (groups)) != NULL) {
			return TRUE;
		}
	}

	return FALSE;
}
Example #4
0
static gboolean
backend_get_updates_thread (PkBackend *backend)
{
	struct stat cache;
	time_t one_hour_ago;

	PacmanTransaction *transaction = NULL;
	PacmanTransactionFlags flags = PACMAN_TRANSACTION_FLAGS_NONE;

	const PacmanList *packages;

	g_return_val_if_fail (local_database != NULL, FALSE);
	g_return_val_if_fail (pacman != NULL, FALSE);
	g_return_val_if_fail (backend != NULL, FALSE);

	time (&one_hour_ago);
	one_hour_ago -= 60 * 60;

	/* refresh databases if they are older than an hour */
	if (g_stat (PACMAN_CACHE_PATH, &cache) < 0 || cache.st_mtime < one_hour_ago) {
		transaction = backend_transaction_run (backend, PACMAN_TRANSACTION_UPDATE, flags, NULL);

		if (transaction != NULL) {
			g_object_unref (transaction);
		} else {
			backend_finished (backend);
			return FALSE;
		}
	} else {
		g_debug ("pacman: databases have been refreshed recently");
	}

	/* find outdated and replacement packages */
	for (packages = pacman_database_get_packages (local_database); packages != NULL; packages = pacman_list_next (packages)) {
		PacmanPackage *package = (PacmanPackage *) pacman_list_get (packages);
		PacmanPackage *upgrade = pacman_package_find_upgrade (package, pacman_manager_get_sync_databases (pacman));

		if (backend_cancelled (backend)) {
			break;
		}

		if (upgrade != NULL) {
			PkInfoEnum info;

			if (pacman_package_should_ignore (upgrade)) {
				info = PK_INFO_ENUM_BLOCKED;
			} else if (pacman_package_should_sync_first (upgrade)) {
				info = PK_INFO_ENUM_IMPORTANT;
			} else {
				info = PK_INFO_ENUM_NORMAL;
			}

			backend_package (backend, upgrade, info);
		}
	}

	backend_finished (backend);
	return TRUE;
}
Example #5
0
/**
 * pacman_list_strdup:
 * @list: A #PacmanList.
 *
 * Creates a new list by duplicating every string in @list.
 *
 * Returns: A #PacmanList. Free the contents with g_free(), then free the list with pacman_list_free().
 */
PacmanList *pacman_list_strdup (const PacmanList *list) {
	const PacmanList *i;
	PacmanList *result = NULL;
	
	for (i = list; i != NULL; i = pacman_list_next (i)) {
		const gchar *string = (const gchar *) pacman_list_get (i);
		result = pacman_list_add (result, g_strdup (string));
	}
	
	return result;
}
Example #6
0
/**
 * pacman_manager_find_sync_database:
 * @manager: A #PacmanManager.
 * @name: The name of a sync database.
 *
 * Finds a sync database named @name.
 *
 * Returns: A #PacmanDatabase, or %NULL if none were found.
 */
PacmanDatabase *pacman_manager_find_sync_database (PacmanManager *manager, const gchar *name) {
	const PacmanList *i;
	
	g_return_val_if_fail (manager != NULL, NULL);
	
	for (i = pacman_manager_get_sync_databases (manager); i != NULL; i = pacman_list_next (i)) {
		PacmanDatabase *database = (PacmanDatabase *) pacman_list_get (i);
		if (g_strcmp0 (name, pacman_database_get_name (database)) == 0) {
			return database;
		}
	}
	
	return NULL;
}
Example #7
0
const gchar *
pacman_package_get_group (PacmanPackage *package)
{
	const PacmanList *list;

	g_return_val_if_fail (group_map != NULL, NULL);
	g_return_val_if_fail (package != NULL, NULL);

	/* use the first group that we recognise */
	for (list = pacman_package_get_groups (package); list != NULL; list = pacman_list_next (list)) {
		gpointer value = g_hash_table_lookup (group_map, pacman_list_get (list));
		if (value != NULL) {
			return (const gchar *) value;
		}
	}

	return "other";
}
Example #8
0
static gboolean
backend_get_repo_list_thread (PkBackend *backend)
{
	const PacmanList *databases;
	GHashTableIter iter;
	gpointer key, value;

	g_return_val_if_fail (pacman != NULL, FALSE);
	g_return_val_if_fail (disabled_repos != NULL, FALSE);
	g_return_val_if_fail (backend != NULL, FALSE);

	/* emit enabled repos */
	for (databases = pacman_manager_get_sync_databases (pacman); databases != NULL; databases = pacman_list_next (databases)) {
		PacmanDatabase *database = (PacmanDatabase *) pacman_list_get (databases);
		const gchar *repo = pacman_database_get_name (database);

		if (backend_cancelled (backend)) {
			break;
		} else {
			pk_backend_repo_detail (backend, repo, repo, TRUE);
		}
	}

	/* emit disabled repos */
	g_hash_table_iter_init (&iter, disabled_repos);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		const gchar *repo = (const gchar *) key;

		if (backend_cancelled (backend)) {
			break;
		} else {
			pk_backend_repo_detail (backend, repo, repo, FALSE);
		}
	}

	backend_finished (backend);
	return TRUE;
}
Example #9
0
static gboolean pacman_install_prepare (PacmanTransaction *transaction, const PacmanList *targets, GError **error) {
	const PacmanList *i;
	PacmanList *data = NULL;
	
	g_return_val_if_fail (transaction != NULL, FALSE);
	g_return_val_if_fail (targets != NULL, FALSE);
	
	if (pacman_transaction_get_installs (transaction) != NULL) {
		/* reinitialize so transaction can be prepared multiple times */
		if (!pacman_transaction_restart (transaction, error)) {
			return FALSE;
		}
	}
	
	for (i = targets; i != NULL; i = pacman_list_next (i)) {
		int result;
		gchar *target = (gchar *) pacman_list_get (i);
		
		if (strstr (target, "://") != NULL) {
			target = alpm_fetch_pkgurl (target);
			if (target == NULL) {
				g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not download package with url '%s': %s"), (gchar *) pacman_list_get (i), alpm_strerrorlast ());
				return FALSE;
			}
			
			result = alpm_add_target (target);
			free (target);
		} else {
			result = alpm_add_target (target);
		}
		
		if (result < 0) {
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not mark the file '%s' for installation: %s"), target, alpm_strerrorlast ());
			return FALSE;
		}
	}
	
	if (alpm_trans_prepare (&data) < 0) {
		if (pm_errno == PACMAN_ERROR_PACKAGE_WRONG_ARCHITECTURE) {
			gchar *packages = pacman_package_make_list (data);
			pacman_transaction_set_marked_packages (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("The following packages have the wrong architecture: %s"), packages);
			g_free (packages);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_DEPENDENCY_UNSATISFIED) {
			gchar *missing = pacman_missing_dependency_make_list (data);
			pacman_transaction_set_missing_dependencies (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), missing);
			g_free (missing);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_CONFLICT) {
			gchar *conflict = pacman_conflict_make_list (data);
			pacman_transaction_set_conflicts (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), conflict);
			g_free (conflict);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_FILE_CONFLICT) {
			gchar *conflict = pacman_file_conflict_make_list (data);
			pacman_transaction_set_file_conflicts (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), conflict);
			g_free (conflict);
			return FALSE;
		} else if (data != NULL) {
			g_debug ("Possible memory leak for install error: %s\n", alpm_strerrorlast ());
		}
		
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
static void pacman_transaction_event_cb (pmtransevt_t event, gpointer data1, gpointer data2) {
	PacmanTransaction *transaction;
	
	g_return_if_fail (pacman_manager != NULL);
	transaction = pacman_manager_get_transaction (pacman_manager);
	g_return_if_fail (transaction != NULL);
	
	switch (event) {
		case PM_TRANS_EVT_CHECKDEPS_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DEPENDENCY_CHECK_START, _("Checking dependencies"));
			break;
		} case PM_TRANS_EVT_CHECKDEPS_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DEPENDENCY_CHECK_END, _("Finished checking dependencies"));
			break;
		} case PM_TRANS_EVT_FILECONFLICTS_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_FILE_CONFLICT_CHECK_START, _("Checking for file conflicts"));
			break;
		} case PM_TRANS_EVT_FILECONFLICTS_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_FILE_CONFLICT_CHECK_END, _("Finished checking for file conflicts"));
			break;
		} case PM_TRANS_EVT_RESOLVEDEPS_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DEPENDENCY_RESOLVE_START, _("Resolving dependencies"));
			break;
		} case PM_TRANS_EVT_RESOLVEDEPS_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DEPENDENCY_RESOLVE_END, _("Finished resolving dependencies"));
			break;
		} case PM_TRANS_EVT_INTERCONFLICTS_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_CONFLICT_CHECK_START, _("Checking for conflicts"));
			break;
		} case PM_TRANS_EVT_INTERCONFLICTS_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_CONFLICT_CHECK_END, _("Finished checking for conflicts"));
			break;
		} case PM_TRANS_EVT_ADD_START: {
			pacman_transaction_set_marked_packages (transaction, pacman_list_add (NULL, data1));
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_INSTALL_START, _("Installing %s"), pacman_package_get_name ((PacmanPackage *) data1));
			pacman_transaction_set_marked_packages (transaction, NULL);
			break;
		} case PM_TRANS_EVT_ADD_DONE: {
			PacmanPackage *package = (PacmanPackage *) data1;
			const PacmanList *optional_dependencies, *i;
			alpm_logaction ("installed %s (%s)\n", pacman_package_get_name (package), pacman_package_get_version (package));
			
			pacman_transaction_set_marked_packages (transaction, pacman_list_add (NULL, data1));
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_INSTALL_END, _("Finished installing %s"), pacman_package_get_name (package));
			pacman_transaction_set_marked_packages (transaction, NULL);
			
			optional_dependencies = pacman_package_get_optional_dependencies (package);
			if (optional_dependencies != NULL) {
				GString *depends = g_string_new ("");
				gchar *message;
				
				g_string_append_printf (depends, _("Optional dependencies for %s:\n"), pacman_package_get_name (package));
				for (i = optional_dependencies; i != NULL; i = pacman_list_next (i)) {
					const gchar *line = (const gchar *) pacman_list_get (i);
					g_string_append_printf (depends, "%s\n", line);
				}
				
				message = g_string_free (depends, FALSE);
				g_message ("%s", message);
				g_free (message);
			}
			break;
		} case PM_TRANS_EVT_REMOVE_START: {
			pacman_transaction_set_marked_packages (transaction, pacman_list_add (NULL, data1));
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_REMOVE_START, _("Removing %s"), pacman_package_get_name ((PacmanPackage *) data1));
			pacman_transaction_set_marked_packages (transaction, NULL);
			break;
		} case PM_TRANS_EVT_REMOVE_DONE: {
			PacmanPackage *package = (PacmanPackage *) data1;
			alpm_logaction ("removed %s (%s)\n", pacman_package_get_name (package), pacman_package_get_version (package));
			
			pacman_transaction_set_marked_packages (transaction, pacman_list_add (NULL, data1));
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_REMOVE_END, _("Finished removing %s"), pacman_package_get_name (package));
			pacman_transaction_set_marked_packages (transaction, NULL);
			break;
		} case PM_TRANS_EVT_UPGRADE_START: {
			PacmanList *new_then_old = NULL;
			new_then_old = pacman_list_add (new_then_old, data1);
			new_then_old = pacman_list_add (new_then_old, data2);
			
			pacman_transaction_set_marked_packages (transaction, new_then_old);
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_UPGRADE_START, _("Upgrading %s"), pacman_package_get_name ((PacmanPackage *) data1));
			pacman_transaction_set_marked_packages (transaction, NULL);
			break;
		} case PM_TRANS_EVT_UPGRADE_DONE: {
			PacmanPackage *package = (PacmanPackage *) data1, *old_package = (PacmanPackage *) data2;
			PacmanList *optional_dependencies, *i, *new_then_old = NULL;
			alpm_logaction ("upgraded %s (%s -> %s)\n", pacman_package_get_name (package), pacman_package_get_version (old_package), pacman_package_get_version (package));
			
			new_then_old = pacman_list_add (new_then_old, data1);
			new_then_old = pacman_list_add (new_then_old, data2);
			
			pacman_transaction_set_marked_packages (transaction, new_then_old);
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_UPGRADE_END, _("Finished upgrading %s"), pacman_package_get_name (package));
			pacman_transaction_set_marked_packages (transaction, NULL);
			
			optional_dependencies = pacman_list_diff (pacman_package_get_optional_dependencies (package), pacman_package_get_optional_dependencies (old_package), (GCompareFunc) g_strcmp0);
			if (optional_dependencies != NULL) {
				GString *depends = g_string_new ("");
				gchar *message;
				
				g_string_append_printf (depends, _("New optional dependencies for %s\n"), pacman_package_get_name (package));
				for (i = optional_dependencies; i != NULL; i = pacman_list_next (i)) {
					const gchar *line = (const gchar *) pacman_list_get (i);
					g_string_append_printf (depends, "%s\n", line);
				}
				
				message = g_string_free (depends, FALSE);
				g_message ("%s", message);
				g_free (message);
				pacman_list_free (optional_dependencies);
			}
			break;
		} case PM_TRANS_EVT_INTEGRITY_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_PACKAGE_INTEGRITY_CHECK_START, _("Checking package integrity"));
			break;
		} case PM_TRANS_EVT_INTEGRITY_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_PACKAGE_INTEGRITY_CHECK_END, _("Finished checking package integrity"));
			break;
		} case PM_TRANS_EVT_DELTA_INTEGRITY_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_INTEGRITY_CHECK_START, _("Checking delta integrity"));
			break;
		} case PM_TRANS_EVT_DELTA_INTEGRITY_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_INTEGRITY_CHECK_END, _("Finished checking delta integrity"));
			break;
		} case PM_TRANS_EVT_DELTA_PATCHES_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_PATCHING_START, _("Applying delta patches"));
			break;
		} case PM_TRANS_EVT_DELTA_PATCHES_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_PATCHING_END, _("Finished applying delta patches"));
			break;
		} case PM_TRANS_EVT_DELTA_PATCH_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_PATCH_START, _("Creating %s from the delta patch %s"), (const gchar *) data1, (const gchar *) data2);
			break;
		} case PM_TRANS_EVT_DELTA_PATCH_DONE: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DELTA_PATCH_END, _("Finished applying delta patch"));
			break;
		} case PM_TRANS_EVT_DELTA_PATCH_FAILED: {
			/* already reported as an error */
			break;
		} case PM_TRANS_EVT_SCRIPTLET_INFO: {
			g_message ("%s\n", (const gchar *) data1);
			break;
		} case PM_TRANS_EVT_RETRIEVE_START: {
			pacman_transaction_tell (transaction, PACMAN_TRANSACTION_STATUS_DOWNLOAD_FROM, _("Downloading packages from [%s]"), (const gchar *) data1);
			break;
		} default: {
			g_debug ("Unrecognised event: %d\n", event);
			break;
		}
	}
}