2011-02-04 17:38:48 -08:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Andreas Obergrusberger <tradiaz@yahoo.de>
|
|
|
|
* Copyright (C) 2008-2010 Valeriy Lyasotskiy <onestep@ukr.net>
|
|
|
|
* Copyright (C) 2010-2011 Jonathan Conder <jonno.conder@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License Version 2
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <pk-backend.h>
|
|
|
|
|
|
|
|
#include "pk-backend-alpm.h"
|
2014-09-05 08:03:17 -07:00
|
|
|
#include "pk-alpm-error.h"
|
|
|
|
#include "pk-alpm-packages.h"
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2011-10-28 06:21:41 -07:00
|
|
|
static alpm_pkg_t *
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_list_find_pkgname (const alpm_list_t *pkgs, const gchar *name)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
for (; pkgs != NULL; pkgs = pkgs->next) {
|
2014-09-05 06:00:37 -07:00
|
|
|
if (g_strcmp0 (name, alpm_pkg_get_name (pkgs->data)) == 0)
|
2011-02-04 17:38:48 -08:00
|
|
|
return pkgs->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static alpm_list_t *
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_find_provider (PkBackendJob *job, alpm_list_t *pkgs,
|
2014-09-06 12:27:37 -07:00
|
|
|
const gchar *depend, gboolean recursive,
|
|
|
|
PkBitfield filters, GError **error)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
2014-09-06 12:27:37 -07:00
|
|
|
PkBackend *backend = pk_backend_job_get_backend (job);
|
|
|
|
PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
|
2014-08-04 06:50:03 -07:00
|
|
|
gboolean skip_local, skip_remote;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2011-10-28 06:21:41 -07:00
|
|
|
alpm_pkg_t *provider;
|
2011-03-31 15:21:05 -07:00
|
|
|
alpm_list_t *pkgcache, *syncdbs;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
g_return_val_if_fail (depend != NULL, pkgs);
|
|
|
|
|
|
|
|
skip_local = pk_bitfield_contain (filters,
|
|
|
|
PK_FILTER_ENUM_NOT_INSTALLED);
|
|
|
|
skip_remote = pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED);
|
|
|
|
|
2011-03-31 15:21:05 -07:00
|
|
|
if (alpm_find_satisfier (pkgs, depend) != NULL) {
|
2011-02-04 17:38:48 -08:00
|
|
|
return pkgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for local dependencies */
|
2014-09-06 12:27:37 -07:00
|
|
|
pkgcache = alpm_db_get_pkgcache (priv->localdb);
|
2011-03-31 15:21:05 -07:00
|
|
|
provider = alpm_find_satisfier (pkgcache, depend);
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
if (provider != NULL) {
|
|
|
|
if (!skip_local) {
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_pkg_emit (job, provider, PK_INFO_ENUM_INSTALLED);
|
2011-02-04 17:38:48 -08:00
|
|
|
/* assume later dependencies will also be local */
|
|
|
|
if (recursive) {
|
|
|
|
pkgs = alpm_list_add (pkgs, provider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for remote dependencies */
|
2014-09-06 12:27:37 -07:00
|
|
|
syncdbs = alpm_get_syncdbs (priv->alpm);
|
|
|
|
provider = alpm_find_dbs_satisfier (priv->alpm, syncdbs, depend);
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
if (provider != NULL) {
|
2014-09-05 06:00:37 -07:00
|
|
|
if (!skip_remote)
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_pkg_emit (job, provider, PK_INFO_ENUM_AVAILABLE);
|
2011-02-04 17:38:48 -08:00
|
|
|
/* keep looking for local dependencies */
|
2014-09-05 06:00:37 -07:00
|
|
|
if (recursive)
|
2011-02-04 17:38:48 -08:00
|
|
|
pkgs = alpm_list_add (pkgs, provider);
|
|
|
|
} else {
|
2011-10-26 02:44:37 -07:00
|
|
|
int code = ALPM_ERR_UNSATISFIED_DEPS;
|
2014-09-05 08:03:17 -07:00
|
|
|
g_set_error (error, PK_ALPM_ERROR, code, "%s: %s", depend,
|
2011-02-04 17:38:48 -08:00
|
|
|
alpm_strerror (code));
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static alpm_list_t *
|
2014-08-04 06:50:03 -07:00
|
|
|
pk_backend_find_requirer (PkBackendJob *job, alpm_list_t *pkgs, const gchar *name, gboolean recursive,
|
2011-02-04 17:38:48 -08:00
|
|
|
GError **error)
|
|
|
|
{
|
2014-09-06 12:27:37 -07:00
|
|
|
PkBackend *backend = pk_backend_job_get_backend (job);
|
|
|
|
PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
|
2011-10-28 06:21:41 -07:00
|
|
|
alpm_pkg_t *requirer;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, pkgs);
|
|
|
|
|
2014-09-05 08:03:17 -07:00
|
|
|
if (pk_alpm_list_find_pkgname (pkgs, name) != NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
return pkgs;
|
|
|
|
|
|
|
|
/* look for local requirers */
|
2014-09-06 12:27:37 -07:00
|
|
|
requirer = alpm_db_get_pkg (priv->localdb, name);
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
if (requirer != NULL) {
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_pkg_emit (job, requirer, PK_INFO_ENUM_INSTALLED);
|
2014-09-05 06:00:37 -07:00
|
|
|
if (recursive)
|
2011-02-04 17:38:48 -08:00
|
|
|
pkgs = alpm_list_add (pkgs, requirer);
|
|
|
|
} else {
|
2011-10-26 02:44:37 -07:00
|
|
|
int code = ALPM_ERR_PKG_NOT_FOUND;
|
2014-09-05 08:03:17 -07:00
|
|
|
g_set_error (error, PK_ALPM_ERROR, code, "%s: %s", name,
|
2011-02-04 17:38:48 -08:00
|
|
|
alpm_strerror (code));
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgs;
|
|
|
|
}
|
|
|
|
|
2014-08-04 06:50:03 -07:00
|
|
|
static void
|
|
|
|
pk_backend_depends_on_thread (PkBackendJob* job, GVariant* params, gpointer p)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
|
|
|
gchar **packages;
|
|
|
|
alpm_list_t *i, *pkgs = NULL;
|
2016-01-28 01:10:29 -08:00
|
|
|
g_autoptr(GError) error = NULL;
|
2014-08-04 06:50:03 -07:00
|
|
|
PkBitfield filters;
|
|
|
|
gboolean recursive;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2014-09-05 06:00:37 -07:00
|
|
|
g_variant_get (params, "(t^a&sb)",
|
|
|
|
&filters, &packages, &recursive);
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
/* construct an initial package list */
|
|
|
|
for (; *packages != NULL; ++packages) {
|
2011-10-28 06:21:41 -07:00
|
|
|
alpm_pkg_t *pkg;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job))
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
2014-09-05 08:03:17 -07:00
|
|
|
pkg = pk_alpm_find_pkg (job, *packages, &error);
|
2014-09-05 06:00:37 -07:00
|
|
|
if (pkg == NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
pkgs = alpm_list_add (pkgs, pkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* package list might be modified along the way but that is ok */
|
|
|
|
for (i = pkgs; i != NULL; i = i->next) {
|
|
|
|
const alpm_list_t *depends;
|
|
|
|
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job) || error != NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
2014-08-04 06:50:03 -07:00
|
|
|
depends = alpm_pkg_get_depends (i->data);
|
2011-02-04 17:38:48 -08:00
|
|
|
for (; depends != NULL; depends = depends->next) {
|
2016-01-28 01:10:29 -08:00
|
|
|
g_autofree gchar *depend = NULL;
|
2011-03-31 15:21:05 -07:00
|
|
|
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job) || error != NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
2011-03-31 15:21:05 -07:00
|
|
|
depend = alpm_dep_compute_string (depends->data);
|
2014-09-05 08:03:17 -07:00
|
|
|
pkgs = pk_alpm_find_provider (job, pkgs, depend, recursive, filters, &error);
|
2011-02-04 17:38:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
alpm_list_free (pkgs);
|
|
|
|
}
|
|
|
|
|
2014-08-04 06:50:03 -07:00
|
|
|
static void
|
|
|
|
pk_backend_required_by_thread (PkBackendJob* job, GVariant* params, gpointer p)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
|
|
|
gchar **packages;
|
|
|
|
alpm_list_t *i, *pkgs = NULL;
|
2016-01-28 01:10:29 -08:00
|
|
|
g_autoptr(GError) error = NULL;
|
2014-08-04 06:50:03 -07:00
|
|
|
gboolean recursive;
|
|
|
|
PkBitfield filters;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2014-09-05 06:00:37 -07:00
|
|
|
g_variant_get (params, "(t^a&sb)",
|
|
|
|
&filters, &packages, &recursive);
|
2011-02-04 17:38:48 -08:00
|
|
|
|
|
|
|
/* construct an initial package list */
|
|
|
|
for (; *packages != NULL; ++packages) {
|
2011-10-28 06:21:41 -07:00
|
|
|
alpm_pkg_t *pkg;
|
2011-02-04 17:38:48 -08:00
|
|
|
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job))
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
2014-09-05 08:03:17 -07:00
|
|
|
pkg = pk_alpm_find_pkg (job, *packages, &error);
|
2014-09-05 06:00:37 -07:00
|
|
|
if (pkg == NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
pkgs = alpm_list_add (pkgs, pkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* package list might be modified along the way but that is ok */
|
|
|
|
for (i = pkgs; i != NULL; i = i->next) {
|
|
|
|
alpm_list_t *requiredby;
|
|
|
|
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job) || error != NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
requiredby = alpm_pkg_compute_requiredby (i->data);
|
|
|
|
for (; requiredby != NULL; requiredby = requiredby->next) {
|
2014-09-06 06:21:59 -07:00
|
|
|
if (pk_backend_job_is_cancelled (job) || error != NULL)
|
2011-02-04 17:38:48 -08:00
|
|
|
break;
|
|
|
|
|
2014-08-04 06:50:03 -07:00
|
|
|
pkgs = pk_backend_find_requirer (job, pkgs,
|
|
|
|
requiredby->data, recursive, &error);
|
2011-02-04 17:38:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
FREELIST (requiredby);
|
|
|
|
}
|
|
|
|
|
|
|
|
alpm_list_free (pkgs);
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_finish (job, error);
|
2011-02-04 17:38:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-04 06:50:03 -07:00
|
|
|
pk_backend_depends_on (PkBackend *self,
|
2014-09-05 06:00:37 -07:00
|
|
|
PkBackendJob *job,
|
|
|
|
PkBitfield filters,
|
|
|
|
gchar **package_ids,
|
|
|
|
gboolean recursive)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_run (job, PK_STATUS_ENUM_QUERY, pk_backend_depends_on_thread, NULL);
|
2011-02-04 17:38:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-05 06:00:37 -07:00
|
|
|
pk_backend_required_by (PkBackend *self,
|
|
|
|
PkBackendJob *job,
|
|
|
|
PkBitfield filters,
|
|
|
|
gchar **package_ids,
|
|
|
|
gboolean recursive)
|
2011-02-04 17:38:48 -08:00
|
|
|
{
|
2014-09-05 08:03:17 -07:00
|
|
|
pk_alpm_run (job, PK_STATUS_ENUM_QUERY, pk_backend_required_by_thread, NULL);
|
2011-02-04 17:38:48 -08:00
|
|
|
}
|