mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
Make alpm_db_set_pkgreason() arguments more sane
This can only ever operate on the local database, and a local package at that. Change the function signature to take a handle and package object, add the relevant asserts, and ensure the frontend can detect the package not found condition when finding packages to pass to this method. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
0fe93bc34c
commit
8f72ffbc45
@ -476,12 +476,13 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
|
|||||||
alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles);
|
alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles);
|
||||||
|
|
||||||
/** Set install reason for a package in db.
|
/** Set install reason for a package in db.
|
||||||
* @param db pointer to the package database
|
* @param handle the context handle
|
||||||
* @param name the name of the package
|
* @param pkg the package to update
|
||||||
* @param reason the new install reason
|
* @param reason the new install reason
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
*/
|
*/
|
||||||
int alpm_db_set_pkgreason(alpm_db_t *db, const char *name, alpm_pkgreason_t reason);
|
int alpm_db_set_pkgreason(alpm_handle_t *handle, alpm_pkg_t *pkg,
|
||||||
|
alpm_pkgreason_t reason);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@ -241,12 +241,17 @@ int SYMEXPORT alpm_db_get_valid(alpm_db_t *db)
|
|||||||
/** Get a package entry from a package database. */
|
/** Get a package entry from a package database. */
|
||||||
alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name)
|
alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name)
|
||||||
{
|
{
|
||||||
|
alpm_pkg_t *pkg;
|
||||||
ASSERT(db != NULL, return NULL);
|
ASSERT(db != NULL, return NULL);
|
||||||
db->handle->pm_errno = 0;
|
db->handle->pm_errno = 0;
|
||||||
ASSERT(name != NULL && strlen(name) != 0,
|
ASSERT(name != NULL && strlen(name) != 0,
|
||||||
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
|
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
|
||||||
|
|
||||||
return _alpm_db_get_pkgfromcache(db, name);
|
pkg = _alpm_db_get_pkgfromcache(db, name);
|
||||||
|
if(!pkg) {
|
||||||
|
RET_ERR(db->handle, ALPM_ERR_PKG_NOT_FOUND, NULL);
|
||||||
|
}
|
||||||
|
return pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the package cache of a package database. */
|
/** Get the package cache of a package database. */
|
||||||
@ -287,19 +292,18 @@ alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Set install reason for a package in db. */
|
/** Set install reason for a package in db. */
|
||||||
int SYMEXPORT alpm_db_set_pkgreason(alpm_db_t *db, const char *name, alpm_pkgreason_t reason)
|
int SYMEXPORT alpm_db_set_pkgreason(alpm_handle_t *handle, alpm_pkg_t *pkg,
|
||||||
|
alpm_pkgreason_t reason)
|
||||||
{
|
{
|
||||||
ASSERT(db != NULL, return -1);
|
CHECK_HANDLE(handle, return -1);
|
||||||
db->handle->pm_errno = 0;
|
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
||||||
/* TODO assert db == db_local ? shouldn't need a db param at all here... */
|
ASSERT(pkg->origin == PKG_FROM_LOCALDB,
|
||||||
ASSERT(name != NULL, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
||||||
|
ASSERT(pkg->origin_data.db == handle->db_local,
|
||||||
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
||||||
|
|
||||||
alpm_pkg_t *pkg = _alpm_db_get_pkgfromcache(db, name);
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
||||||
if(pkg == NULL) {
|
"setting install reason %u for %s\n", reason, pkg->name);
|
||||||
RET_ERR(db->handle, ALPM_ERR_PKG_NOT_FOUND, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
_alpm_log(db->handle, ALPM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
|
|
||||||
if(alpm_pkg_get_reason(pkg) == reason) {
|
if(alpm_pkg_get_reason(pkg) == reason) {
|
||||||
/* we are done */
|
/* we are done */
|
||||||
return 0;
|
return 0;
|
||||||
@ -307,8 +311,8 @@ int SYMEXPORT alpm_db_set_pkgreason(alpm_db_t *db, const char *name, alpm_pkgrea
|
|||||||
/* set reason (in pkgcache) */
|
/* set reason (in pkgcache) */
|
||||||
pkg->reason = reason;
|
pkg->reason = reason;
|
||||||
/* write DESC */
|
/* write DESC */
|
||||||
if(_alpm_local_db_write(db, pkg, INFRQ_DESC)) {
|
if(_alpm_local_db_write(handle->db_local, pkg, INFRQ_DESC)) {
|
||||||
RET_ERR(db->handle, ALPM_ERR_DB_WRITE, -1);
|
RET_ERR(handle, ALPM_ERR_DB_WRITE, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -66,7 +66,8 @@ int pacman_database(alpm_list_t *targets)
|
|||||||
db_local = alpm_option_get_localdb(config->handle);
|
db_local = alpm_option_get_localdb(config->handle);
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
char *pkgname = i->data;
|
char *pkgname = i->data;
|
||||||
if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) {
|
alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
|
||||||
|
if(!pkg || alpm_db_set_pkgreason(config->handle, pkg, reason)) {
|
||||||
pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
|
pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
|
||||||
pkgname, alpm_strerror(alpm_errno(config->handle)));
|
pkgname, alpm_strerror(alpm_errno(config->handle)));
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user