From ac9dde072c56b9dbc3fe515dc3702c2c992f492f Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Wed, 20 May 2009 21:46:23 +0200 Subject: Introduce -D, --database The request of FS#12950 is implemented. On the backend side, I introduced a new function, alpm_db_set_pkgreason(), to modify the install reason of a package in the local database. On the front-end side, I introduced a new main operation, -D/--database, which has two options, --asdeps and --asexplicit. I documented this in pacman manual. I've created two pactests to test -D: database001.py and database002.py. Signed-off-by: Nagy Gabor Signed-off-by: Dan McGee --- lib/libalpm/alpm.h | 16 ++++++++++------ lib/libalpm/db.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 0a2ee846..33291325 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -158,6 +158,15 @@ void alpm_option_set_usedelta(int usedelta); pmdb_t *alpm_option_get_localdb(); alpm_list_t *alpm_option_get_syncdbs(); +/* + * Install reasons -- ie, why the package was installed + */ + +typedef enum _pmpkgreason_t { + PM_PKG_REASON_EXPLICIT = 0, /* explicitly requested by the user */ + PM_PKG_REASON_DEPEND = 1 /* installed as a dependency for another package */ +} pmpkgreason_t; + /* * Databases */ @@ -181,6 +190,7 @@ alpm_list_t *alpm_db_get_pkgcache(pmdb_t *db); pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name); alpm_list_t *alpm_db_get_grpcache(pmdb_t *db); alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles); +int alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason); /* * Packages @@ -188,12 +198,6 @@ alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles); /* Info parameters */ -/* reasons -- ie, why the package was installed */ -typedef enum _pmpkgreason_t { - PM_PKG_REASON_EXPLICIT = 0, /* explicitly requested by the user */ - PM_PKG_REASON_DEPEND = 1 /* installed as a dependency for another package */ -} pmpkgreason_t; - int alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg); int alpm_pkg_free(pmpkg_t *pkg); int alpm_pkg_checkmd5sum(pmpkg_t *pkg); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 6e266501..c8a91a2b 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -321,6 +321,44 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles) return(_alpm_db_search(db, needles)); } +/* Set install reason for a package in db + * @param db pointer to the package database + * @param name the name of the package + * @param reason the new install reason + * @return 0 on success, -1 on error (pm_errno is set accordingly) + */ +int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason) +{ + ALPM_LOG_FUNC; + + /* Sanity checks */ + ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + ASSERT(db != NULL && name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + pmpkg_t *pkg = _alpm_db_get_pkgfromcache(db, name); + if(pkg == NULL) { + RET_ERR(PM_ERR_PKG_NOT_FOUND, -1); + } + + _alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name); + /* read DESC */ + if(_alpm_db_read(db, pkg, INFRQ_DESC)) { + return(-1); + } + if(pkg->reason == reason) { + /* we are done */ + return(0); + } + /* set reason (in pkgcache) */ + pkg->reason = reason; + /* write DESC */ + if(_alpm_db_write(db, pkg, INFRQ_DESC)) { + return(-1); + } + + return(0); +} + /** @} */ static pmdb_t *_alpm_db_new(const char *treename, int is_local) -- cgit v1.2.3-70-g09d2