mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
Remove global handle from remove.c
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
307a6de17a
commit
d2f05f72f0
@ -527,7 +527,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
|
|||||||
|
|
||||||
if(oldpkg) {
|
if(oldpkg) {
|
||||||
/* set up fake remove transaction */
|
/* set up fake remove transaction */
|
||||||
if(_alpm_upgraderemove_package(oldpkg, newpkg, trans) == -1) {
|
if(_alpm_upgraderemove_package(handle, oldpkg, newpkg) == -1) {
|
||||||
pm_errno = PM_ERR_TRANS_ABORT;
|
pm_errno = PM_ERR_TRANS_ABORT;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -44,9 +44,6 @@
|
|||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
#include "handle.h"
|
#include "handle.h"
|
||||||
|
|
||||||
/* global handle variable */
|
|
||||||
extern pmhandle_t *handle;
|
|
||||||
|
|
||||||
int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
|
int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
|
||||||
{
|
{
|
||||||
pmtrans_t *trans;
|
pmtrans_t *trans;
|
||||||
@ -54,8 +51,7 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
|
|||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
trans = pkg->handle->trans;
|
||||||
trans = handle->trans;
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
ASSERT(trans->state == STATE_INITIALIZED,
|
ASSERT(trans->state == STATE_INITIALIZED,
|
||||||
RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
||||||
@ -129,16 +125,14 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
|
|||||||
* This functions takes a pointer to a alpm_list_t which will be
|
* This functions takes a pointer to a alpm_list_t which will be
|
||||||
* filled with a list of pmdepmissing_t* objects representing
|
* filled with a list of pmdepmissing_t* objects representing
|
||||||
* the packages blocking the transaction.
|
* the packages blocking the transaction.
|
||||||
* @param trans the transaction object
|
* @param handle the context handle
|
||||||
* @param db the database of local packages
|
|
||||||
* @param data a pointer to an alpm_list_t* to fill
|
* @param data a pointer to an alpm_list_t* to fill
|
||||||
*/
|
*/
|
||||||
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
|
int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data)
|
||||||
{
|
{
|
||||||
alpm_list_t *lp;
|
alpm_list_t *lp;
|
||||||
|
pmtrans_t *trans = handle->trans;
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
pmdb_t *db = handle->db_local;
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
|
|
||||||
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
|
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
|
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
|
||||||
@ -190,7 +184,7 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_remove_file(const char *path, alpm_list_t *skip)
|
static int can_remove_file(pmhandle_t *handle, const char *path, alpm_list_t *skip)
|
||||||
{
|
{
|
||||||
char file[PATH_MAX+1];
|
char file[PATH_MAX+1];
|
||||||
|
|
||||||
@ -217,7 +211,8 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
|
|||||||
|
|
||||||
/* Helper function for iterating through a package's file and deleting them
|
/* Helper function for iterating through a package's file and deleting them
|
||||||
* Used by _alpm_remove_commit. */
|
* Used by _alpm_remove_commit. */
|
||||||
static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, int nosave)
|
static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename,
|
||||||
|
alpm_list_t *skip_remove, int nosave)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
char file[PATH_MAX+1];
|
char file[PATH_MAX+1];
|
||||||
@ -281,8 +276,8 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
|
int _alpm_upgraderemove_package(pmhandle_t *handle,
|
||||||
pmtrans_t *trans)
|
pmpkg_t *oldpkg, pmpkg_t *newpkg)
|
||||||
{
|
{
|
||||||
alpm_list_t *skip_remove, *b;
|
alpm_list_t *skip_remove, *b;
|
||||||
alpm_list_t *newfiles, *lp;
|
alpm_list_t *newfiles, *lp;
|
||||||
@ -293,13 +288,13 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
|
|||||||
_alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
_alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
|
||||||
oldpkg->name, oldpkg->version);
|
oldpkg->name, oldpkg->version);
|
||||||
|
|
||||||
if(trans->flags & PM_TRANS_FLAG_DBONLY) {
|
if(handle->trans->flags & PM_TRANS_FLAG_DBONLY) {
|
||||||
goto db;
|
goto db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the remove skiplist over */
|
/* copy the remove skiplist over */
|
||||||
skip_remove = alpm_list_join(
|
skip_remove = alpm_list_join(
|
||||||
alpm_list_strdup(trans->skip_remove),
|
alpm_list_strdup(handle->trans->skip_remove),
|
||||||
alpm_list_strdup(handle->noupgrade));
|
alpm_list_strdup(handle->noupgrade));
|
||||||
/* Add files in the NEW backup array to the skip_remove array
|
/* Add files in the NEW backup array to the skip_remove array
|
||||||
* so this removal operation doesn't kill them */
|
* so this removal operation doesn't kill them */
|
||||||
@ -317,7 +312,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(lp = files; lp; lp = lp->next) {
|
for(lp = files; lp; lp = lp->next) {
|
||||||
if(!can_remove_file(lp->data, skip_remove)) {
|
if(!can_remove_file(handle, lp->data, skip_remove)) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
||||||
pkgname);
|
pkgname);
|
||||||
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
||||||
@ -330,7 +325,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
|
|||||||
/* iterate through the list backwards, unlinking files */
|
/* iterate through the list backwards, unlinking files */
|
||||||
newfiles = alpm_list_reverse(files);
|
newfiles = alpm_list_reverse(files);
|
||||||
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
||||||
unlink_file(oldpkg, lp->data, skip_remove, 0);
|
unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
|
||||||
}
|
}
|
||||||
alpm_list_free(newfiles);
|
alpm_list_free(newfiles);
|
||||||
FREELIST(skip_remove);
|
FREELIST(skip_remove);
|
||||||
@ -352,14 +347,12 @@ db:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
int _alpm_remove_packages(pmhandle_t *handle)
|
||||||
{
|
{
|
||||||
pmpkg_t *info;
|
pmpkg_t *info;
|
||||||
alpm_list_t *targ, *lp;
|
alpm_list_t *targ, *lp;
|
||||||
size_t pkg_count;
|
size_t pkg_count;
|
||||||
|
pmtrans_t *trans = handle->trans;
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
|
|
||||||
pkg_count = alpm_list_count(trans->remove);
|
pkg_count = alpm_list_count(trans->remove);
|
||||||
|
|
||||||
@ -370,14 +363,14 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
const char *pkgname = NULL;
|
const char *pkgname = NULL;
|
||||||
size_t targcount = alpm_list_count(targ);
|
size_t targcount = alpm_list_count(targ);
|
||||||
|
|
||||||
if(handle->trans->state == STATE_INTERRUPTED) {
|
if(trans->state == STATE_INTERRUPTED) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the name now so we can use it after package is removed */
|
/* get the name now so we can use it after package is removed */
|
||||||
pkgname = alpm_pkg_get_name(info);
|
pkgname = alpm_pkg_get_name(info);
|
||||||
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
|
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
|
||||||
_alpm_db_path(db), pkgname, alpm_pkg_get_version(info));
|
_alpm_db_path(handle->db_local), pkgname, alpm_pkg_get_version(info));
|
||||||
|
|
||||||
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
|
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
|
||||||
_alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
|
_alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
|
||||||
@ -395,7 +388,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
size_t filenum;
|
size_t filenum;
|
||||||
|
|
||||||
for(lp = files; lp; lp = lp->next) {
|
for(lp = files; lp; lp = lp->next) {
|
||||||
if(!can_remove_file(lp->data, NULL)) {
|
if(!can_remove_file(handle, lp->data, NULL)) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
|
||||||
pkgname);
|
pkgname);
|
||||||
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
|
||||||
@ -413,7 +406,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
newfiles = alpm_list_reverse(files);
|
newfiles = alpm_list_reverse(files);
|
||||||
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
|
||||||
int percent;
|
int percent;
|
||||||
unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
|
unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
|
||||||
|
|
||||||
/* update progress bar after each file */
|
/* update progress bar after each file */
|
||||||
percent = (position * 100) / filenum;
|
percent = (position * 100) / filenum;
|
||||||
@ -437,12 +430,12 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
|
|||||||
/* remove the package from the database */
|
/* remove the package from the database */
|
||||||
_alpm_log(PM_LOG_DEBUG, "updating database\n");
|
_alpm_log(PM_LOG_DEBUG, "updating database\n");
|
||||||
_alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
|
_alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
|
||||||
if(_alpm_local_db_remove(db, info) == -1) {
|
if(_alpm_local_db_remove(handle->db_local, info) == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
|
||||||
pkgname, alpm_pkg_get_version(info));
|
pkgname, alpm_pkg_get_version(info));
|
||||||
}
|
}
|
||||||
/* remove the package from the cache */
|
/* remove the package from the cache */
|
||||||
if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
|
if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
_alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
|
||||||
pkgname);
|
pkgname);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,11 @@
|
|||||||
#include "alpm_list.h"
|
#include "alpm_list.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
|
|
||||||
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
|
int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data);
|
||||||
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
|
int _alpm_remove_packages(pmhandle_t *handle);
|
||||||
|
|
||||||
int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
|
int _alpm_upgraderemove_package(pmhandle_t *handle,
|
||||||
|
pmpkg_t *oldpkg, pmpkg_t *newpkg);
|
||||||
|
|
||||||
#endif /* _ALPM_REMOVE_H */
|
#endif /* _ALPM_REMOVE_H */
|
||||||
|
|
||||||
|
@ -947,7 +947,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
if(replaces) {
|
if(replaces) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
|
_alpm_log(PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
|
||||||
/* we want the frontend to be aware of commit details */
|
/* we want the frontend to be aware of commit details */
|
||||||
if(_alpm_remove_packages(trans, handle->db_local) == -1) {
|
if(_alpm_remove_packages(handle) == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n"));
|
_alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(trans->add == NULL) {
|
if(trans->add == NULL) {
|
||||||
if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
|
if(_alpm_remove_prepare(handle, data) == -1) {
|
||||||
/* pm_errno is set by _alpm_remove_prepare() */
|
/* pm_errno is set by _alpm_remove_prepare() */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
|
|||||||
trans->state = STATE_COMMITING;
|
trans->state = STATE_COMMITING;
|
||||||
|
|
||||||
if(trans->add == NULL) {
|
if(trans->add == NULL) {
|
||||||
if(_alpm_remove_packages(trans, handle->db_local) == -1) {
|
if(_alpm_remove_packages(handle) == -1) {
|
||||||
/* pm_errno is set by _alpm_remove_commit() */
|
/* pm_errno is set by _alpm_remove_commit() */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user