diff options
Diffstat (limited to 'lib/libalpm/remove.c')
-rw-r--r-- | lib/libalpm/remove.c | 188 |
1 files changed, 89 insertions, 99 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index cf416d52..264d79ea 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -44,64 +44,62 @@ #include "deps.h" #include "handle.h" -int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg) +int SYMEXPORT alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg) { - pmtrans_t *trans; const char *pkgname; - - ALPM_LOG_FUNC; + pmtrans_t *trans; /* Sanity checks */ - ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + ASSERT(handle != NULL, return -1); + ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1)); + ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1)); trans = handle->trans; - ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); + ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1)); ASSERT(trans->state == STATE_INITIALIZED, - RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1)); + RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1)); pkgname = pkg->name; if(_alpm_pkg_find(trans->remove, pkgname)) { - RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1); + RET_ERR(handle, PM_ERR_TRANS_DUP_TARGET, -1); } - _alpm_log(PM_LOG_DEBUG, "adding package %s to the transaction remove list\n", + _alpm_log(handle, 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; } -static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db, - alpm_list_t *lp) +static void remove_prepare_cascade(pmhandle_t *handle, alpm_list_t *lp) { - ALPM_LOG_FUNC; + pmtrans_t *trans = handle->trans; while(lp) { alpm_list_t *i; for(i = lp; i; i = i->next) { pmdepmissing_t *miss = (pmdepmissing_t *)i->data; - pmpkg_t *info = _alpm_db_get_pkgfromcache(db, miss->target); + pmpkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target); if(info) { if(!_alpm_pkg_find(trans->remove, alpm_pkg_get_name(info))) { - _alpm_log(PM_LOG_DEBUG, "pulling %s in target list\n", + _alpm_log(handle, PM_LOG_DEBUG, "pulling %s in target list\n", alpm_pkg_get_name(info)); trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info)); } } else { - _alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"), + _alpm_log(handle, PM_LOG_ERROR, _("could not find %s in database -- skipping\n"), miss->target); } } alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free); alpm_list_free(lp); - lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL); + lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local), + trans->remove, NULL, 1); } } -static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db, - alpm_list_t *lp) +static void remove_prepare_keep_needed(pmhandle_t *handle, alpm_list_t *lp) { - ALPM_LOG_FUNC; + pmtrans_t *trans = handle->trans; /* Remove needed packages (which break dependencies) from target list */ while(lp != NULL) { @@ -117,14 +115,15 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db, &vpkg); pkg = vpkg; if(pkg) { - _alpm_log(PM_LOG_WARNING, _("removing %s from target list\n"), + _alpm_log(handle, PM_LOG_WARNING, _("removing %s from target list\n"), alpm_pkg_get_name(pkg)); _alpm_pkg_free(pkg); } } alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free); alpm_list_free(lp); - lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL); + lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local), + trans->remove, NULL, 1); } } @@ -132,37 +131,34 @@ 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"); - _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL); + _alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n"); + _alpm_recursedeps(db, trans->remove, + trans->flags & PM_TRANS_FLAG_RECURSEALL); } if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); - _alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); - lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL); + _alpm_log(handle, PM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); + lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); if(lp != NULL) { if(trans->flags & PM_TRANS_FLAG_CASCADE) { - remove_prepare_cascade(trans, db, lp); + remove_prepare_cascade(handle, lp); } 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); + remove_prepare_keep_needed(handle, lp); } else { if(data) { *data = lp; @@ -170,21 +166,21 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free); alpm_list_free(lp); } - RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1); + RET_ERR(handle, PM_ERR_UNSATISFIED_DEPS, -1); } } } /* re-order w.r.t. dependencies */ - _alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n"); - lp = _alpm_sortbydeps(trans->remove, 1); + _alpm_log(handle, PM_LOG_DEBUG, "sorting by dependencies\n"); + lp = _alpm_sortbydeps(handle, trans->remove, 1); /* free the old alltargs */ alpm_list_free(trans->remove); trans->remove = lp; /* -Rcs == -Rc then -Rs */ if((trans->flags & PM_TRANS_FLAG_CASCADE) && (trans->flags & PM_TRANS_FLAG_RECURSE)) { - _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n"); + _alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n"); _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL); } @@ -195,9 +191,10 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) 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]; snprintf(file, PATH_MAX, "%s%s", handle->root, path); @@ -211,7 +208,7 @@ static int can_remove_file(const char *path, alpm_list_t *skip) if(errno != EACCES && errno != ETXTBSY && access(file, F_OK) == 0) { /* only return failure if the file ACTUALLY exists and we can't write to * it - ignore "chmod -w" simple permission failures */ - _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"), + _alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"), file, strerror(errno)); return 0; } @@ -222,12 +219,11 @@ static int can_remove_file(const char *path, alpm_list_t *skip) /* 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; + char file[PATH_MAX]; snprintf(file, PATH_MAX, "%s%s", handle->root, filename); @@ -235,7 +231,7 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, * see the big comment block in db_find_fileconflicts() for an * explanation. */ if(alpm_list_find_str(skip_remove, filename)) { - _alpm_log(PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n", + _alpm_log(handle, PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n", file); return; } @@ -245,51 +241,51 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, * filesystem, we want to work with the linked directory instead of the * actual symlink */ if(lstat(file, &buf)) { - _alpm_log(PM_LOG_DEBUG, "file %s does not exist\n", file); + _alpm_log(handle, PM_LOG_DEBUG, "file %s does not exist\n", file); return; } if(S_ISDIR(buf.st_mode)) { if(rmdir(file)) { /* this is okay, other packages are probably using it (like /usr) */ - _alpm_log(PM_LOG_DEBUG, "keeping directory %s\n", file); + _alpm_log(handle, PM_LOG_DEBUG, "keeping directory %s\n", file); } else { - _alpm_log(PM_LOG_DEBUG, "removing directory %s\n", file); + _alpm_log(handle, PM_LOG_DEBUG, "removing directory %s\n", file); } } else { /* if the file needs backup and has been modified, back it up to .pacsave */ char *pkghash = _alpm_needbackup(filename, alpm_pkg_get_backup(info)); if(pkghash) { if(nosave) { - _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file); + _alpm_log(handle, PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file); FREE(pkghash); } else { char *filehash = alpm_compute_md5sum(file); - int cmp = strcmp(filehash,pkghash); + int cmp = filehash ? strcmp(filehash, pkghash) : 0; FREE(filehash); FREE(pkghash); if(cmp != 0) { char newpath[PATH_MAX]; snprintf(newpath, PATH_MAX, "%s.pacsave", file); rename(file, newpath); - _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); - alpm_logaction("warning: %s saved as %s\n", file, newpath); + _alpm_log(handle, PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); + alpm_logaction(handle, "warning: %s saved as %s\n", file, newpath); return; } } } - _alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file); + _alpm_log(handle, PM_LOG_DEBUG, "unlinking %s\n", file); if(unlink(file) == -1) { - _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"), + _alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"), filename, strerror(errno)); } } } -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; @@ -297,18 +293,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", + _alpm_log(handle, 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 */ @@ -321,56 +315,52 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, FREE(backup); continue; } - _alpm_log(PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup); + _alpm_log(handle, PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup); skip_remove = alpm_list_add(skip_remove, backup); } for(lp = files; lp; lp = lp->next) { - if(!can_remove_file(lp->data, skip_remove)) { - _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n", + if(!can_remove_file(handle, lp->data, skip_remove)) { + _alpm_log(handle, PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n", pkgname); - RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1); + RET_ERR(handle, PM_ERR_PKG_CANT_REMOVE, -1); } } filenum = alpm_list_count(files); - _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum); + _alpm_log(handle, PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum); /* 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); db: /* 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); + _alpm_log(handle, PM_LOG_DEBUG, "updating database\n"); + _alpm_log(handle, PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname); if(_alpm_local_db_remove(handle->db_local, oldpkg) == -1) { - _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"), + _alpm_log(handle, PM_LOG_ERROR, _("could not remove database entry %s-%s\n"), pkgname, alpm_pkg_get_version(oldpkg)); } /* remove the package from the cache */ if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) { - _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"), + _alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"), pkgname); } 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); @@ -381,23 +371,23 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) const char *pkgname = NULL; size_t targcount = alpm_list_count(targ); - if(handle->trans->state == STATE_INTERRUPTED) { + 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", + _alpm_log(handle, PM_LOG_DEBUG, "removing package %s-%s\n", pkgname, alpm_pkg_get_version(info)); /* 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)) { @@ -406,15 +396,15 @@ 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)) { - _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n", + if(!can_remove_file(handle, lp->data, NULL)) { + _alpm_log(handle, PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n", pkgname); - RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1); + RET_ERR(handle, PM_ERR_PKG_CANT_REMOVE, -1); } } filenum = alpm_list_count(files); - _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum); + _alpm_log(handle, PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum); /* init progress bar */ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0, @@ -424,7 +414,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; @@ -441,20 +431,20 @@ 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) { - _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"), + _alpm_log(handle, PM_LOG_DEBUG, "updating database\n"); + _alpm_log(handle, PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname); + if(_alpm_local_db_remove(handle->db_local, info) == -1) { + _alpm_log(handle, 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) { - _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"), + if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -1) { + _alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"), pkgname); } @@ -462,7 +452,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db) } /* run ldconfig if it exists */ - _alpm_ldconfig(handle->root); + _alpm_ldconfig(handle); return 0; } |