alpm: use separate alpm_handle_t for updates
This prevents updating the system syncdbs without updating packages, which often leads to undesirable behaviour on most alpm-based distros.
This commit is contained in:
parent
eba92454d3
commit
a76711fd45
@ -24,6 +24,7 @@
|
||||
#include <alpm.h>
|
||||
#include <glob.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <syslog.h>
|
||||
@ -39,7 +40,7 @@ static gchar *xfercmd = NULL;
|
||||
typedef struct
|
||||
{
|
||||
gboolean checkspace, color, disabledownloadtimeout, ilovecandy,
|
||||
totaldl, usesyslog, verbosepkglists;
|
||||
totaldl, usesyslog, verbosepkglists, is_check;
|
||||
|
||||
gchar *arch, *cleanmethod, *dbpath, *gpgdir, *logfile,
|
||||
*root, *xfercmd;
|
||||
@ -633,7 +634,16 @@ pk_alpm_config_initialize_alpm (PkAlpmConfig *config, GError **error)
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_debug ("initializing alpm");
|
||||
if (config->is_check) {
|
||||
g_free(config->dbpath);
|
||||
gchar* path = g_strconcat (config->root,
|
||||
"/var/lib/PackageKit/alpm" + dir,
|
||||
NULL);
|
||||
g_mkdir_with_parents(path, 0755);
|
||||
config->dbpath = path;
|
||||
}
|
||||
|
||||
|
||||
handle = alpm_initialize (config->root, config->dbpath, &errno);
|
||||
if (handle == NULL) {
|
||||
g_set_error_literal (error, PK_ALPM_ERROR, errno,
|
||||
@ -660,6 +670,13 @@ pk_alpm_config_initialize_alpm (PkAlpmConfig *config, GError **error)
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (config->is_check) {
|
||||
g_free(config->logfile);
|
||||
config->logfile = g_strconcat (config->root,
|
||||
"/var/log/pacman.PackageKit.log" + dir,
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (alpm_option_set_logfile (handle, config->logfile) < 0) {
|
||||
errno = alpm_errno (handle);
|
||||
g_set_error (error, PK_ALPM_ERROR, errno, "LogFile: %s",
|
||||
@ -812,7 +829,14 @@ pk_alpm_config_configure_repos (PkBackend *backend, PkAlpmConfig *config,
|
||||
if (repo_level == ALPM_SIG_USE_DEFAULT)
|
||||
return FALSE;
|
||||
|
||||
pk_alpm_add_database (backend, repo->name, repo->servers, repo_level);
|
||||
if (!config->is_check) {
|
||||
pk_alpm_add_database (backend, repo->name, repo->servers, repo_level);
|
||||
} else {
|
||||
alpm_db_t *db;
|
||||
|
||||
db = alpm_register_syncdb (handle, repo->name, repo_level);
|
||||
alpm_db_set_servers (db, alpm_list_strdup (repo->servers));
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -967,7 +991,7 @@ pk_alpm_config_configure_alpm (PkBackend *backend, PkAlpmConfig *config, GError
|
||||
}
|
||||
|
||||
alpm_handle_t *
|
||||
pk_alpm_configure (PkBackend *backend, const gchar *filename, GError **error)
|
||||
pk_alpm_configure (PkBackend *backend, const gchar *filename, gboolean is_check, GError **error)
|
||||
{
|
||||
PkAlpmConfig *config;
|
||||
alpm_handle_t *handle = NULL;
|
||||
@ -979,8 +1003,11 @@ pk_alpm_configure (PkBackend *backend, const gchar *filename, GError **error)
|
||||
config = pk_alpm_config_new (backend);
|
||||
pk_alpm_config_enter_section (config, "options");
|
||||
|
||||
if (pk_alpm_config_parse (config, filename, NULL, &e))
|
||||
|
||||
if (pk_alpm_config_parse (config, filename, NULL, &e)) {
|
||||
config->is_check = is_check;
|
||||
handle = pk_alpm_config_configure_alpm (backend, config, &e);
|
||||
}
|
||||
|
||||
pk_alpm_config_free (config);
|
||||
if (e != NULL) {
|
||||
|
@ -24,4 +24,4 @@
|
||||
#include <alpm.h>
|
||||
#include <glib.h>
|
||||
|
||||
alpm_handle_t *pk_alpm_configure (PkBackend *backend, const gchar *filename, GError **error);
|
||||
alpm_handle_t *pk_alpm_configure (PkBackend *backend, const gchar *filename, gboolean is_check, GError **error);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <syslog.h>
|
||||
|
||||
#include "pk-backend-alpm.h"
|
||||
#include "pk-alpm-config.h"
|
||||
#include "pk-alpm-error.h"
|
||||
#include "pk-alpm-packages.h"
|
||||
#include "pk-alpm-transaction.h"
|
||||
@ -428,9 +429,26 @@ pk_backend_get_updates_thread (PkBackendJob *job, GVariant* params, gpointer p)
|
||||
PkBitfield filters = 0;
|
||||
FILE *file;
|
||||
int stored_count;
|
||||
alpm_cb_totaldl totaldlcb;
|
||||
gboolean ret;
|
||||
alpm_handle_t* handle = pk_alpm_configure (backend, PK_BACKEND_CONFIG_FILE, TRUE, error);
|
||||
|
||||
if (!pk_alpm_update_databases (job, 0, &error)) {
|
||||
return pk_alpm_error_emit (job, error);
|
||||
alpm_logaction (handle, PK_LOG_PREFIX, "synchronizing package lists\n");
|
||||
pk_backend_job_set_status (job, PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST);
|
||||
|
||||
/* set total size to minus the number of databases */
|
||||
i = alpm_get_syncdbs (handle);
|
||||
|
||||
for (; i != NULL; i = i->next) {
|
||||
if (pk_backend_job_is_cancelled (job)) {
|
||||
/* pretend to be finished */
|
||||
i = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = pk_alpm_update_database (job, TRUE, i->data, error);
|
||||
if (!ret)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pk_backend_job_get_role (job) == PK_ROLE_ENUM_GET_UPDATES) {
|
||||
@ -438,7 +456,7 @@ pk_backend_get_updates_thread (PkBackendJob *job, GVariant* params, gpointer p)
|
||||
}
|
||||
|
||||
/* find outdated and replacement packages */
|
||||
syncdbs = alpm_get_syncdbs (priv->alpm);
|
||||
syncdbs = alpm_get_syncdbs (handle);
|
||||
for (i = alpm_db_get_pkgcache (priv->localdb); i != NULL; i = i->next) {
|
||||
PkInfoEnum info = PK_INFO_ENUM_NORMAL;
|
||||
alpm_pkg_t *upgrade = pk_alpm_pkg_find_update (i->data, syncdbs);
|
||||
|
@ -80,7 +80,7 @@ pk_alpm_initialize (PkBackend *backend, GError **error)
|
||||
{
|
||||
PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
|
||||
|
||||
priv->alpm = pk_alpm_configure (backend, PK_BACKEND_CONFIG_FILE, error);
|
||||
priv->alpm = pk_alpm_configure (backend, PK_BACKEND_CONFIG_FILE, FALSE, error);
|
||||
if (priv->alpm == NULL) {
|
||||
g_prefix_error (error, "using %s: ", PK_BACKEND_CONFIG_FILE);
|
||||
return FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user