diff options
Diffstat (limited to 'lib/libalpm/remove.c')
-rw-r--r-- | lib/libalpm/remove.c | 101 |
1 files changed, 41 insertions, 60 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 22ae2bb8..27305ae3 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -26,8 +26,6 @@ #include <stdlib.h> #include <errno.h> -#include <time.h> -#include <fcntl.h> #include <string.h> #include <limits.h> #include <unistd.h> @@ -36,6 +34,7 @@ /* libalpm */ #include "remove.h" #include "alpm_list.h" +#include "alpm.h" #include "trans.h" #include "util.h" #include "log.h" @@ -44,39 +43,34 @@ #include "db.h" #include "deps.h" #include "handle.h" -#include "alpm.h" int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg) { pmtrans_t *trans; const char *pkgname; - ALPM_LOG_FUNC; - /* Sanity checks */ ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - trans = handle->trans; + trans = pkg->handle->trans; ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1)); - pkgname = alpm_pkg_get_name(pkg); + pkgname = pkg->name; if(_alpm_pkg_find(trans->remove, pkgname)) { RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1); } - _alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", pkgname); + _alpm_log(PM_LOG_DEBUG, "adding package %s to the transaction remove list\n", + pkgname); trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg)); - return(0); + return 0; } static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db, alpm_list_t *lp) { - ALPM_LOG_FUNC; - while(lp) { alpm_list_t *i; for(i = lp; i; i = i->next) { @@ -102,8 +96,6 @@ static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db, static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db, alpm_list_t *lp) { - ALPM_LOG_FUNC; - /* Remove needed packages (which break dependencies) from target list */ while(lp != NULL) { alpm_list_t *i; @@ -133,18 +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 * filled with a list of pmdepmissing_t* objects representing * the packages blocking the transaction. - * @param trans the transaction object - * @param db the database of local packages + * @param handle the context handle * @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_LOG_FUNC; - - ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); - ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); + pmtrans_t *trans = handle->trans; + pmdb_t *db = handle->db_local; if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) { _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n"); @@ -160,7 +148,7 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) if(trans->flags & PM_TRANS_FLAG_CASCADE) { remove_prepare_cascade(trans, db, lp); - } else if (trans->flags & PM_TRANS_FLAG_UNNEEDED) { + } else if(trans->flags & PM_TRANS_FLAG_UNNEEDED) { /* Remove needed packages (which would break dependencies) * from target list */ remove_prepare_keep_needed(trans, db, lp); @@ -193,10 +181,10 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL); } - 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]; @@ -204,7 +192,7 @@ static int can_remove_file(const char *path, alpm_list_t *skip) if(alpm_list_find_str(skip, file)) { /* return success because we will never actually remove this file */ - return(1); + return 1; } /* If we fail write permissions due to a read-only filesystem, abort. * Assume all other possible failures are covered somewhere else */ @@ -214,22 +202,21 @@ static int can_remove_file(const char *path, alpm_list_t *skip) * it - ignore "chmod -w" simple permission failures */ _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"), file, strerror(errno)); - return(0); + return 0; } } - return(1); + return 1; } /* Helper function for iterating through a package's file and deleting them * 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; char file[PATH_MAX+1]; - ALPM_LOG_FUNC; - snprintf(file, PATH_MAX, "%s%s", handle->root, filename); /* check the remove skip list before removing the file. @@ -289,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, - pmtrans_t *trans) +int _alpm_upgraderemove_package(pmhandle_t *handle, + pmpkg_t *oldpkg, pmpkg_t *newpkg) { alpm_list_t *skip_remove, *b; alpm_list_t *newfiles, *lp; @@ -298,18 +285,16 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, alpm_list_t *files = alpm_pkg_get_files(oldpkg); const char *pkgname = alpm_pkg_get_name(oldpkg); - ALPM_LOG_FUNC; - _alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n", oldpkg->name, oldpkg->version); - if(trans->flags & PM_TRANS_FLAG_DBONLY) { + if(handle->trans->flags & PM_TRANS_FLAG_DBONLY) { goto db; } /* copy the remove skiplist over */ skip_remove = alpm_list_join( - alpm_list_strdup(trans->skip_remove), + alpm_list_strdup(handle->trans->skip_remove), alpm_list_strdup(handle->noupgrade)); /* Add files in the NEW backup array to the skip_remove array * so this removal operation doesn't kill them */ @@ -327,7 +312,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, } 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", pkgname); RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1); @@ -340,7 +325,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, /* iterate through the list backwards, unlinking files */ newfiles = alpm_list_reverse(files); 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); FREELIST(skip_remove); @@ -359,37 +344,33 @@ db: pkgname); } - return(0); + return 0; } -int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) +int _alpm_remove_packages(pmhandle_t *handle) { pmpkg_t *info; alpm_list_t *targ, *lp; size_t pkg_count; - - ALPM_LOG_FUNC; - - ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); - ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); + pmtrans_t *trans = handle->trans; pkg_count = alpm_list_count(trans->remove); for(targ = trans->remove; targ; targ = targ->next) { int position = 0; char scriptlet[PATH_MAX]; - info = (pmpkg_t*)targ->data; + info = (pmpkg_t *)targ->data; const char *pkgname = NULL; size_t targcount = alpm_list_count(targ); - if(handle->trans->state == STATE_INTERRUPTED) { - return(0); + if(trans->state == STATE_INTERRUPTED) { + return 0; } /* get the name now so we can use it after package is removed */ pkgname = alpm_pkg_get_name(info); 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); _alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n", @@ -397,8 +378,8 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) /* run the pre-remove scriptlet if it exists */ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { - _alpm_runscriptlet(handle->root, scriptlet, "pre_remove", - alpm_pkg_get_version(info), NULL, trans); + _alpm_runscriptlet(handle, scriptlet, "pre_remove", + alpm_pkg_get_version(info), NULL); } if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) { @@ -407,7 +388,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) size_t filenum; 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", pkgname); RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1); @@ -425,7 +406,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) newfiles = alpm_list_reverse(files); for(lp = newfiles; lp; lp = alpm_list_next(lp)) { 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 */ percent = (position * 100) / filenum; @@ -442,19 +423,19 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) /* run the post-remove script if it exists */ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { - _alpm_runscriptlet(handle->root, scriptlet, "post_remove", - alpm_pkg_get_version(info), NULL, trans); + _alpm_runscriptlet(handle, scriptlet, "post_remove", + alpm_pkg_get_version(info), NULL); } /* remove the package from the database */ _alpm_log(PM_LOG_DEBUG, "updating database\n"); _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"), pkgname, alpm_pkg_get_version(info)); } /* 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"), pkgname); } @@ -463,9 +444,9 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) } /* run ldconfig if it exists */ - _alpm_ldconfig(handle->root); + _alpm_ldconfig(handle); - return(0); + return 0; } /* vim: set ts=2 sw=2 noet: */ |