summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindings/alpm.i12
-rw-r--r--configure.ac4
-rw-r--r--lib/libalpm/add.h2
-rw-r--r--lib/libalpm/alpm.c340
-rw-r--r--lib/libalpm/alpm.h268
-rw-r--r--lib/libalpm/be_files.c6
-rw-r--r--lib/libalpm/cache.h4
-rw-r--r--lib/libalpm/conflict.c2
-rw-r--r--lib/libalpm/conflict.h5
-rw-r--r--lib/libalpm/db.c25
-rw-r--r--lib/libalpm/db.h23
-rw-r--r--lib/libalpm/deps.h11
-rw-r--r--lib/libalpm/group.c16
-rw-r--r--lib/libalpm/group.h11
-rw-r--r--lib/libalpm/handle.c346
-rw-r--r--lib/libalpm/handle.h51
-rw-r--r--lib/libalpm/list.c4
-rw-r--r--lib/libalpm/list.h8
-rw-r--r--lib/libalpm/log.c11
-rw-r--r--lib/libalpm/log.h7
-rw-r--r--lib/libalpm/package.c304
-rw-r--r--lib/libalpm/package.h18
-rw-r--r--lib/libalpm/provide.h5
-rw-r--r--lib/libalpm/remove.h2
-rw-r--r--lib/libalpm/server.c10
-rw-r--r--lib/libalpm/server.h20
-rw-r--r--lib/libalpm/sync.c33
-rw-r--r--lib/libalpm/sync.h9
-rw-r--r--lib/libalpm/trans.h25
-rw-r--r--lib/libalpm/util.c1
-rwxr-xr-xscripts/repo-add237
-rw-r--r--src/pacman/Makefile.am3
-rw-r--r--src/pacman/add.c10
-rw-r--r--src/pacman/conf.c3
-rw-r--r--src/pacman/conf.h8
-rw-r--r--src/pacman/deptest.c8
-rw-r--r--src/pacman/downloadprog.c2
-rw-r--r--src/pacman/list.c14
-rw-r--r--src/pacman/list.h12
-rw-r--r--src/pacman/package.c108
-rw-r--r--src/pacman/package.h8
-rw-r--r--src/pacman/pacman.c64
-rw-r--r--src/pacman/query.c103
-rw-r--r--src/pacman/remove.c24
-rw-r--r--src/pacman/sync.c122
-rw-r--r--src/pacman/sync.h2
-rw-r--r--src/pacman/trans.c40
-rw-r--r--src/pacman/util.c16
-rw-r--r--src/pacman/util.h4
49 files changed, 1293 insertions, 1078 deletions
diff --git a/bindings/alpm.i b/bindings/alpm.i
index 49541b91..661f1694 100644
--- a/bindings/alpm.i
+++ b/bindings/alpm.i
@@ -13,11 +13,11 @@
%pointer_cast(void *, long *, void_to_long);
%pointer_cast(void *, char *, void_to_char);
%pointer_cast(void *, unsigned long, void_to_unsigned_long);
-%pointer_cast(void *, PM_LIST *, void_to_PM_LIST);
-%pointer_cast(void *, PM_PKG *, void_to_PM_PKG);
-%pointer_cast(void *, PM_GRP *, void_to_PM_GRP);
-%pointer_cast(void *, PM_SYNCPKG *, void_to_PM_SYNCPKG);
-%pointer_cast(void *, PM_DB *, void_to_PM_DB);
-%pointer_cast(void *, PM_CONFLICT *, void_to_PM_CONFLICT);
+%pointer_cast(void *, pmlist_t *, void_to_pmlist);
+%pointer_cast(void *, pmpkg_t *, void_to_pmpkg);
+%pointer_cast(void *, pmgrp_t *, void_to_pmgrp);
+%pointer_cast(void *, pmsyncpkg_t *, void_to_pmsyncpkg);
+%pointer_cast(void *, pmdb_t *, void_to_pmdb);
+%pointer_cast(void *, pmconflict_t *, void_to_pmconflict);
%include "alpm.h"
diff --git a/configure.ac b/configure.ac
index 2c025350..2c04978d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ dnl Put out version numbers to config.h
AC_DEFINE_UNQUOTED([PM_VERSION], ["$PM_VERSION"], [libalpm version number])
dnl Configuration files
-AC_CONFIG_FILES([etc/makepkg.conf] [etc/pacman.conf])
+dnl AC_CONFIG_FILES([etc/makepkg.conf] [etc/pacman.conf])
AC_PROG_CC
AC_HEADER_STDC
@@ -353,6 +353,8 @@ doc/libalpm.3
doc/pacman.8
doc/hu/Makefile
etc/Makefile
+etc/makepkg.conf
+etc/pacman.conf
etc/pacman.d/Makefile
bindings/perl/Makefile
bindings/python/Makefile
diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h
index 9b77a2ca..d39aa140 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/add.h
@@ -21,8 +21,8 @@
#ifndef _ALPM_ADD_H
#define _ALPM_ADD_H
-#include "list.h"
#include "db.h"
+#include "list.h"
#include "trans.h"
int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index b642501b..49cfd0cd 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -65,7 +65,7 @@
pmhandle_t *handle = NULL;
enum __pmerrno_t pm_errno;
-/** @defgroup alpm_interface Interface Functions
+/** \addtogroup alpm_interface Interface Functions
* @brief Function to initialize and release libalpm
* @{
*/
@@ -75,7 +75,7 @@ enum __pmerrno_t pm_errno;
* @param root the full path of the root we'll be installing to (usually /)
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_initialize(char *root)
+int alpm_initialize(const char *root)
{
char str[PATH_MAX];
@@ -129,40 +129,12 @@ int alpm_release()
}
/** @} */
-/** @defgroup alpm_options Library Options
+/** \addtogroup alpm_options Library Options
* @brief Functions to set and get libalpm options
* @{
*/
-/** Set a library option.
- * @param parm the name of the parameter
- * @param data the value of the parameter
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int alpm_set_option(unsigned char parm, unsigned long data)
-{
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
-
- return(_alpm_handle_set_option(handle, parm, data));
-}
-
-/** Get the value of a library option.
- * @param parm the parameter to get
- * @param data pointer argument to get the value in
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int alpm_get_option(unsigned char parm, long *data)
-{
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-
- return(_alpm_handle_get_option(handle, parm, data));
-}
-/** @} */
-
-/** @defgroup alpm_databases Database Functions
+/** \addtogroup alpm_databases Database Functions
* @brief Frunctions to query and manipulate the database of libalpm
* @{
*/
@@ -224,36 +196,6 @@ int alpm_db_unregister(pmdb_t *db)
return(0);
}
-/** Get informations about a database.
- * @param db database pointer
- * @param parm name of the info to get
- * @return a void* on success (the value), NULL on error
- */
-void *alpm_db_getinfo(PM_DB *db, unsigned char parm)
-{
- void *data = NULL;
- char path[PATH_MAX];
- pmserver_t *server;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
-
- switch(parm) {
- case PM_DB_TREENAME: data = db->treename; break;
- case PM_DB_FIRSTSERVER:
- server = (pmserver_t*)db->servers->data;
- snprintf(path, PATH_MAX, "%s://%s%s", server->s_url->scheme,
- server->s_url->host, server->s_url->doc);
- data = strdup(path);
- break;
- default:
- data = NULL;
- }
-
- return(data);
-}
-
/** Set the serverlist of a database.
* @param db database pointer
* @param url url of the server
@@ -307,7 +249,7 @@ int alpm_db_setserver(pmdb_t *db, const char *url)
* @return 0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up
* to date
*/
-int alpm_db_update(int force, PM_DB *db)
+int alpm_db_update(int force, pmdb_t *db)
{
pmlist_t *lp;
char path[PATH_MAX];
@@ -455,112 +397,11 @@ pmlist_t *alpm_db_getgrpcache(pmdb_t *db)
/** @} */
-/** @defgroup alpm_packages Package Functions
+/** \addtogroup alpm_packages Package Functions
* @brief Functions to manipulate libalpm packages
* @{
*/
-/** Get informations about a package.
- * @param pkg package pointer
- * @param parm name of the info to get
- * @return a void* on success (the value), NULL on error
- */
-void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
-{
- void *data = NULL;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- /* Update the cache package entry if needed */
- if(pkg->origin == PKG_FROM_CACHE) {
- switch(parm) {
- /* Desc entry */
- /*case PM_PKG_NAME:
- case PM_PKG_VERSION:*/
- case PM_PKG_DESC:
- case PM_PKG_GROUPS:
- case PM_PKG_URL:
- case PM_PKG_LICENSE:
- case PM_PKG_ARCH:
- case PM_PKG_BUILDDATE:
- case PM_PKG_INSTALLDATE:
- case PM_PKG_PACKAGER:
- case PM_PKG_SIZE:
- case PM_PKG_USIZE:
- case PM_PKG_REASON:
- case PM_PKG_MD5SUM:
- case PM_PKG_SHA1SUM:
- if(!(pkg->infolevel & INFRQ_DESC)) {
- _alpm_log(PM_LOG_DEBUG, _("loading DESC info for '%s'"), pkg->name);
- _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
- }
- break;
- /* Depends entry */
- case PM_PKG_DEPENDS:
- case PM_PKG_REQUIREDBY:
- case PM_PKG_CONFLICTS:
- case PM_PKG_PROVIDES:
- case PM_PKG_REPLACES:
- if(!(pkg->infolevel & INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_DEBUG, "loading DEPENDS info for '%s'", pkg->name);
- _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
- }
- break;
- /* Files entry */
- case PM_PKG_FILES:
- case PM_PKG_BACKUP:
- if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_FILES)) {
- _alpm_log(PM_LOG_DEBUG, _("loading FILES info for '%s'"), pkg->name);
- _alpm_db_read(pkg->data, INFRQ_FILES, pkg);
- }
- break;
- /* Scriptlet */
- case PM_PKG_SCRIPLET:
- if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_SCRIPLET)) {
- _alpm_log(PM_LOG_DEBUG, _("loading SCRIPLET info for '%s'"), pkg->name);
- _alpm_db_read(pkg->data, INFRQ_SCRIPLET, pkg);
- }
- break;
- }
- }
-
- switch(parm) {
- case PM_PKG_NAME: data = pkg->name; break;
- case PM_PKG_VERSION: data = pkg->version; break;
- case PM_PKG_DESC: data = pkg->desc; break;
- case PM_PKG_GROUPS: data = pkg->groups; break;
- case PM_PKG_URL: data = pkg->url; break;
- case PM_PKG_ARCH: data = pkg->arch; break;
- case PM_PKG_BUILDDATE: data = pkg->builddate; break;
- case PM_PKG_BUILDTYPE: data = pkg->buildtype; break;
- case PM_PKG_INSTALLDATE: data = pkg->installdate; break;
- case PM_PKG_PACKAGER: data = pkg->packager; break;
- case PM_PKG_SIZE: data = (void *)(long)pkg->size; break;
- case PM_PKG_USIZE: data = (void *)(long)pkg->usize; break;
- case PM_PKG_REASON: data = (void *)(long)pkg->reason; break;
- case PM_PKG_LICENSE: data = pkg->license; break;
- case PM_PKG_REPLACES: data = pkg->replaces; break;
- case PM_PKG_MD5SUM: data = pkg->md5sum; break;
- case PM_PKG_SHA1SUM: data = pkg->sha1sum; break;
- case PM_PKG_DEPENDS: data = pkg->depends; break;
- case PM_PKG_REMOVES: data = pkg->removes; break;
- case PM_PKG_REQUIREDBY: data = pkg->requiredby; break;
- case PM_PKG_PROVIDES: data = pkg->provides; break;
- case PM_PKG_CONFLICTS: data = pkg->conflicts; break;
- case PM_PKG_FILES: data = pkg->files; break;
- case PM_PKG_BACKUP: data = pkg->backup; break;
- case PM_PKG_SCRIPLET: data = (void *)(long)pkg->scriptlet; break;
- case PM_PKG_DATA: data = pkg->data; break;
- default:
- data = NULL;
- break;
- }
-
- return(data);
-}
-
/** Create a package from a file.
* @param filename location of the package tarball
* @param pkg address of the package pointer
@@ -746,64 +587,11 @@ char *alpm_pkg_name_hasarch(char *pkgname)
/** @} */
-/** @defgroup alpm_groups Group Functions
- * @brief Functions to get informations about libalpm groups
- * @{
- */
-
-/** Get informations about a group.
- * @param grp group pointer
- * @param parm name of the info to get
- * @return a void* on success (the value), NULL on error
- */
-void *alpm_grp_getinfo(pmgrp_t *grp, unsigned char parm)
-{
- void *data = NULL;
-
- /* Sanity checks */
- ASSERT(grp != NULL, return(NULL));
-
- switch(parm) {
- case PM_GRP_NAME: data = grp->name; break;
- case PM_GRP_PKGNAMES: data = grp->packages; break;
- default:
- data = NULL;
- break;
- }
-
- return(data);
-}
-/** @} */
-
-/** @defgroup alpm_sync Sync Functions
+/** \addtogroup alpm_sync Sync Functions
* @brief Functions to get informations about libalpm syncs
* @{
*/
-/** Get informations about a sync.
- * @param sync pointer
- * @param parm name of the info to get
- * @return a void* on success (the value), NULL on error
- */
-void *alpm_sync_getinfo(pmsyncpkg_t *sync, unsigned char parm)
-{
- void *data;
-
- /* Sanity checks */
- ASSERT(sync != NULL, return(NULL));
-
- switch(parm) {
- case PM_SYNC_TYPE: data = (void *)(long)sync->type; break;
- case PM_SYNC_PKG: data = sync->pkg; break;
- case PM_SYNC_DATA: data = sync->data; break;
- default:
- data = NULL;
- break;
- }
-
- return(data);
-}
-
/** Searches a database
* @param db pointer to the package database to search in
* @return the list of packages on success, NULL on error
@@ -820,7 +608,7 @@ pmlist_t *alpm_db_search(pmdb_t *db)
}
/** @} */
-/** @defgroup alpm_trans Transaction Functions
+/** \addtogroup alpm_trans Transaction Functions
* @brief Functions to manipulate libalpm transactions
* @{
*/
@@ -998,7 +786,7 @@ int alpm_trans_release()
}
/** @} */
-/** @defgroup alpm_dep Dependency Functions
+/** \addtogroup alpm_dep Dependency Functions
* @brief Functions to get informations about a libalpm dependency
* @{
*/
@@ -1030,7 +818,7 @@ void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm)
}
/** @} */
-/** @defgroup alpm_conflict File Conflicts Functions
+/** \addtogroup alpm_conflict File Conflicts Functions
* @brief Functions to get informations about a libalpm file conflict
* @{
*/
@@ -1061,7 +849,7 @@ void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm)
}
/** @} */
-/** @defgroup alpm_log Logging Functions
+/** \addtogroup alpm_log Logging Functions
* @brief Functions to log using libalpm
* @{
*/
@@ -1099,7 +887,7 @@ int alpm_logaction(char *fmt, ...)
}
/** @} */
-/** @defgroup alpm_list List Functions
+/** \addtogroup alpm_list List Functions
* @brief Functions to manipulate libalpm linked lists
* @{
*/
@@ -1128,7 +916,7 @@ pmlist_t *alpm_list_next(pmlist_t *entry)
* @param entry the list entry
* @return the data on success, NULL on error
*/
-void *alpm_list_getdata(pmlist_t *entry)
+void *alpm_list_getdata(const pmlist_t *entry)
{
ASSERT(entry != NULL, return(NULL));
@@ -1165,7 +953,7 @@ int alpm_list_free_outer(pmlist_t *entry)
* @param list the list to count
* @return number of entries on success, NULL on error
*/
-int alpm_list_count(pmlist_t *list)
+int alpm_list_count(const pmlist_t *list)
{
ASSERT(list != NULL, return(-1));
@@ -1173,7 +961,7 @@ int alpm_list_count(pmlist_t *list)
}
/** @} */
-/** @defgroup alpm_misc Miscellaneous Functions
+/** \addtogroup alpm_misc Miscellaneous Functions
* @brief Various libalpm functions
* @{
*/
@@ -1225,7 +1013,7 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this
char *key = NULL;
int linenum = 0;
char section[256] = "";
- PM_DB *db = NULL;
+ pmdb_t *db = NULL;
fp = fopen(file, "r");
if(fp == NULL) {
@@ -1282,12 +1070,17 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this
}
if(ptr == NULL) {
if(!strcmp(key, "NOPASSIVEFTP")) {
- alpm_set_option(PM_OPT_NOPASSIVEFTP, (long)1);
+ alpm_option_set_nopassiveftp(1);
+ _alpm_log(PM_LOG_DEBUG, _("config: nopassiveftp"));
} else if(!strcmp(key, "USESYSLOG")) {
- alpm_set_option(PM_OPT_USESYSLOG, (long)1);
+ alpm_option_set_usesyslog(1);
_alpm_log(PM_LOG_DEBUG, _("config: usesyslog"));
} else if(!strcmp(key, "ILOVECANDY")) {
- alpm_set_option(PM_OPT_CHOMP, (long)1);
+ alpm_option_set_chomp(1);
+ _alpm_log(PM_LOG_DEBUG, _("config: chomp"));
+ } else if(!strcmp(key, "USECOLOR")) {
+ alpm_option_set_usecolor(1);
+ _alpm_log(PM_LOG_DEBUG, _("config: usecolor"));
} else {
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
}
@@ -1302,123 +1095,80 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this
if(!strcmp(key, "NOUPGRADE")) {
char *p = ptr;
char *q;
+
while((q = strchr(p, ' '))) {
*q = '\0';
- if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_noupgrade(p);
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
p = q;
p++;
}
- if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_noupgrade(p);
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
} else if(!strcmp(key, "NOEXTRACT")) {
char *p = ptr;
char *q;
+
while((q = strchr(p, ' '))) {
*q = '\0';
- if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_noextract(p);
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
p = q;
p++;
}
- if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_noextract(p);
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
} else if(!strcmp(key, "IGNOREPKG")) {
char *p = ptr;
char *q;
+
while((q = strchr(p, ' '))) {
*q = '\0';
- if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_ignorepkg(p);
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
p = q;
p++;
}
- if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_ignorepkg(p);
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
} else if(!strcmp(key, "HOLDPKG")) {
char *p = ptr;
char *q;
+
while((q = strchr(p, ' '))) {
*q = '\0';
- if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_holdpkg(p);
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
p = q;
p++;
}
- if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_add_holdpkg(p);
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
} else if(!strcmp(key, "DBPATH")) {
/* shave off the leading slash, if there is one */
if(*ptr == '/') {
ptr++;
}
- if(alpm_set_option(PM_OPT_DBPATH, (long)ptr) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_set_dbpath(ptr);
_alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr);
} else if(!strcmp(key, "CACHEDIR")) {
/* shave off the leading slash, if there is one */
if(*ptr == '/') {
ptr++;
}
- if(alpm_set_option(PM_OPT_CACHEDIR, (long)ptr) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_set_cachedir(ptr);
_alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr);
} else if (!strcmp(key, "LOGFILE")) {
- if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
- _alpm_log(PM_LOG_DEBUG, _("config: log file: %s"), ptr);
+ alpm_option_set_logfile(ptr);
+ _alpm_log(PM_LOG_DEBUG, _("config: logfile: %s"), ptr);
} else if (!strcmp(key, "XFERCOMMAND")) {
- if(alpm_set_option(PM_OPT_XFERCOMMAND, (long)ptr) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ alpm_option_set_xfercommand(ptr);
+ _alpm_log(PM_LOG_DEBUG, _("config: xfercommand: %s"), ptr);
} else if (!strcmp(key, "UPGRADEDELAY")) {
/* The config value is in days, we use seconds */
- _alpm_log(PM_LOG_DEBUG, _("config: UpgradeDelay: %i"), (60*60*24) * atol(ptr));
- if(alpm_set_option(PM_OPT_UPGRADEDELAY, (60*60*24) * atol(ptr)) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
- } else if (!strcmp(key, "PROXYSERVER")) {
- if(alpm_set_option(PM_OPT_PROXYHOST, (long)ptr) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
- } else if (!strcmp(key, "PROXYPORT")) {
- if(alpm_set_option(PM_OPT_PROXYPORT, (long)atoi(ptr)) == -1) {
- /* pm_errno is set by alpm_set_option */
- return(-1);
- }
+ long ud = atol(ptr) * 60 * 60 *24;
+ alpm_option_set_upgradedelay(ud);
+ _alpm_log(PM_LOG_DEBUG, _("config: upgradedelay: %d"), ud);
} else {
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
}
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 394001ce..3b5126b1 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -28,6 +28,8 @@
extern "C" {
#endif
+#include <time.h> /* for time_t */
+
/*
* Arch Linux Package Management library
*/
@@ -42,23 +44,25 @@ extern "C" {
#define PM_EXT_DB ".db.tar.gz"
/*
- * Structures (opaque)
+ * Structures
*/
-typedef struct __pmlist_t PM_LIST;
-typedef struct __pmdb_t PM_DB;
-typedef struct __pmpkg_t PM_PKG;
-typedef struct __pmgrp_t PM_GRP;
-typedef struct __pmsyncpkg_t PM_SYNCPKG;
-typedef struct __pmtrans_t PM_TRANS;
-typedef struct __pmdepmissing_t PM_DEPMISS;
-typedef struct __pmconflict_t PM_CONFLICT;
+typedef struct __pmlist_t pmlist_t;
+typedef struct __pmdb_t pmdb_t;
+typedef struct __pmpkg_t pmpkg_t;
+typedef struct __pmgrp_t pmgrp_t;
+typedef struct __pmserver_t pmserver_t;
+typedef struct __pmtrans_t pmtrans_t;
+typedef struct __pmsyncpkg_t pmsyncpkg_t;
+typedef struct __pmdepend_t pmdepend_t;
+typedef struct __pmdepmissing_t pmdepmissing_t;
+typedef struct __pmconflict_t pmconflict_t;
/*
* Library
*/
-int alpm_initialize(char *root);
+int alpm_initialize(const char *root);
int alpm_release(void);
/*
@@ -74,120 +78,110 @@ int alpm_release(void);
#define PM_LOG_FUNCTION 0x20
#define PM_LOG_DOWNLOAD 0x40
+typedef void (*alpm_cb_log)(unsigned short, char *);
int alpm_logaction(char *fmt, ...);
/*
+ * Downloading
+ */
+
+typedef void (*alpm_cb_download)(const char *filename, int xfered, int total);
+
+/*
* Options
*/
#define PM_DLFNM_LEN 22
-/* Parameters */
-enum {
- PM_OPT_LOGCB = 1,
- PM_OPT_LOGMASK,
- PM_OPT_USESYSLOG,
- PM_OPT_ROOT,
- PM_OPT_DBPATH,
- PM_OPT_CACHEDIR,
- PM_OPT_LOGFILE,
- PM_OPT_LOCALDB,
- PM_OPT_SYNCDB,
- PM_OPT_NOUPGRADE,
- PM_OPT_NOEXTRACT,
- PM_OPT_IGNOREPKG,
- PM_OPT_UPGRADEDELAY,
- /* Download */
- PM_OPT_PROXYHOST,
- PM_OPT_PROXYPORT,
- PM_OPT_XFERCOMMAND,
- PM_OPT_NOPASSIVEFTP,
- PM_OPT_DLCB,
- PM_OPT_DLFNM,
- PM_OPT_DLOFFSET,
- PM_OPT_DLT0,
- PM_OPT_DLT,
- PM_OPT_DLRATE,
- PM_OPT_DLXFERED1,
- PM_OPT_DLETA_H,
- PM_OPT_DLETA_M,
- PM_OPT_DLETA_S,
- /* End of download */
- PM_OPT_HOLDPKG,
- PM_OPT_CHOMP,
- PM_OPT_NEEDLES
-};
+alpm_cb_log alpm_option_get_logcb();
+void alpm_option_set_logcb(alpm_cb_log cb);
+
+alpm_cb_download alpm_option_get_dlcb();
+void alpm_option_set_dlcb(alpm_cb_download cb);
+
+unsigned char alpm_option_get_logmask();
+void alpm_option_set_logmask(unsigned char mask);
+
+const char *alpm_option_get_root();
+void alpm_option_set_root(const char *root);
+
+const char *alpm_option_get_dbpath();
+void alpm_option_set_dbpath(const char *dbpath);
+
+const char *alpm_option_get_cachedir();
+void alpm_option_set_cachedir(const char *cachedir);
+
+const char *alpm_option_get_logfile();
+void alpm_option_set_logfile(const char *logfile);
+
+unsigned char alpm_option_get_usesyslog();
+void alpm_option_set_usesyslog(unsigned char usesyslog);
+
+pmlist_t *alpm_option_get_noupgrades();
+void alpm_option_add_noupgrade(char *pkg);
+void alpm_option_set_noupgrades(pmlist_t *noupgrade);
+
+pmlist_t *alpm_option_get_noextracts();
+void alpm_option_add_noextract(char *pkg);
+void alpm_option_set_noextracts(pmlist_t *noextract);
+
+pmlist_t *alpm_option_get_ignorepkgs();
+void alpm_option_add_ignorepkg(char *pkg);
+void alpm_option_set_ignorepkgs(pmlist_t *ignorepkgs);
+
+pmlist_t *alpm_option_get_holdpkgs();
+void alpm_option_add_holdpkg(char *pkg);
+void alpm_option_set_holdpkgs(pmlist_t *holdpkgs);
+
+time_t alpm_option_get_upgradedelay();
+void alpm_option_set_upgradedelay(time_t delay);
+
+const char *alpm_option_get_xfercommand();
+void alpm_option_set_xfercommand(const char *cmd);
+
+unsigned short alpm_option_get_nopassiveftp();
+void alpm_option_set_nopassiveftp(unsigned short nopasv);
-int alpm_set_option(unsigned char parm, unsigned long data);
-int alpm_get_option(unsigned char parm, long *data);
+unsigned short alpm_option_get_chomp();
+void alpm_option_set_chomp(unsigned short chomp);
+
+pmlist_t *alpm_option_get_needles();
+void alpm_option_add_needle(char *needle);
+void alpm_option_set_needles(pmlist_t *needles);
+
+unsigned short alpm_option_get_usecolor();
+void alpm_option_set_usecolor(unsigned short usecolor);
/*
* Databases
*/
-/* Info parameters */
-enum {
- PM_DB_TREENAME = 1,
- PM_DB_FIRSTSERVER
-};
-
/* Database registration callback */
-typedef void (*alpm_cb_db_register)(char *, PM_DB *);
+typedef void (*alpm_cb_db_register)(char *, pmdb_t *);
+
+pmdb_t *alpm_db_register(char *treename);
+int alpm_db_unregister(pmdb_t *db);
-PM_DB *alpm_db_register(char *treename);
-int alpm_db_unregister(PM_DB *db);
+const char *alpm_db_get_name(pmdb_t *db);
+const char *alpm_db_get_url(pmdb_t *db);
-void *alpm_db_getinfo(PM_DB *db, unsigned char parm);
-int alpm_db_setserver(PM_DB *db, const char *url);
+int alpm_db_setserver(pmdb_t *db, const char *url);
-int alpm_db_update(int level, PM_DB *db);
+int alpm_db_update(int level, pmdb_t *db);
-PM_PKG *alpm_db_readpkg(PM_DB *db, char *name);
-PM_LIST *alpm_db_getpkgcache(PM_DB *db);
-PM_LIST *alpm_db_whatprovides(PM_DB *db, char *name);
+pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name);
+pmlist_t *alpm_db_getpkgcache(pmdb_t *db);
+pmlist_t *alpm_db_whatprovides(pmdb_t *db, char *name);
-PM_GRP *alpm_db_readgrp(PM_DB *db, char *name);
-PM_LIST *alpm_db_getgrpcache(PM_DB *db);
-PM_LIST *alpm_db_search(PM_DB *db);
+pmgrp_t *alpm_db_readgrp(pmdb_t *db, char *name);
+pmlist_t *alpm_db_getgrpcache(pmdb_t *db);
+pmlist_t *alpm_db_search(pmdb_t *db);
/*
* Packages
*/
/* Info parameters */
-enum {
- /* Desc entry */
- PM_PKG_NAME = 1,
- PM_PKG_VERSION,
- PM_PKG_DESC,
- PM_PKG_GROUPS,
- PM_PKG_URL,
- PM_PKG_LICENSE,
- PM_PKG_ARCH,
- PM_PKG_BUILDDATE,
- PM_PKG_BUILDTYPE,
- PM_PKG_INSTALLDATE,
- PM_PKG_PACKAGER,
- PM_PKG_SIZE,
- PM_PKG_USIZE,
- PM_PKG_REASON,
- PM_PKG_MD5SUM, /* Sync DB only */
- PM_PKG_SHA1SUM, /* Sync DB only */
- /* Depends entry */
- PM_PKG_DEPENDS,
- PM_PKG_REMOVES,
- PM_PKG_REQUIREDBY,
- PM_PKG_CONFLICTS,
- PM_PKG_PROVIDES,
- PM_PKG_REPLACES, /* Sync DB only */
- /* Files entry */
- PM_PKG_FILES,
- PM_PKG_BACKUP,
- /* Sciplet */
- PM_PKG_SCRIPLET,
- /* Misc */
- PM_PKG_DATA
-};
/* reasons -- ie, why the package was installed */
#define PM_PKG_REASON_EXPLICIT 0 /* explicitly requested by the user */
@@ -197,27 +191,46 @@ enum {
#define PM_PKG_WITHOUT_ARCH 0 /* pkgname-pkgver-pkgrel, used under PM_DBPATH */
#define PM_PKG_WITH_ARCH 1 /* ie, pkgname-pkgver-pkgrel-arch, used under PM_CACHEDIR */
-void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm);
-int alpm_pkg_load(char *filename, PM_PKG **pkg);
-int alpm_pkg_free(PM_PKG *pkg);
-int alpm_pkg_checkmd5sum(PM_PKG *pkg);
-int alpm_pkg_checksha1sum(PM_PKG *pkg);
+int alpm_pkg_load(char *filename, pmpkg_t **pkg);
+int alpm_pkg_free(pmpkg_t *pkg);
+int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
+int alpm_pkg_checksha1sum(pmpkg_t *pkg);
char *alpm_fetch_pkgurl(char *url);
int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section);
int alpm_pkg_vercmp(const char *ver1, const char *ver2);
char *alpm_pkg_name_hasarch(char *pkgname);
+const char *alpm_pkg_get_name(pmpkg_t *pkg);
+const char *alpm_pkg_get_version(pmpkg_t *pkg);
+const char *alpm_pkg_get_desc(pmpkg_t *pkg);
+const char *alpm_pkg_get_url(pmpkg_t *pkg);
+const char *alpm_pkg_get_builddate(pmpkg_t *pkg);
+const char *alpm_pkg_get_buildtype(pmpkg_t *pkg);
+const char *alpm_pkg_get_installdate(pmpkg_t *pkg);
+const char *alpm_pkg_get_packager(pmpkg_t *pkg);
+const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
+const char *alpm_pkg_get_sha1sum(pmpkg_t *pkg);
+const char *alpm_pkg_get_arch(pmpkg_t *pkg);
+unsigned long alpm_pkg_get_size(pmpkg_t *pkg);
+unsigned long alpm_pkg_get_usize(pmpkg_t *pkg);
+unsigned char alpm_pkg_get_reason(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_groups(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_depends(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_removes(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_requiredby(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_conflicts(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_provides(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_files(pmpkg_t *pkg);
+pmlist_t *alpm_pkg_get_backup(pmpkg_t *pkg);
+unsigned char alpm_pkg_has_scriptlet(pmpkg_t *pkg);
+
/*
* Groups
*/
-
-/* Info parameters */
-enum {
- PM_GRP_NAME = 1,
- PM_GRP_PKGNAMES
-};
-
-void *alpm_grp_getinfo(PM_GRP *grp, unsigned char parm);
+const char *alpm_grp_get_name(pmgrp_t *grp);
+pmlist_t *alpm_grp_get_packages(pmgrp_t *grp);
/*
* Sync
@@ -229,14 +242,10 @@ enum {
PM_SYNC_TYPE_UPGRADE,
PM_SYNC_TYPE_DEPEND
};
-/* Info parameters */
-enum {
- PM_SYNC_TYPE = 1,
- PM_SYNC_PKG,
- PM_SYNC_DATA
-};
-void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm);
+unsigned char alpm_sync_get_type(pmsyncpkg_t *sync);
+pmpkg_t *alpm_sync_get_package(pmsyncpkg_t *sync);
+void *alpm_sync_get_data(pmsyncpkg_t *sync);
/*
* Transactions
@@ -334,8 +343,8 @@ void *alpm_trans_getinfo(unsigned char parm);
int alpm_trans_init(unsigned char type, unsigned int flags, alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv, alpm_trans_cb_progress cb_progress);
int alpm_trans_sysupgrade(void);
int alpm_trans_addtarget(char *target);
-int alpm_trans_prepare(PM_LIST **data);
-int alpm_trans_commit(PM_LIST **data);
+int alpm_trans_prepare(pmlist_t **data);
+int alpm_trans_commit(pmlist_t **data);
int alpm_trans_release(void);
/*
@@ -362,7 +371,7 @@ enum {
PM_DEP_VERSION
};
-void *alpm_dep_getinfo(PM_DEPMISS *miss, unsigned char parm);
+void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm);
/*
* File conflicts
@@ -380,19 +389,19 @@ enum {
PM_CONFLICT_CTARGET
};
-void *alpm_conflict_getinfo(PM_CONFLICT *conflict, unsigned char parm);
+void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm);
/*
* Helpers
*/
-/* PM_LIST */
-PM_LIST *alpm_list_first(PM_LIST *list);
-PM_LIST *alpm_list_next(PM_LIST *entry);
-void *alpm_list_getdata(PM_LIST *entry);
-int alpm_list_free(PM_LIST *entry);
-int alpm_list_free_outer(PM_LIST *entry);
-int alpm_list_count(PM_LIST *list);
+/* pmlist_t */
+pmlist_t *alpm_list_first(pmlist_t *list);
+pmlist_t *alpm_list_next(pmlist_t *entry);
+void *alpm_list_getdata(const pmlist_t *entry);
+int alpm_list_free(pmlist_t *entry);
+int alpm_list_free_outer(pmlist_t *entry);
+int alpm_list_count(const pmlist_t *list);
/* md5sums */
char *alpm_get_md5sum(char *name);
@@ -401,7 +410,6 @@ char *alpm_get_sha1sum(char *name);
/*
* Errors
*/
-
extern enum __pmerrno_t {
PM_ERR_MEMORY = 1,
PM_ERR_SYSTEM,
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 8f81235f..33dd78b5 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -43,6 +43,7 @@
#include "alpm.h"
#include "error.h"
#include "handle.h"
+#include "package.h"
/* This function is used to convert the downloaded db file to the proper backend
@@ -199,6 +200,9 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
_alpm_log(PM_LOG_FUNCTION, _("loading package data for %s : level=%d"), info->name, inforeq);
+ /* clear out 'line', to be certain - and to make valgrind happy */
+ memset(line, 513, 0);
+
snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
if(stat(path, &buf)) {
/* directory doesn't exist or can't be opened */
@@ -410,7 +414,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
}
/* INSTALL */
- if(inforeq & INFRQ_SCRIPLET) {
+ if(inforeq & INFRQ_SCRIPTLET) {
snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
if(!stat(path, &buf)) {
info->scriptlet = 1;
diff --git a/lib/libalpm/cache.h b/lib/libalpm/cache.h
index b1187225..5b366bdf 100644
--- a/lib/libalpm/cache.h
+++ b/lib/libalpm/cache.h
@@ -21,10 +21,10 @@
#ifndef _ALPM_CACHE_H
#define _ALPM_CACHE_H
+#include "db.h"
#include "list.h"
-#include "package.h"
#include "group.h"
-#include "db.h"
+#include "package.h"
/* packages */
int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 18a9f06f..57323c30 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -35,6 +35,8 @@
#include <sys/stat.h>
#include <libintl.h>
/* pacman */
+#include "list.h"
+#include "trans.h"
#include "util.h"
#include "error.h"
#include "log.h"
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index a47a585e..7bf8744b 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -22,15 +22,16 @@
#define _ALPM_CONFLICT_H
#include "db.h"
+#include "alpm.h"
#define CONFLICT_FILE_LEN 512
-typedef struct __pmconflict_t {
+struct __pmconflict_t {
char target[PKG_NAME_LEN];
unsigned char type;
char file[CONFLICT_FILE_LEN];
char ctarget[PKG_NAME_LEN];
-} pmconflict_t;
+};
pmlist_t *_alpm_checkconflicts(pmdb_t *db, pmlist_t *packages);
pmlist_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root, pmlist_t **skip_list);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 641a6f3f..c3e071b0 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -223,4 +223,29 @@ pmdb_t *_alpm_db_register(char *treename, alpm_cb_db_register callback)
return(db);
}
+
+const char *alpm_db_get_name(pmdb_t *db)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(db != NULL, return(NULL));
+
+ return db->treename;
+}
+
+const char *alpm_db_get_url(pmdb_t *db)
+{
+ char path[PATH_MAX];
+ pmserver_t *s;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(db != NULL, return(NULL));
+
+ s = (pmserver_t*)db->servers->data;
+
+ snprintf(path, PATH_MAX, "%s://%s%s", s->s_url->scheme, s->s_url->host, s->s_url->doc);
+ return strdup(path);
+}
+
/* vim: set noet: */
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index bffae081..d894c213 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -23,36 +23,31 @@
#ifndef _ALPM_DB_H
#define _ALPM_DB_H
-#include <limits.h>
-#include "package.h"
#include "alpm.h"
+#include <limits.h>
/* Database entries */
-#define INFRQ_NONE 0x00
-#define INFRQ_DESC 0x01
-#define INFRQ_DEPENDS 0x02
-#define INFRQ_FILES 0x04
-#define INFRQ_SCRIPLET 0x08
-#define INFRQ_ALL 0xFF
-
-#define DB_O_CREATE 0x01
+#define INFRQ_NONE 0x00
+#define INFRQ_DESC 0x01
+#define INFRQ_DEPENDS 0x02
+#define INFRQ_FILES 0x04
+#define INFRQ_SCRIPTLET 0x08
+#define INFRQ_ALL 0xFF
/* Database */
-typedef struct __pmdb_t {
+struct __pmdb_t {
char *path;
char treename[PATH_MAX];
void *handle;
pmlist_t *pkgcache;
pmlist_t *grpcache;
pmlist_t *servers;
-} pmdb_t;
+};
pmdb_t *_alpm_db_new(char *root, char *dbpath, char *treename);
void _alpm_db_free(void *data);
int _alpm_db_cmp(const void *db1, const void *db2);
pmlist_t *_alpm_db_search(pmdb_t *db, pmlist_t *needles);
-
-/* Prototypes for backends functions */
int _alpm_db_install(pmdb_t *db, const char *dbfile);
int _alpm_db_open(pmdb_t *db);
void _alpm_db_close(pmdb_t *db);
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index 030020a9..d3269673 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -25,18 +25,21 @@
#include "db.h"
#include "sync.h"
+#include "alpm.h"
-typedef struct __pmdepend_t {
+/* Dependency */
+struct __pmdepend_t {
unsigned char mod;
char name[PKG_NAME_LEN];
char version[PKG_VERSION_LEN];
-} pmdepend_t;
+};
-typedef struct __pmdepmissing_t {
+/* Missing dependency */
+struct __pmdepmissing_t {
char target[PKG_NAME_LEN];
unsigned char type;
pmdepend_t depend;
-} pmdepmissing_t;
+};
pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod,
const char *depname, const char *depversion);
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index a578c777..ecc608d8 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -29,6 +29,7 @@
#include "error.h"
#include "log.h"
#include "group.h"
+#include "list.h"
#include "alpm.h"
pmgrp_t *_alpm_grp_new()
@@ -72,4 +73,19 @@ int _alpm_grp_cmp(const void *g1, const void *g2)
return(strcmp(grp1->name, grp2->name));
}
+const char *alpm_grp_get_name(pmgrp_t *grp)
+{
+ /* Sanity checks */
+ ASSERT(grp != NULL, return(NULL));
+
+ return grp->name;
+}
+
+pmlist_t *alpm_grp_get_packages(pmgrp_t *grp)
+{
+ /* Sanity checks */
+ ASSERT(grp != NULL, return(NULL));
+
+ return grp->packages;
+}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h
index bb3de2a5..86562b10 100644
--- a/lib/libalpm/group.h
+++ b/lib/libalpm/group.h
@@ -21,18 +21,17 @@
#ifndef _ALPM_GROUP_H
#define _ALPM_GROUP_H
-#include "list.h"
-
+/* Groups */
#define GRP_NAME_LEN 256
-/* Groups structure */
-typedef struct __pmgrp_t {
+#include "alpm.h"
+
+struct __pmgrp_t {
char name[GRP_NAME_LEN];
pmlist_t *packages; /* List of strings */
-} pmgrp_t;
+};
#define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0)
-
#define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free)
pmgrp_t *_alpm_grp_new(void);
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index dd9d50b6..ddc8d77d 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -31,7 +31,6 @@
#include <syslog.h>
#include <libintl.h>
#include <time.h>
-/////#include <ftplib.h>
/* pacman */
#include "util.h"
#include "log.h"
@@ -105,7 +104,6 @@ int _alpm_handle_free(pmhandle_t *handle)
FREE(handle->dbpath);
FREE(handle->cachedir);
FREE(handle->logfile);
- FREE(handle->proxyhost);
FREE(handle->xfercommand);
FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade);
@@ -118,242 +116,130 @@ int _alpm_handle_free(pmhandle_t *handle)
return(0);
}
-int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data)
+alpm_cb_log alpm_option_get_logcb() { return handle->logcb; }
+alpm_cb_download alpm_option_get_dlcb() { return handle->dlcb; }
+unsigned char alpm_option_get_logmask() { return handle->logmask; }
+const char *alpm_option_get_root() { return handle->root; }
+const char *alpm_option_get_dbpath() { return handle->dbpath; }
+const char *alpm_option_get_cachedir() { return handle->cachedir; }
+const char *alpm_option_get_logfile() { return handle->logfile; }
+unsigned char alpm_option_get_usesyslog() { return handle->usesyslog; }
+pmlist_t *alpm_option_get_noupgrades() { return handle->noupgrade; }
+pmlist_t *alpm_option_get_noextracts() { return handle->noextract; }
+pmlist_t *alpm_option_get_ignorepkgs() { return handle->ignorepkg; }
+pmlist_t *alpm_option_get_holdpkgs() { return handle->holdpkg; }
+time_t alpm_option_get_upgradedelay() { return handle->upgradedelay; }
+const char *alpm_option_get_xfercommand() { return handle->xfercommand; }
+unsigned short alpm_option_get_nopassiveftp() { return handle->nopassiveftp; }
+unsigned short alpm_option_get_chomp() { return handle->chomp; }
+pmlist_t *alpm_option_get_needles() { return handle->needles; }
+unsigned short alpm_option_get_usecolor() { return handle->use_color; }
+
+pmdb_t *alpm_option_get_localdb(pmhandle_t *handle) { return handle->db_local; }
+pmlist_t *alpm_option_get_syncdbs(pmhandle_t *handle) { return handle->dbs_sync; }
+
+void alpm_option_set_logcb(alpm_cb_log cb) { handle->logcb = cb; }
+
+void alpm_option_set_dlcb(alpm_cb_download cb) { handle->dlcb = cb; }
+
+void alpm_option_set_logmask(unsigned char mask) { handle->logmask = mask; }
+
+void alpm_option_set_root(const char *root)
{
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ if(handle->root) FREE(handle->root);
+ if(root) handle->root = strdup(root);
+}
- char *p;
- switch(val) {
- case PM_OPT_DBPATH:
- if(handle->dbpath) {
- FREE(handle->dbpath);
- }
- handle->dbpath = strdup((data && strlen((char *)data) != 0) ? (char *)data : PM_DBPATH);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_DBPATH set to '%s'"), handle->dbpath);
- break;
- case PM_OPT_CACHEDIR:
- if(handle->cachedir) {
- FREE(handle->cachedir);
- }
- handle->cachedir = strdup((data && strlen((char *)data) != 0) ? (char *)data : PM_CACHEDIR);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_CACHEDIR set to '%s'"), handle->cachedir);
- break;
- case PM_OPT_LOGFILE:
- if((char *)data == NULL || handle->uid != 0) {
- return(0);
- }
- if(handle->logfile) {
- FREE(handle->logfile);
- }
- if(handle->logfd) {
- if(fclose(handle->logfd) != 0) {
- handle->logfd = NULL;
- RET_ERR(PM_ERR_OPT_LOGFILE, -1);
- }
- handle->logfd = NULL;
- }
- if((handle->logfd = fopen((char *)data, "a")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("can't open log file %s"), (char *)data);
- RET_ERR(PM_ERR_OPT_LOGFILE, -1);
- }
- handle->logfile = strdup((char *)data);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_LOGFILE set to '%s'"), (char *)data);
- break;
- case PM_OPT_NOUPGRADE:
- if((char *)data && strlen((char *)data) != 0) {
- handle->noupgrade = _alpm_list_add(handle->noupgrade, strdup((char *)data));
- _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NOUPGRADE"), (char *)data);
- } else {
- FREELIST(handle->noupgrade);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOUPGRADE flushed"));
- }
- break;
- case PM_OPT_NOEXTRACT:
- if((char *)data && strlen((char *)data) != 0) {
- handle->noextract = _alpm_list_add(handle->noextract, strdup((char *)data));
- _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NOEXTRACT"), (char *)data);
- } else {
- FREELIST(handle->noextract);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOEXTRACT flushed"));
- }
- break;
- case PM_OPT_IGNOREPKG:
- if((char *)data && strlen((char *)data) != 0) {
- handle->ignorepkg = _alpm_list_add(handle->ignorepkg, strdup((char *)data));
- _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_IGNOREPKG"), (char *)data);
- } else {
- FREELIST(handle->ignorepkg);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_IGNOREPKG flushed"));
- }
- break;
- case PM_OPT_HOLDPKG:
- if((char *)data && strlen((char *)data) != 0) {
- handle->holdpkg = _alpm_list_add(handle->holdpkg, strdup((char *)data));
- _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_HOLDPKG"), (char *)data);
- } else {
- FREELIST(handle->holdpkg);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_HOLDPKG flushed"));
- }
- break;
- case PM_OPT_NEEDLES:
- if((char *)data && strlen((char *)data) != 0) {
- handle->needles = _alpm_list_add(handle->needles, strdup((char *)data));
- _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NEEDLES"), (char *)data);
- } else {
- FREELIST(handle->needles);
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NEEDLES flushed"));
- }
- break;
- case PM_OPT_USESYSLOG:
- if(data != 0 && data != 1) {
- RET_ERR(PM_ERR_OPT_USESYSLOG, -1);
- }
- if(handle->usesyslog == data) {
- return(0);
- }
- if(handle->usesyslog) {
- closelog();
- } else {
- openlog("alpm", 0, LOG_USER);
- }
- handle->usesyslog = (unsigned short)data;
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_USESYSLOG set to '%d'"), handle->usesyslog);
- break;
- case PM_OPT_LOGCB:
- pm_logcb = (alpm_cb_log)data;
- break;
- case PM_OPT_DLCB:
- pm_dlcb = (download_progress_cb)data;
- break;
-/* case PM_OPT_DLFNM:
- pm_dlfnm = (char *)data;
- break;
- case PM_OPT_DLOFFSET:
- pm_dloffset = (int *)data;
- break;
- case PM_OPT_DLT0:
- pm_dlt0 = (struct timeval *)data;
- break;
- case PM_OPT_DLT:
- pm_dlt = (struct timeval *)data;
- break;
- case PM_OPT_DLRATE:
- pm_dlrate = (float *)data;
- break;
- case PM_OPT_DLXFERED1:
- pm_dlxfered1 = (int *)data;
- break;
- case PM_OPT_DLETA_H:
- pm_dleta_h = (unsigned char *)data;
- break;
- case PM_OPT_DLETA_M:
- pm_dleta_m = (unsigned char *)data;
- break;
- case PM_OPT_DLETA_S:
- pm_dleta_s = (unsigned char *)data;
- break;
-*/
- case PM_OPT_UPGRADEDELAY:
- handle->upgradedelay = data;
- break;
- case PM_OPT_LOGMASK:
- pm_logmask = (unsigned char)data;
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_LOGMASK set to '%02x'"), (unsigned char)data);
- break;
- case PM_OPT_PROXYHOST:
- if(handle->proxyhost) {
- FREE(handle->proxyhost);
- }
- p = strstr((char*)data, "://");
- if(p) {
- p += 3;
- if(p == NULL || *p == '\0') {
- RET_ERR(PM_ERR_SERVER_BAD_LOCATION, -1);
- }
- data = (long)p;
- }
-#if defined(__APPLE__) || defined(__OpenBSD__)
- handle->proxyhost = strdup((char*)data);
-#else
- handle->proxyhost = strndup((char*)data, PATH_MAX);
-#endif
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_PROXYHOST set to '%s'"), handle->proxyhost);
- break;
- case PM_OPT_PROXYPORT:
- handle->proxyport = (unsigned short)data;
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_PROXYPORT set to '%d'"), handle->proxyport);
- break;
- case PM_OPT_XFERCOMMAND:
- if(handle->xfercommand) {
- FREE(handle->xfercommand);
- }
-#if defined(__APPLE__) || defined(__OpenBSD__)
- handle->xfercommand = strdup((char*)data);
-#else
- handle->xfercommand = strndup((char*)data, PATH_MAX);
-#endif
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_XFERCOMMAND set to '%s'"), handle->xfercommand);
- break;
- case PM_OPT_NOPASSIVEFTP:
- handle->nopassiveftp = (unsigned short)data;
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOPASSIVEFTP set to '%d'"), handle->nopassiveftp);
- break;
- case PM_OPT_CHOMP:
- handle->chomp = (unsigned short)data;
- _alpm_log(PM_LOG_FLOW2, _("PM_OPT_CHOMP set to '%d'"), handle->chomp);
- break;
- default:
- RET_ERR(PM_ERR_WRONG_ARGS, -1);
+void alpm_option_set_dbpath(const char *dbpath)
+{
+ if(handle->dbpath) FREE(handle->dbpath);
+ if(dbpath) handle->dbpath = strdup(dbpath);
+}
+
+void alpm_option_set_cachedir(const char *cachedir)
+{
+ if(handle->cachedir) FREE(handle->cachedir);
+ if(cachedir) handle->cachedir = strdup(cachedir);
+}
+
+void alpm_option_set_logfile(const char *logfile)
+{
+ if(handle->logfile) {
+ FREE(handle->logfile);
+ if(handle->logfd) {
+ fclose(handle->logfd);
+ handle->logfd = NULL;
+ }
+ }
+ if(logfile) {
+ handle->logfile = strdup(logfile);
+ handle->logfd = fopen(logfile, "a");
}
+}
- return(0);
+void alpm_option_set_usesyslog(unsigned char usesyslog) { handle->usesyslog = usesyslog; }
+
+void alpm_option_add_noupgrade(char *pkg)
+{
+ handle->noupgrade = _alpm_list_add(handle->noupgrade, strdup(pkg));
+}
+void alpm_option_set_noupgrades(pmlist_t *noupgrade)
+{
+ if(handle->noupgrade) FREELIST(handle->noupgrade);
+ if(noupgrade) handle->noupgrade = noupgrade;
}
-int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data)
+void alpm_option_add_noextract(char *pkg)
{
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ handle->noextract = _alpm_list_add(handle->noextract, strdup(pkg));
+}
+void alpm_option_set_noextracts(pmlist_t *noextract)
+{
+ if(handle->noextract) FREELIST(handle->noextract);
+ if(noextract) handle->noextract = noextract;
+}
- switch(val) {
- case PM_OPT_ROOT: *data = (long)handle->root; break;
- case PM_OPT_DBPATH: *data = (long)handle->dbpath; break;
- case PM_OPT_CACHEDIR: *data = (long)handle->cachedir; break;
- case PM_OPT_LOCALDB: *data = (long)handle->db_local; break;
- case PM_OPT_SYNCDB: *data = (long)handle->dbs_sync; break;
- case PM_OPT_LOGFILE: *data = (long)handle->logfile; break;
- case PM_OPT_NOUPGRADE: *data = (long)handle->noupgrade; break;
- case PM_OPT_NOEXTRACT: *data = (long)handle->noextract; break;
- case PM_OPT_IGNOREPKG: *data = (long)handle->ignorepkg; break;
- case PM_OPT_HOLDPKG: *data = (long)handle->holdpkg; break;
- case PM_OPT_NEEDLES: *data = (long)handle->needles; break;
- case PM_OPT_USESYSLOG: *data = handle->usesyslog; break;
- case PM_OPT_LOGCB: *data = (long)pm_logcb; break;
- case PM_OPT_DLCB: *data = (long)pm_dlcb; break;
- case PM_OPT_UPGRADEDELAY: *data = (long)handle->upgradedelay; break;
- case PM_OPT_LOGMASK: *data = pm_logmask; break;
-/*
- case PM_OPT_DLFNM: *data = (long)pm_dlfnm; break;
- case PM_OPT_DLOFFSET: *data = (long)pm_dloffset; break;
- case PM_OPT_DLT0: *data = (long)pm_dlt0; break;
- case PM_OPT_DLT: *data = (long)pm_dlt; break;
- case PM_OPT_DLRATE: *data = (long)pm_dlrate; break;
- case PM_OPT_DLXFERED1: *data = (long)pm_dlxfered1; break;
- case PM_OPT_DLETA_H: *data = (long)pm_dleta_h; break;
- case PM_OPT_DLETA_M: *data = (long)pm_dleta_m; break;
- case PM_OPT_DLETA_S: *data = (long)pm_dleta_s; break;
-*/
- case PM_OPT_PROXYHOST: *data = (long)handle->proxyhost; break;
- case PM_OPT_PROXYPORT: *data = handle->proxyport; break;
- case PM_OPT_XFERCOMMAND: *data = (long)handle->xfercommand; break;
- case PM_OPT_NOPASSIVEFTP: *data = handle->nopassiveftp; break;
- case PM_OPT_CHOMP: *data = handle->chomp; break;
- default:
- RET_ERR(PM_ERR_WRONG_ARGS, -1);
- break;
- }
+void alpm_option_add_ignorepkg(char *pkg)
+{
+ handle->ignorepkg = _alpm_list_add(handle->ignorepkg, strdup(pkg));
+}
+void alpm_option_set_ignorepkgs(pmlist_t *ignorepkgs)
+{
+ if(handle->ignorepkg) FREELIST(handle->ignorepkg);
+ if(ignorepkgs) handle->ignorepkg = ignorepkgs;
+}
- return(0);
+void alpm_option_add_holdpkg(char *pkg)
+{
+ handle->holdpkg = _alpm_list_add(handle->holdpkg, strdup(pkg));
+}
+void alpm_option_set_holdpkgs(pmlist_t *holdpkgs)
+{
+ if(handle->holdpkg) FREELIST(handle->holdpkg);
+ if(holdpkgs) handle->holdpkg = holdpkgs;
+}
+
+void alpm_option_set_upgradedelay(time_t delay) { handle->upgradedelay = delay; }
+
+void alpm_option_set_xfercommand(const char *cmd)
+{
+ if(handle->xfercommand) FREE(handle->xfercommand);
+ if(cmd) handle->xfercommand = strdup(cmd);
+}
+
+void alpm_option_set_nopassiveftp(unsigned short nopasv) { handle->nopassiveftp = nopasv; }
+
+void alpm_option_set_chomp(unsigned short chomp) { handle->chomp = chomp; }
+
+void alpm_option_add_needle(char *needle)
+{
+ handle->needles = _alpm_list_add(handle->needles, strdup(needle));
+}
+void alpm_option_set_needles(pmlist_t *needles)
+{
+ if(handle->needles) FREELIST(handle->needles);
+ if(needles) handle->needles = needles;
}
+void alpm_option_set_usecolor(unsigned short usecolor) { handle->use_color = usecolor; }
-/* vim: set ts=2 sw=2 noet: */
+/* vim: set ts=2 sw=2 et: */
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 9311f724..41e8a5fe 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -21,17 +21,19 @@
#ifndef _ALPM_HANDLE_H
#define _ALPM_HANDLE_H
-#include "list.h"
#include "db.h"
-#include "trans.h"
+#include "log.h"
+#include "list.h"
#include "alpm.h"
+#include "trans.h"
-typedef enum __pmaccess_t {
+typedef enum _pmaccess_t {
PM_ACCESS_RO,
PM_ACCESS_RW
} pmaccess_t;
-typedef struct __pmhandle_t {
+typedef struct _pmhandle_t {
+ /* Internal */
pmaccess_t access;
uid_t uid;
pmdb_t *db_local;
@@ -39,24 +41,29 @@ typedef struct __pmhandle_t {
FILE *logfd;
int lckfd;
pmtrans_t *trans;
- /* parameters */
- char *root;
- char *dbpath;
- char *cachedir;
- char *logfile;
- pmlist_t *noupgrade; /* List of strings */
- pmlist_t *noextract; /* List of strings */
- pmlist_t *ignorepkg; /* List of strings */
- pmlist_t *holdpkg; /* List of strings */
- unsigned char usesyslog;
- time_t upgradedelay;
+
+ /* options */
+ alpm_cb_log logcb; /* Log callback function */
+ alpm_cb_download dlcb; /* Download callback function */
+ unsigned char logmask; /* Output mask for logging functions */
+ char *root; /* Root path, default '/' */
+ char *dbpath; /* Base path to pacman's DBs */
+ char *cachedir; /* Base path to pacman's cache */
+ char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
+ unsigned char usesyslog; /* Use syslog instead of logfile? */
+
+ pmlist_t *noupgrade; /* List of packages NOT to be upgraded */
+ pmlist_t *noextract; /* List of packages NOT to extrace */ /*TODO is this used?*/
+ pmlist_t *ignorepkg; /* List of packages to ignore */
+ pmlist_t *holdpkg; /* List of packages which 'hold' pacman */
+
+ time_t upgradedelay; /* Amount of time to wait before upgrading a package*/
/* servers */
- char *proxyhost;
- unsigned short proxyport;
- char *xfercommand;
- unsigned short nopassiveftp;
- unsigned short chomp; /* if eye-candy features should be enabled or not */
- pmlist_t *needles; /* for searching */
+ char *xfercommand; /* External download command */
+ unsigned short nopassiveftp; /* Don't use PASV ftp connections */
+ unsigned short chomp; /* I Love Candy! */
+ pmlist_t *needles; /* needles for searching */ /* TODO why is this here? */
+ unsigned short use_color; /* enable colorful output */
} pmhandle_t;
extern pmhandle_t *handle;
@@ -65,8 +72,6 @@ extern pmhandle_t *handle;
pmhandle_t *_alpm_handle_new(void);
int _alpm_handle_free(pmhandle_t *handle);
-int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data);
-int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data);
#endif /* _ALPM_HANDLE_H */
diff --git a/lib/libalpm/list.c b/lib/libalpm/list.c
index 0f48030b..47c31990 100644
--- a/lib/libalpm/list.c
+++ b/lib/libalpm/list.c
@@ -187,10 +187,10 @@ pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, v
return(haystack);
}
-int _alpm_list_count(pmlist_t *list)
+int _alpm_list_count(const pmlist_t *list)
{
int i;
- pmlist_t *lp;
+ const pmlist_t *lp;
for(lp = list, i = 0; lp; lp = lp->next, i++);
diff --git a/lib/libalpm/list.h b/lib/libalpm/list.h
index abff7819..3fdc01ad 100644
--- a/lib/libalpm/list.h
+++ b/lib/libalpm/list.h
@@ -21,13 +21,15 @@
#ifndef _ALPM_LIST_H
#define _ALPM_LIST_H
+#include "alpm.h"
+
/* Chained list struct */
-typedef struct __pmlist_t {
+struct __pmlist_t {
void *data;
struct __pmlist_t *prev;
struct __pmlist_t *next;
struct __pmlist_t *last; /* Quick access to last item in list */
-} pmlist_t;
+};
#define _FREELIST(p, f) do { if(p) { _alpm_list_free(p, f); p = NULL; } } while(0)
#define FREELIST(p) _FREELIST(p, free)
@@ -42,7 +44,7 @@ void _alpm_list_free(pmlist_t *list, _alpm_fn_free fn);
pmlist_t *_alpm_list_add(pmlist_t *list, void *data);
pmlist_t *_alpm_list_add_sorted(pmlist_t *list, void *data, _alpm_fn_cmp fn);
pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, void **data);
-int _alpm_list_count(pmlist_t *list);
+int _alpm_list_count(const pmlist_t *list);
int _alpm_list_is_in(void *needle, pmlist_t *haystack);
int _alpm_list_is_strin(char *needle, pmlist_t *haystack);
pmlist_t *_alpm_list_last(pmlist_t *list);
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index f0dd2b18..2b543ae6 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -27,17 +27,14 @@
#include "alpm.h"
#include "log.h"
-/* Internal library log mechanism */
-alpm_cb_log pm_logcb = NULL;
-unsigned char pm_logmask = 0;
-
void _alpm_log(unsigned char flag, char *fmt, ...)
{
- if(pm_logcb == NULL) {
+ alpm_cb_log logcb = alpm_option_get_logcb();
+ if(logcb == NULL) {
return;
}
- if(flag & pm_logmask) {
+ if(flag & alpm_option_get_logmask()) {
char str[LOG_STR_LEN];
va_list args;
@@ -45,7 +42,7 @@ void _alpm_log(unsigned char flag, char *fmt, ...)
vsnprintf(str, LOG_STR_LEN, fmt, args);
va_end(args);
- pm_logcb(flag, str);
+ logcb(flag, str);
}
}
diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h
index da1d9966..ab35e72b 100644
--- a/lib/libalpm/log.h
+++ b/lib/libalpm/log.h
@@ -21,12 +21,7 @@
#ifndef _ALPM_LOG_H
#define _ALPM_LOG_H
-#define LOG_STR_LEN 256
-
-typedef void (*alpm_cb_log)(unsigned short, char *);
-
-extern alpm_cb_log pm_logcb;
-extern unsigned char pm_logmask;
+#define LOG_STR_LEN 1024
void _alpm_log(unsigned char flag, char *fmt, ...);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 1302ebe5..31867551 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -36,6 +36,8 @@
#include "error.h"
#include "list.h"
#include "package.h"
+#include "db.h"
+#include "handle.h"
#include "alpm.h"
pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
@@ -241,11 +243,11 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output)
} else if(!strcmp(key, "SIZE")) {
char tmp[32];
STRNCPY(tmp, ptr, sizeof(tmp));
- info->size = atol(tmp);
+ info->size = atol(ptr);
} else if(!strcmp(key, "USIZE")) {
char tmp[32];
STRNCPY(tmp, ptr, sizeof(tmp));
- info->usize = atol(tmp);
+ info->usize = atol(ptr);
} else if(!strcmp(key, "DEPEND")) {
info->depends = _alpm_list_add(info->depends, strdup(ptr));
} else if(!strcmp(key, "REMOVE")) {
@@ -509,4 +511,302 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
return(0);
}
+const char *alpm_pkg_get_name(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ return pkg->name;
+}
+
+const char *alpm_pkg_get_version(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ return pkg->version;
+}
+
+const char *alpm_pkg_get_desc(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->desc;
+}
+
+const char *alpm_pkg_get_url(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->url;
+}
+
+const char *alpm_pkg_get_builddate(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->builddate;
+}
+
+const char *alpm_pkg_get_buildtype(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->buildtype;
+}
+
+const char *alpm_pkg_get_installdate(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->installdate;
+}
+
+const char *alpm_pkg_get_packager(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->packager;
+}
+
+const char *alpm_pkg_get_md5sum(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->md5sum;
+}
+
+const char *alpm_pkg_get_sha1sum(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->sha1sum;
+}
+
+const char *alpm_pkg_get_arch(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->arch;
+}
+
+unsigned long alpm_pkg_get_size(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->size;
+}
+
+unsigned long alpm_pkg_get_usize(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->usize;
+}
+
+unsigned char alpm_pkg_get_reason(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->reason;
+}
+
+pmlist_t *alpm_pkg_get_licenses(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->license;
+}
+
+pmlist_t *alpm_pkg_get_groups(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
+ }
+ return pkg->groups;
+}
+
+/* depends */
+pmlist_t *alpm_pkg_get_depends(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->depends;
+}
+
+pmlist_t *alpm_pkg_get_removes(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->removes;
+}
+
+pmlist_t *alpm_pkg_get_requiredby(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->requiredby;
+}
+
+pmlist_t *alpm_pkg_get_conflicts(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->conflicts;
+}
+
+pmlist_t *alpm_pkg_get_provides(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->provides;
+}
+
+pmlist_t *alpm_pkg_get_replaces(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
+ }
+ return pkg->replaces;
+}
+
+pmlist_t *alpm_pkg_get_files(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local
+ && !(pkg->infolevel & INFRQ_FILES)) {
+ _alpm_db_read(pkg->data, INFRQ_FILES, pkg);
+ }
+ return pkg->files;
+}
+
+pmlist_t *alpm_pkg_get_backup(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(pkg != NULL, return(NULL));
+
+ if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local
+ && !(pkg->infolevel & INFRQ_FILES)) {
+ _alpm_db_read(pkg->data, INFRQ_FILES, pkg);
+ }
+ return pkg->backup;
+}
+
+unsigned char alpm_pkg_has_scriptlet(pmpkg_t *pkg)
+{
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local
+ && !(pkg->infolevel & INFRQ_SCRIPTLET)) {
+ _alpm_db_read(pkg->data, INFRQ_SCRIPTLET, pkg);
+ }
+ return pkg->scriptlet;
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index d96f8d41..1b834cb8 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -28,13 +28,15 @@
#if defined(__APPLE__) || defined(__sun__)
#include <time.h>
#endif
-#include "list.h"
+
+#include "alpm.h"
enum {
PKG_FROM_CACHE = 1,
PKG_FROM_FILE
};
+/* Packages */
#define PKG_NAME_LEN 256
#define PKG_VERSION_LEN 64
#define PKG_FULLNAME_LEN (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1
@@ -47,7 +49,7 @@ enum {
#define PKG_SHA1SUM_LEN 41
#define PKG_ARCH_LEN 32
-typedef struct __pmpkg_t {
+struct __pmpkg_t {
char name[PKG_NAME_LEN];
char version[PKG_VERSION_LEN];
char desc[PKG_DESC_LEN];
@@ -80,16 +82,9 @@ typedef struct __pmpkg_t {
unsigned char origin;
void *data;
unsigned char infolevel;
-} pmpkg_t;
-
-#define FREEPKG(p) \
-do { \
- if(p) { \
- _alpm_pkg_free(p); \
- p = NULL; \
- } \
-} while(0)
+};
+#define FREEPKG(p) do { if(p){_alpm_pkg_free(p); p = NULL;}} while(0)
#define FREELISTPKGS(p) _FREELIST(p, _alpm_pkg_free)
pmpkg_t* _alpm_pkg_new(const char *name, const char *version);
@@ -101,6 +96,7 @@ pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack);
char *_alpm_pkg_makefilename(pmpkg_t *pkg);
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
+
#endif /* _ALPM_PACKAGE_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/provide.h b/lib/libalpm/provide.h
index 7b132200..eb587003 100644
--- a/lib/libalpm/provide.h
+++ b/lib/libalpm/provide.h
@@ -21,10 +21,9 @@
#ifndef _ALPM_PROVIDE_H
#define _ALPM_PROVIDE_H
-#include "config.h"
-
-#include "list.h"
#include "db.h"
+#include "list.h"
+#include "config.h"
pmlist_t *_alpm_db_whatprovides(pmdb_t *db, char *package);
diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h
index ac6ff1bf..524e5faa 100644
--- a/lib/libalpm/remove.h
+++ b/lib/libalpm/remove.h
@@ -21,8 +21,8 @@
#ifndef _ALPM_REMOVE_H
#define _ALPM_REMOVE_H
-#include "list.h"
#include "db.h"
+#include "list.h"
#include "trans.h"
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index 4c0b5e79..90466e32 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -38,8 +38,6 @@
#include "handle.h"
#include "log.h"
-download_progress_cb pm_dlcb = NULL;
-
pmserver_t *_alpm_server_new(const char *url)
{
struct url *u;
@@ -172,10 +170,10 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
downloadTimeout = 10000;
/* Make libdownload super verbose... worthwhile for testing */
- if(pm_logmask & PM_LOG_DOWNLOAD) {
+ if(alpm_option_get_logmask() & PM_LOG_DOWNLOAD) {
downloadDebug = 1;
}
- if(pm_logmask & PM_LOG_DEBUG) {
+ if(alpm_option_get_logmask() & PM_LOG_DEBUG) {
dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp"));
} else {
dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p"));
@@ -229,7 +227,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
}
/* Progress 0 - initialize */
- if(pm_dlcb) pm_dlcb(fn, 0, ust.size);
+ if(handle->dlcb) handle->dlcb(fn, 0, ust.size);
int nread = 0;
char buffer[PM_DLBUF_LEN];
@@ -238,7 +236,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
while((nwritten += fwrite(buffer, 1, (nread - nwritten), localf)) < nread) ;
dltotal_bytes += nread;
- if(pm_dlcb) pm_dlcb(fn, dltotal_bytes, ust.size);
+ if(handle->dlcb) handle->dlcb(fn, dltotal_bytes, ust.size);
}
fclose(localf);
diff --git a/lib/libalpm/server.h b/lib/libalpm/server.h
index 5ce848cc..80e9a7e1 100644
--- a/lib/libalpm/server.h
+++ b/lib/libalpm/server.h
@@ -22,30 +22,22 @@
#define _ALPM_SERVER_H
#include "list.h"
-#include <time.h>
+#include "alpm.h"
+#include <time.h>
#include <download.h>
-#define FREESERVER(p) \
-do { \
- if(p) { \
- _alpm_server_free(p); \
- p = NULL; \
- } \
-} while(0)
-
+#define FREESERVER(p) do { if(p){_alpm_server_free(p); p = NULL;}} while(0)
#define FREELISTSERVERS(p) _FREELIST(p, _alpm_server_free)
/* Servers */
-typedef struct __pmserver_t {
+struct __pmserver_t {
char *path;
struct url *s_url;
-} pmserver_t;
+};
#define PM_DLBUF_LEN (1024 * 10)
-typedef void (*download_progress_cb)(const char *filename, int xfered, int total);
-
pmserver_t *_alpm_server_new(const char *url);
void _alpm_server_free(void *data);
int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *files);
@@ -54,8 +46,6 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
char *_alpm_fetch_pkgurl(char *target);
-extern download_progress_cb pm_dlcb;
-
#endif /* _ALPM_SERVER_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 9fd1884f..acc48362 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -790,7 +790,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
fname = _alpm_pkg_makefilename(spkg);
if(trans->flags & PM_TRANS_FLAG_PRINTURIS) {
- EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), fname);
+ EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current), fname);
} else {
struct stat buf;
snprintf(path, PATH_MAX, "%s/%s", ldir, fname);
@@ -818,11 +818,8 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
*/
_alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
alpm_logaction(_("warning: couldn't create package cache, using /tmp instead"));
- snprintf(ldir, PATH_MAX, "%s/tmp", handle->root);
- if(_alpm_handle_set_option(handle, PM_OPT_CACHEDIR, (long)"/tmp") == -1) {
- _alpm_log(PM_LOG_WARNING, _("failed to set option CACHEDIR (%s)\n"), alpm_strerror(pm_errno));
- RET_ERR(PM_ERR_RETRIEVE, -1);
- }
+ snprintf(ldir, PATH_MAX, "%stmp", alpm_option_get_root());
+ alpm_option_set_cachedir(ldir);
varcache = 0;
}
}
@@ -1054,4 +1051,28 @@ error:
return(-1);
}
+unsigned char alpm_sync_get_type(pmsyncpkg_t *sync)
+{
+ /* Sanity checks */
+ ASSERT(sync != NULL, return(-1));
+
+ return sync->type;
+}
+
+pmpkg_t *alpm_sync_get_package(pmsyncpkg_t *sync)
+{
+ /* Sanity checks */
+ ASSERT(sync != NULL, return(NULL));
+
+ return sync->pkg;
+}
+
+void *alpm_sync_get_data(pmsyncpkg_t *sync)
+{
+ /* Sanity checks */
+ ASSERT(sync != NULL, return(NULL));
+
+ return sync->data;
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index d23dc6d8..f3d5ec02 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -23,15 +23,14 @@
#ifndef _ALPM_SYNC_H
#define _ALPM_SYNC_H
-#include "db.h"
-#include "package.h"
-#include "trans.h"
+#include "alpm.h"
-typedef struct __pmsyncpkg_t {
+/* Sync package */
+struct __pmsyncpkg_t {
unsigned char type;
pmpkg_t *pkg;
void *data;
-} pmsyncpkg_t;
+};
#define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0)
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 95e672b6..49bcceb3 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -24,19 +24,10 @@
#ifndef _ALPM_TRANS_H
#define _ALPM_TRANS_H
-enum {
- STATE_IDLE = 0,
- STATE_INITIALIZED,
- STATE_PREPARED,
- STATE_DOWNLOADING,
- STATE_COMMITING,
- STATE_COMMITED,
- STATE_INTERRUPTED
-};
-
#include "alpm.h"
-typedef struct __pmtrans_t {
+/* Transaction */
+struct __pmtrans_t {
unsigned char type;
unsigned int flags;
unsigned char state;
@@ -46,7 +37,17 @@ typedef struct __pmtrans_t {
alpm_trans_cb_event cb_event;
alpm_trans_cb_conv cb_conv;
alpm_trans_cb_progress cb_progress;
-} pmtrans_t;
+};
+
+enum {
+ STATE_IDLE = 0,
+ STATE_INITIALIZED,
+ STATE_PREPARED,
+ STATE_DOWNLOADING,
+ STATE_COMMITING,
+ STATE_COMMITED,
+ STATE_INTERRUPTED
+};
#define FREETRANS(p) \
do { \
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f1f74202..cca43117 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -63,6 +63,7 @@
#include "sync.h"
#include "util.h"
#include "error.h"
+#include "package.h"
#include "alpm.h"
#ifdef __sun__
diff --git a/scripts/repo-add b/scripts/repo-add
new file mode 100755
index 00000000..4079ef05
--- /dev/null
+++ b/scripts/repo-add
@@ -0,0 +1,237 @@
+#!/bin/bash
+# repo-add : add a package to a given repo database file
+#
+# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+
+FORCE=0
+REPO_DB_FILE=""
+
+DB_COMPRESSION="gz" #TODO this is gross
+DB_CHECKSUMS=(md5)
+TMP_DIR=""
+
+if [ $# -lt 2 ]; then
+ echo "repo-add /path/to/repo.db.tar.gz [--force] [packages-to-add]"
+ exit 1
+fi
+
+
+get_checksum () {
+ case "$(echo "$1" | tr A-Z a-z)" in
+ md5) sum=$(md5sum $2); echo ${sum% *} ;;
+ sha1) sum=$(sha1sum $2); echo ${sum% *} ;;
+ sha256) sum=$(sha256sum $2); echo ${sum% *} ;;
+ sha384) sum=$(sha256sum $2); echo ${sum% *} ;;
+ sha512) sum=$(sha256sum $2); echo ${sum% *} ;;
+ esac
+}
+
+checksum_name () {
+ case "$(echo "$1" | tr A-Z a-z)" in
+ md5) echo "MD5SUM" ;;
+ sha1) echo "SHA1SUM" ;;
+ sha256) echo "SHA256SUM" ;;
+ sha384) echo "SHA384SUM" ;;
+ sha512) echo "SHA512SUM" ;;
+ esac
+}
+
+test_repo_db_file () {
+ if [ -f "$REPO_DB_FILE" ]; then
+ [ "$(tar tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1
+ else
+ true
+ fi
+}
+
+db_write_entry()
+{
+ pkgfile=$(readlink -f $1)
+ export pkgname=""
+ pkgver=""
+ pkgdesc=""
+ url=""
+ builddate=""
+ packager=""
+ csize=""
+ size=""
+ groups=""
+ depends=""
+ backups=""
+ licenses=""
+ _replaces=""
+ _provides=""
+ _conflicts=""
+
+ OLDIFS="$IFS"
+ #gross... IFS == new line
+ IFS='
+'
+ for i in $(tar xOf "$pkgfile" .PKGINFO | grep -v "^#" |sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
+ eval "${i}"
+ case "$i" in
+ group=*) groups="$groups $group" ;;
+ depend=*) depends="$depends $depend" ;;
+ backup=*) backups="$backups $backup" ;;
+ license=*) licenses="$licenses $license" ;;
+ replaces=*) _replaces="$_replaces $replaces" ;;
+ provides=*) _provides="$_provides $provides" ;;
+ conflicts=*) _conflicts="$_conflicts $conflicts" ;;
+ esac
+ done
+ IFS=$OLDIFS
+
+ csize="$(du -b $pkgfile | cut -f1)"
+
+ cd $gstmpdir
+
+ if [ -z "$pkgname" -o -z "$pkgver" ]; then
+ echo " error: invalid package file"
+ return 1
+ fi
+
+ if [ ! -d "$pkgname-$pkgver" ]; then
+ [ -e "$pkgname-$pkgver" ] && rm -rf "$pkgname-$pkgver"
+ mkdir "$pkgname-$pkgver"
+ cd "$pkgname-$pkgver"
+ else
+ cd "$pkgname-$pkgver"
+ [ -e desc ] && rm desc
+ [ -e depends ] && rm depends
+ fi
+
+ # desc
+ echo ":: creating 'desc' db entry"
+ echo -e "%FILENAME%\n$1\n" >> desc
+ echo -e "%NAME%\n$pkgname\n" >>desc
+ echo -e "%VERSION%\n$pkgver\n" >>desc
+ if [ -n "$pkgdesc" ]; then
+ echo -e "%DESC%\n$pkgdesc\n" >>desc
+ fi
+ if [ -n "$groups" ]; then
+ echo "%GROUPS%" >>desc
+ echo $groups | tr -s ' ' '\n' >>desc
+ echo "" >desc
+ fi
+ [ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc
+ #TODO SIZE ? USIZE ?
+ [ -n $size ] && echo -e "%USIZE%\n$size\n" >>desc
+
+ for chk in ${DB_CHECKSUMS[@]}; do
+ name="$(checksum_name $chk)"
+ echo ":: computing $name checksums"
+ if [ -n "$name" ]; then
+ echo -e "%$name%\n$(get_checksum $chk $pkgfile)\n" >>desc
+ fi
+ done
+
+ [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
+ if [ -n "$licenses" ]; then
+ echo "%LICENSE%" >>desc
+ echo $licenses | tr -s ' ' '\n' >>desc
+ echo "" >>desc
+ fi
+ [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc
+ [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc
+ [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc
+
+ if [ -n "$_replaces" ]; then
+ echo "%REPLACES%" >>desc
+ echo $_replaces | tr -s ' ' '\n' >>desc
+ echo "" >>desc
+ fi
+ [ "$FORCE" = "1" ] && echo -e "%FORCE%\n" >>desc
+
+ # depends
+ echo ":: creating 'depends' db entry"
+ if [ -n "$depends" ]; then
+ echo "%DEPENDS%" >>depends
+ echo $depends | tr -s ' ' '\n' >>depends
+ echo "" >>depends
+ fi
+ if [ -n "$_conflicts" ]; then
+ echo "%CONFLICTS%" >>depends
+ echo $_conflicts | tr -s ' ' '\n' >>depends
+ echo "" >>depends
+ fi
+ if [ -n "$_provides" ]; then
+ echo "%PROVIDES%" >>depends
+ echo $_provides | tr -s ' ' '\n' >>depends
+ echo "" >>depends
+ fi
+
+ # preserve the modification time
+ touch -r "$pkgfile" desc depends
+}
+
+if [ $# -gt 1 ]; then
+ gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\
+ echo "cannot create temp directory for database building"; \
+ exit 1)
+
+ success=0
+ for arg in $@; do
+ if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
+ FORCE=1
+ elif [ "x$REPO_DB_FILE" == "x" ]; then
+ REPO_DB_FILE="$(readlink -f $arg)"
+ if ! test_repo_db_file; then
+ echo " repository db file '$REPO_DB_FILE' is not a proper pacman db"
+ exit 1
+ elif [ -f "$REPO_DB_FILE" ]; then
+ echo ":: extracting database to a temporary location"
+ tar xf "$REPO_DB_FILE" -C "$gstmpdir"
+ fi
+ else
+ if [ -f "$arg" ]; then
+ if ! tar xf "$arg" .PKGINFO 2>&1 >/dev/null; then
+ echo "error: '$arg' is not a package file, skipping"
+ else
+ echo ":: adding package '$arg'"
+
+ this_dir="$(pwd)"
+ if db_write_entry "$arg"; then
+ success=1
+ fi
+ cd $this_dir
+ fi
+ else
+ echo "error: package '$arg' not found"
+ fi
+ fi
+ done
+
+ if [ "$success" = "1" ]; then
+ echo ":: creating updated database file ${REPO_DB_FILE}"
+ cd $gstmpdir
+ if [ -n "$(ls)" ]; then
+ [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old"
+ [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ case "$DB_COMPRESSION" in
+ gz) tar c * | gzip -9 >$REPO_DB_FILE ;;
+ bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;;
+ *) echo "warning: no compression set"
+ tar c * >$REPO_DB_FILE;;
+ esac
+ fi
+ else
+ echo ":: no packages modified, nothing to do"
+ fi
+fi
+
+[ -d "$gstmpdir" ] && rm -rf $gstmpdir
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index 956cdecb..216633a6 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -5,8 +5,7 @@ SUBDIRS = po
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
-AM_CFLAGS = $(CFLAGS) -D_GNU_SOURCE \
- -I$(top_srcdir)/lib/libalpm
+AM_CFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/lib/libalpm $(CFLAGS)
pacman_SOURCES = util.c log.c list.c package.c downloadprog.c trans.c add.c \
remove.c upgrade.c query.c sync.c conf.c deptest.c pacman.c
diff --git a/src/pacman/add.c b/src/pacman/add.c
index 600bc625..9b5a650f 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -38,7 +38,7 @@ extern config_t *config;
int pacman_add(list_t *targets)
{
- PM_LIST *data;
+ pmlist_t *data;
list_t *i;
int retval = 0;
@@ -87,13 +87,13 @@ int pacman_add(list_t *targets)
*/
if(alpm_trans_prepare(&data) == -1) {
long long *pkgsize, *freespace;
- PM_LIST *i;
+ pmlist_t *i;
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) {
- PM_DEPMISS *miss = alpm_list_getdata(i);
+ pmdepmissing_t *miss = alpm_list_getdata(i);
MSG(NL, _(":: %s: requires %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
@@ -107,7 +107,7 @@ int pacman_add(list_t *targets)
break;
case PM_ERR_CONFLICTING_DEPS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) {
- PM_DEPMISS *miss = alpm_list_getdata(i);
+ pmdepmissing_t *miss = alpm_list_getdata(i);
MSG(NL, _(":: %s: conflicts with %s"),
alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME));
}
@@ -115,7 +115,7 @@ int pacman_add(list_t *targets)
break;
case PM_ERR_FILE_CONFLICTS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) {
- PM_CONFLICT *conflict = alpm_list_getdata(i);
+ pmconflict_t *conflict = alpm_list_getdata(i);
switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
case PM_CONFLICT_TYPE_TARGET:
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 72c55f35..ef380580 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -53,7 +53,6 @@ int config_free(config_t *config)
return(-1);
}
- FREE(config->root);
FREE(config->configfile);
FREELIST(config->op_s_ignore);
free(config);
@@ -61,7 +60,7 @@ int config_free(config_t *config)
return(0);
}
-void cb_db_register(char *section, PM_DB *db)
+void cb_db_register(char *section, pmdb_t *db)
{
sync_t *sync;
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index f7b5d2fb..79f9c0ec 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -23,9 +23,9 @@
typedef struct __config_t {
/* command line options */
- char *root;
- char *dbpath;
- char *cachedir;
+ const char *root;
+ const char *dbpath;
+ const char *cachedir;
char *configfile;
unsigned short op;
unsigned short verbose;
@@ -63,7 +63,7 @@ typedef struct __config_t {
config_t *config_new(void);
int config_free(config_t *config);
-void cb_db_register(char *section, PM_DB *db);
+void cb_db_register(char *section, pmdb_t *db);
#endif /* _PM_CONF_H */
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 4f6723e7..4caaf3c7 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -38,7 +38,7 @@ extern config_t *config;
int pacman_deptest(list_t *targets)
{
- PM_LIST *data;
+ pmlist_t *data;
list_t *i;
char *str;
int retval = 0;
@@ -94,7 +94,7 @@ int pacman_deptest(list_t *targets)
FREE(str);
if(alpm_trans_prepare(&data) == -1) {
- PM_LIST *lp;
+ pmlist_t *lp;
list_t *synctargs = NULL;
retval = 126;
/* return 126 = deps were missing, but successfully resolved
@@ -105,7 +105,7 @@ int pacman_deptest(list_t *targets)
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_DEPMISS *miss = alpm_list_getdata(lp);
+ pmdepmissing_t *miss = alpm_list_getdata(lp);
if(!config->op_d_resolve) {
MSG(NL, _("requires: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
@@ -122,7 +122,7 @@ int pacman_deptest(list_t *targets)
case PM_ERR_CONFLICTING_DEPS:
/* we can't auto-resolve conflicts */
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_DEPMISS *miss = alpm_list_getdata(lp);
+ pmdepmissing_t *miss = alpm_list_getdata(lp);
MSG(NL, _("conflict: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME));
}
retval = 127;
diff --git a/src/pacman/downloadprog.c b/src/pacman/downloadprog.c
index 0de34d3d..f831656b 100644
--- a/src/pacman/downloadprog.c
+++ b/src/pacman/downloadprog.c
@@ -77,7 +77,7 @@ void log_progress(const char *filename, int xfered, int total)
}
/* a little hard to conceal easter eggs in open-source software, but they're still fun. ;) */
- alpm_get_option(PM_OPT_CHOMP, &chomp);
+ chomp = alpm_option_get_chomp();
gettimeofday(&current_time, NULL);
total_timediff = current_time.tv_sec-initial_time.tv_sec
diff --git a/src/pacman/list.c b/src/pacman/list.c
index 0a080373..0c271978 100644
--- a/src/pacman/list.c
+++ b/src/pacman/list.c
@@ -101,7 +101,7 @@ static list_t *list_last(list_t *list)
/* Test for existence of a string in a list_t
*/
-int list_is_strin(char *needle, list_t *haystack)
+int list_is_strin(const char *needle, list_t *haystack)
{
list_t *lp;
@@ -144,9 +144,9 @@ void list_display(const char *title, list_t *list)
}
}
-void PM_LIST_display(const char *title, PM_LIST *list)
+void pmlist_display(const char *title, pmlist_t *list)
{
- PM_LIST *lp;
+ pmlist_t *lp;
int cols, len;
len = strlen(title);
@@ -172,17 +172,17 @@ void PM_LIST_display(const char *title, PM_LIST *list)
}
}
-/* Filter out any duplicate strings in a PM_LIST
+/* Filter out any duplicate strings in a pmlist_t
*
* Not the most efficient way, but simple to implement -- we assemble
* a new list, using is_in() to check for dupes at each iteration.
*
- * This function takes a PM_LIST* and returns a list_t*
+ * This function takes a pmlist_t* and returns a list_t*
*
*/
-list_t *PM_LIST_remove_dupes(PM_LIST *list)
+list_t *pmlist_remove_dupes(pmlist_t *list)
{
- PM_LIST *i;
+ pmlist_t *i;
list_t *newlist = NULL;
for(i = alpm_list_first(list); i; i = alpm_list_next(i)) {
diff --git a/src/pacman/list.h b/src/pacman/list.h
index 68f080e4..30830aae 100644
--- a/src/pacman/list.h
+++ b/src/pacman/list.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
-#ifndef _PM_LIST_H
-#define _PM_LIST_H
+#ifndef _LIST_H
+#define _LIST_H
#include <alpm.h>
@@ -42,12 +42,12 @@ list_t *list_new(void);
void list_free(list_t *list);
list_t *list_add(list_t *list, void *data);
int list_count(list_t *list);
-int list_is_strin(char *needle, list_t *haystack);
+int list_is_strin(const char *needle, list_t *haystack);
void list_display(const char *title, list_t *list);
-void PM_LIST_display(const char *title, PM_LIST *list);
-list_t *PM_LIST_remove_dupes(PM_LIST *list);
+void pmlist_display(const char *title, pmlist_t *list);
+list_t *pmlist_remove_dupes(pmlist_t *list);
-#endif /* _PM_LIST_H */
+#endif /*_LIST_H*/
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 498b6988..bf26c5c2 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -35,36 +35,36 @@
/* Display the content of an installed package
*/
-void dump_pkg_full(PM_PKG *pkg, int level)
+void dump_pkg_full(pmpkg_t *pkg, int level)
{
- char *date, *type;
+ const char *date, *type;
if(pkg == NULL) {
return;
}
- printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME));
- printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
+ printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
+ printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg));
- PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS));
+ pmlist_display(_("Groups :"), alpm_pkg_get_groups(pkg));
- printf(_("Packager : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_PACKAGER));
- printf("URL : %s\n", (char *)alpm_pkg_getinfo(pkg, PM_PKG_URL));
- PM_LIST_display(_("License :"), alpm_pkg_getinfo(pkg, PM_PKG_LICENSE));
- printf(_("Architecture : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_ARCH));
- printf(_("Size : %ld\n"), (long int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE));
+ printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg));
+ printf("URL : %s\n", (char *)alpm_pkg_get_url(pkg));
+ pmlist_display(_("License :"), alpm_pkg_get_licenses(pkg));
+ printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg));
+ printf(_("Size : %ld\n"), (long int)alpm_pkg_get_size(pkg));
- date = alpm_pkg_getinfo(pkg, PM_PKG_BUILDDATE);
+ date = alpm_pkg_get_builddate(pkg);
printf(_("Build Date : %s %s\n"), date, strlen(date) ? "UTC" : "");
- type = alpm_pkg_getinfo(pkg, PM_PKG_BUILDTYPE);
+ type = alpm_pkg_get_buildtype(pkg);
printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown"));
- date = alpm_pkg_getinfo(pkg, PM_PKG_INSTALLDATE);
+ date = alpm_pkg_get_installdate(pkg);
printf(_("Install Date : %s %s\n"), date, strlen(date) ? "UTC" : "");
- printf(_("Install Script : %s\n"), alpm_pkg_getinfo(pkg, PM_PKG_SCRIPLET) ? _("Yes") : _("No"));
+ printf(_("Install Script : %s\n"), alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
printf(_("Reason : "));
- switch((long)alpm_pkg_getinfo(pkg, PM_PKG_REASON)) {
+ switch((long)alpm_pkg_get_reason(pkg)) {
case PM_PKG_REASON_EXPLICIT:
printf(_("Explicitly installed\n"));
break;
@@ -76,24 +76,21 @@ void dump_pkg_full(PM_PKG *pkg, int level)
break;
}
- PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES));
- PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS));
- PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES));
- PM_LIST_display(_("Required By :"), alpm_pkg_getinfo(pkg, PM_PKG_REQUIREDBY));
- PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS));
+ pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
+ pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
+ pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg));
+ pmlist_display(_("Required By :"), alpm_pkg_get_requiredby(pkg));
+ pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
printf(_("Description : "));
- indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 17);
+ indentprint(alpm_pkg_get_desc(pkg), 17);
printf("\n");
if(level > 1) {
- PM_LIST *i;
- long lroot;
- char *root;
- alpm_get_option(PM_OPT_ROOT, &lroot);
- root = (void *)lroot;
+ pmlist_t *i;
+ const char *root = alpm_option_get_root();
fprintf(stdout, "\n");
- for(i = alpm_list_first(alpm_pkg_getinfo(pkg, PM_PKG_BACKUP)); i; i = alpm_list_next(i)) {
+ for(i = alpm_list_first(alpm_pkg_get_backup(pkg)); i; i = alpm_list_next(i)) {
struct stat buf;
char path[PATH_MAX];
char *str = strdup(alpm_list_getdata(i));
@@ -131,46 +128,47 @@ void dump_pkg_full(PM_PKG *pkg, int level)
/* Display the content of a sync package
*/
-void dump_pkg_sync(PM_PKG *pkg, char *treename)
+void dump_pkg_sync(pmpkg_t *pkg, char *treename)
{
- char *tmp1, *tmp2;
+ char *sum;
if(pkg == NULL) {
return;
}
printf(_("Repository : %s\n"), treename);
- printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME));
- printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
-
- PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS));
- PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES));
- PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS));
- PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES));
- PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS));
- PM_LIST_display(_("Replaces :"), alpm_pkg_getinfo(pkg, PM_PKG_REPLACES));
-
- printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE));
- printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE));
+ printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
+ printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg));
+
+ pmlist_display(_("Groups :"), alpm_pkg_get_groups(pkg));
+ pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
+ pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
+ pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg));
+ pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
+ pmlist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
+
+ printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_get_size(pkg));
+ printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_get_usize(pkg));
printf(_("Description : "));
- indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 20);
- tmp1 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM);
- if (tmp1 != NULL && tmp1[0] != '\0') {
- printf(_("\nMD5 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM));
- }
- tmp2 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM);
- if (tmp2 != NULL && tmp2[0] != '\0') {
- printf(_("\nSHA1 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM));
+ indentprint(alpm_pkg_get_desc(pkg), 20);
+
+ sum = (char *)alpm_pkg_get_md5sum(pkg);
+ if (sum != NULL && sum[0] != '\0') {
+ printf(_("\nMD5 Sum : %s"), sum);
+ }
+ sum = (char *)alpm_pkg_get_sha1sum(pkg);
+ if (sum != NULL && sum[0] != '\0') {
+ printf(_("\nSHA1 Sum : %s"), sum);
}
printf("\n");
}
-void dump_pkg_files(PM_PKG *pkg)
+void dump_pkg_files(pmpkg_t *pkg)
{
- char *pkgname;
- PM_LIST *i, *pkgfiles;
+ const char *pkgname;
+ pmlist_t *i, *pkgfiles;
- pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
- pkgfiles = alpm_pkg_getinfo(pkg, PM_PKG_FILES);
+ pkgname = alpm_pkg_get_name(pkg);
+ pkgfiles = alpm_pkg_get_files(pkg);
for(i = pkgfiles; i; i = alpm_list_next(i)) {
fprintf(stdout, "%s %s\n", (char *)pkgname, (char *)alpm_list_getdata(i));
@@ -181,7 +179,7 @@ void dump_pkg_files(PM_PKG *pkg)
/* Display the changelog of an installed package
*/
-void dump_pkg_changelog(char *clfile, char *pkgname)
+void dump_pkg_changelog(char *clfile, const char *pkgname)
{
FILE* fp = NULL;
char line[PATH_MAX+1];
diff --git a/src/pacman/package.h b/src/pacman/package.h
index 284105cb..e8c89c9b 100644
--- a/src/pacman/package.h
+++ b/src/pacman/package.h
@@ -21,11 +21,11 @@
#ifndef _PM_PACKAGE_H
#define _PM_PACKAGE_H
-void dump_pkg_full(PM_PKG *pkg, int level);
-void dump_pkg_sync(PM_PKG *pkg, char *treename);
+void dump_pkg_full(pmpkg_t *pkg, int level);
+void dump_pkg_sync(pmpkg_t *pkg, char *treename);
-void dump_pkg_files(PM_PKG *pkg);
-void dump_pkg_changelog(char *clfile, char *pkgname);
+void dump_pkg_files(pmpkg_t *pkg);
+void dump_pkg_changelog(char *clfile, const char *pkgname);
int split_pkgname(char *target, char *name, char *version);
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 79c15c3f..c138c2c4 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -75,7 +75,7 @@ enum {
config_t *config = NULL;
-PM_DB *db_local;
+pmdb_t *db_local;
/* list of (sync_t *) structs for sync locations */
list_t *pmc_syncs = NULL;
/* list of targets specified on command line */
@@ -322,10 +322,8 @@ static int parseargs(int argc, char *argv[])
config->op_d_vertest = 1;
break;
case 'b':
- if(config->dbpath) {
- FREE(config->dbpath);
- }
- config->dbpath = strdup(optarg);
+ alpm_option_set_dbpath(optarg);
+ config->dbpath = alpm_option_get_dbpath(optarg);
break;
case 'c':
config->op_s_clean++;
@@ -355,10 +353,8 @@ static int parseargs(int argc, char *argv[])
perror(_("bad root path"));
return(1);
}
- if(config->root) {
- free(config->root);
- }
- config->root = strdup(root);
+ alpm_option_set_root(root);
+ config->root = alpm_option_get_root();
break;
case 's':
config->op_s_search = 1;
@@ -404,7 +400,7 @@ static int parseargs(int argc, char *argv[])
int main(int argc, char *argv[])
{
int ret = 0;
- char *cenv = NULL, *lang = NULL;
+ char *lang = NULL;
#ifndef CYGWIN
uid_t myuid;
#endif
@@ -414,10 +410,7 @@ int main(int argc, char *argv[])
/*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/
mtrace();
#endif
- cenv = getenv("COLUMNS");
- if(cenv != NULL) {
- maxcols = atoi(cenv);
- }
+ maxcols = getcols();
/* set signal handlers */
signal(SIGINT, cleanup);
@@ -490,34 +483,33 @@ int main(int argc, char *argv[])
#endif
if(config->root == NULL) {
- config->root = strdup(PM_ROOT);
+ config->root = PM_ROOT;
}
+ char *initroot = NULL;
/* add a trailing '/' if there isn't one */
if(config->root[strlen(config->root)-1] != '/') {
char *ptr;
MALLOC(ptr, strlen(config->root)+2);
strcpy(ptr, config->root);
strcat(ptr, "/");
- FREE(config->root);
- config->root = ptr;
+ initroot = ptr;
+ } else {
+ initroot = strdup(config->root);
}
/* initialize pm library */
- if(alpm_initialize(config->root) == -1) {
+ if(alpm_initialize(initroot) == -1) {
ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno));
cleanup(1);
}
+ FREE(initroot);
+ config->root = alpm_option_get_root();
+
/* Setup logging as soon as possible, to print out maximum debugging info */
- if(alpm_set_option(PM_OPT_LOGMASK, (long)config->debug) == -1) {
- ERR(NL, _("failed to set option LOGMASK (%s)\n"), alpm_strerror(pm_errno));
- cleanup(1);
- }
- if(alpm_set_option(PM_OPT_LOGCB, (long)cb_log) == -1) {
- ERR(NL, _("failed to set option LOGCB (%s)\n"), alpm_strerror(pm_errno));
- cleanup(1);
- }
+ alpm_option_set_logmask(config->debug);
+ alpm_option_set_logcb(cb_log);
if(config->configfile == NULL) {
config->configfile = strdup(PACCONF);
@@ -528,23 +520,13 @@ int main(int argc, char *argv[])
}
/* set library parameters */
- if(alpm_set_option(PM_OPT_DLCB, (long)log_progress) == -1) {
- ERR(NL, _("failed to set option DLCB (%s)\n"), alpm_strerror(pm_errno));
- cleanup(1);
- }
- FREE(config->dbpath);
- long ldbpath, lcachedir;
- alpm_get_option(PM_OPT_DBPATH, &ldbpath);
- config->dbpath = (char *)ldbpath;
- FREE(config->cachedir);
- alpm_get_option(PM_OPT_CACHEDIR, &lcachedir);
- config->cachedir = (char *)lcachedir;
+ alpm_option_set_dlcb(log_progress);
+
+ config->dbpath = alpm_option_get_dbpath();
+ config->cachedir = alpm_option_get_cachedir();
for(lp = config->op_s_ignore; lp; lp = lp->next) {
- if(alpm_set_option(PM_OPT_IGNOREPKG, (long)lp->data) == -1) {
- ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno));
- cleanup(1);
- }
+ alpm_option_add_ignorepkg(lp->data);
}
if(config->verbose > 0) {
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 517ade74..e080ddf6 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -37,17 +37,16 @@
#include "util.h"
extern config_t *config;
-extern PM_DB *db_local;
+extern pmdb_t *db_local;
extern list_t *pmc_syncs;
-static int query_fileowner(PM_DB *db, char *filename)
+static int query_fileowner(pmdb_t *db, char *filename)
{
struct stat buf;
int gotcha = 0;
char rpath[PATH_MAX];
- PM_LIST *lp;
- long lroot;
- char *root;
+ pmlist_t *lp;
+ const char *root;
if(db == NULL) {
return(0);
@@ -62,23 +61,22 @@ static int query_fileowner(PM_DB *db, char *filename)
return(1);
}
- alpm_get_option(PM_OPT_ROOT, &lroot);
- root = (char *)lroot;
+ root = alpm_option_get_root();
for(lp = alpm_db_getpkgcache(db); lp && !gotcha; lp = alpm_list_next(lp)) {
- PM_PKG *info;
- PM_LIST *i;
+ pmpkg_t *info;
+ pmlist_t *i;
info = alpm_list_getdata(lp);
- for(i = alpm_pkg_getinfo(info, PM_PKG_FILES); i && !gotcha; i = alpm_list_next(i)) {
+ for(i = alpm_pkg_get_files(info); i && !gotcha; i = alpm_list_next(i)) {
char path[PATH_MAX];
char *filename = (char *)alpm_list_getdata(i);
snprintf(path, PATH_MAX, "%s%s", root, filename);
if(!strcmp(path, rpath)) {
- printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_getinfo(info, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(info, PM_PKG_VERSION));
+ printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_get_name(info),
+ (char *)alpm_pkg_get_version(info));
gotcha = 1;
break;
}
@@ -94,29 +92,29 @@ static int query_fileowner(PM_DB *db, char *filename)
int pacman_query(list_t *targets)
{
- PM_PKG *info = NULL;
+ pmpkg_t *info = NULL;
list_t *targ;
list_t *i;
- PM_LIST *j, *ret;
+ pmlist_t *j, *ret;
char *package = NULL;
int done = 0;
if(config->op_q_search) {
for(i = targets; i; i = i->next) {
- alpm_set_option(PM_OPT_NEEDLES, (long)i->data);
+ alpm_option_add_needle(i->data);
}
ret = alpm_db_search(db_local);
if(ret == NULL) {
return(1);
}
for(j = ret; j; j = alpm_list_next(j)) {
- PM_PKG *pkg = alpm_list_getdata(j);
+ pmpkg_t *pkg = alpm_list_getdata(j);
printf("local/%s/%s %s\n ",
- (char*)alpm_list_getdata(alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)),
- (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
- indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
+ (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg)),
+ alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg));
+ indentprint(alpm_pkg_get_desc(pkg), 4);
printf("\n");
}
alpm_list_free_outer(ret);
@@ -142,24 +140,24 @@ int pacman_query(list_t *targets)
/* looking for groups */
if(config->group) {
- PM_LIST *lp;
+ pmlist_t *lp;
if(targets == NULL) {
for(lp = alpm_db_getgrpcache(db_local); lp; lp = alpm_list_next(lp)) {
- PM_GRP *grp = alpm_list_getdata(lp);
- PM_LIST *i, *pkgnames;
- char *grpname;
+ pmgrp_t *grp = alpm_list_getdata(lp);
+ pmlist_t *i, *pkgnames;
+ const char *grpname;
- grpname = alpm_grp_getinfo(grp, PM_GRP_NAME);
- pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
+ grpname = alpm_grp_get_name(grp);
+ pkgnames = alpm_grp_get_packages(grp);
for(i = pkgnames; i; i = alpm_list_next(i)) {
MSG(NL, "%s %s\n", grpname, (char *)alpm_list_getdata(i));
}
}
} else {
- PM_GRP *grp = alpm_db_readgrp(db_local, package);
+ pmgrp_t *grp = alpm_db_readgrp(db_local, package);
if(grp) {
- PM_LIST *i, *pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
+ pmlist_t *i, *pkgnames = alpm_grp_get_packages(grp);
for(i = pkgnames; i; i = alpm_list_next(i)) {
MSG(NL, "%s %s\n", package, (char *)alpm_list_getdata(i));
}
@@ -189,8 +187,8 @@ int pacman_query(list_t *targets)
dump_pkg_files(info);
}
if(!config->op_q_info && !config->op_q_list) {
- MSG(NL, "%s %s\n", (char *)alpm_pkg_getinfo(info, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(info, PM_PKG_VERSION));
+ MSG(NL, "%s %s\n", alpm_pkg_get_name(info),
+ alpm_pkg_get_version(info));
}
FREEPKG(info);
continue;
@@ -203,17 +201,17 @@ int pacman_query(list_t *targets)
/* find packages in the db */
if(package == NULL) {
- PM_LIST *lp;
+ pmlist_t *lp;
/* no target */
for(lp = alpm_db_getpkgcache(db_local); lp; lp = alpm_list_next(lp)) {
- PM_PKG *tmpp = alpm_list_getdata(lp);
- char *pkgname, *pkgver;
+ pmpkg_t *tmpp = alpm_list_getdata(lp);
+ const char *pkgname, *pkgver;
- pkgname = alpm_pkg_getinfo(tmpp, PM_PKG_NAME);
- pkgver = alpm_pkg_getinfo(tmpp, PM_PKG_VERSION);
+ pkgname = alpm_pkg_get_name(tmpp);
+ pkgver = alpm_pkg_get_version(tmpp);
if(config->op_q_list || config->op_q_orphans || config->op_q_foreign) {
- info = alpm_db_readpkg(db_local, pkgname);
+ info = alpm_db_readpkg(db_local, (char *)pkgname);
if(info == NULL) {
/* something weird happened */
ERR(NL, _("package \"%s\" not found\n"), pkgname);
@@ -224,11 +222,11 @@ int pacman_query(list_t *targets)
for(i = pmc_syncs; i; i = i->next) {
sync_t *sync = (sync_t *)i->data;
for(j = alpm_db_getpkgcache(sync->db); j; j = alpm_list_next(j)) {
- PM_PKG *pkg = alpm_list_getdata(j);
+ pmpkg_t *pkg = alpm_list_getdata(j);
char *haystack;
char *needle;
- haystack = strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME));
- needle = strdup(alpm_pkg_getinfo(info, PM_PKG_NAME));
+ haystack = strdup(alpm_pkg_get_name(pkg));
+ needle = strdup(alpm_pkg_get_name(info));
if(!strcmp(haystack, needle)) {
match = 1;
}
@@ -244,8 +242,8 @@ int pacman_query(list_t *targets)
dump_pkg_files(info);
}
if(config->op_q_orphans) {
- if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL
- && (long)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_DEPEND) {
+ if(alpm_pkg_get_requiredby(info) == NULL
+ && (long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND) {
MSG(NL, "%s %s\n", pkgname, pkgver);
}
}
@@ -254,7 +252,8 @@ int pacman_query(list_t *targets)
}
}
} else {
- char *pkgname = NULL, *pkgver = NULL, changelog[PATH_MAX];
+ const char *pkgname = NULL, *pkgver = NULL;
+ char changelog[PATH_MAX];
info = alpm_db_readpkg(db_local, package);
if(info == NULL) {
@@ -265,16 +264,14 @@ int pacman_query(list_t *targets)
/* find a target */
if(config->op_q_changelog || config->op_q_info || config->op_q_list) {
if(config->op_q_changelog) {
- long ldbpath;
- char *dbpath;
- alpm_get_option(PM_OPT_DBPATH, &ldbpath);
- dbpath = (char *)ldbpath;
+ const char *dbpath;
+ dbpath = alpm_option_get_dbpath();
snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog",
config->root, dbpath,
- (char*)alpm_db_getinfo(db_local, PM_DB_TREENAME),
- (char*)alpm_pkg_getinfo(info, PM_PKG_NAME),
- (char*)alpm_pkg_getinfo(info, PM_PKG_VERSION));
- dump_pkg_changelog(changelog, (char*)alpm_pkg_getinfo(info, PM_PKG_NAME));
+ alpm_db_get_name(db_local),
+ alpm_pkg_get_name(info),
+ alpm_pkg_get_version(info));
+ dump_pkg_changelog(changelog, alpm_pkg_get_name(info));
}
if(config->op_q_info) {
dump_pkg_full(info, config->op_q_info);
@@ -283,12 +280,12 @@ int pacman_query(list_t *targets)
dump_pkg_files(info);
}
} else if(config->op_q_orphans) {
- if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL) {
+ if(alpm_pkg_get_requiredby(info) == NULL) {
MSG(NL, "%s %s\n", pkgname, pkgver);
}
} else {
- pkgname = alpm_pkg_getinfo(info, PM_PKG_NAME);
- pkgver = alpm_pkg_getinfo(info, PM_PKG_VERSION);
+ pkgname = alpm_pkg_get_name(info);
+ pkgver = alpm_pkg_get_version(info);
MSG(NL, "%s %s\n", pkgname, pkgver);
}
}
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 475df393..ddc22e7e 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -35,11 +35,11 @@
extern config_t *config;
-extern PM_DB *db_local;
+extern pmdb_t *db_local;
int pacman_remove(list_t *targets)
{
- PM_LIST *data;
+ pmlist_t *data;
list_t *i;
list_t *finaltargs = NULL;
int retval = 0;
@@ -52,17 +52,17 @@ int pacman_remove(list_t *targets)
* (the library can't remove groups for now)
*/
for(i = targets; i; i = i->next) {
- PM_GRP *grp;
+ pmgrp_t *grp;
grp = alpm_db_readgrp(db_local, i->data);
if(grp) {
- PM_LIST *lp, *pkgnames;
+ pmlist_t *lp, *pkgnames;
int all;
- pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
+ pkgnames = alpm_grp_get_packages(grp);
- MSG(NL, _(":: group %s:\n"), alpm_grp_getinfo(grp, PM_GRP_NAME));
- PM_LIST_display(" ", pkgnames);
+ MSG(NL, _(":: group %s:\n"), alpm_grp_get_name(grp));
+ pmlist_display(" ", pkgnames);
all = yesno(_(" Remove whole content? [Y/n] "));
for(lp = alpm_list_first(pkgnames); lp; lp = alpm_list_next(lp)) {
if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), (char *)alpm_list_getdata(lp), i->data)) {
@@ -98,12 +98,12 @@ int pacman_remove(list_t *targets)
/* Step 2: prepare the transaction based on its type, targets and flags
*/
if(alpm_trans_prepare(&data) == -1) {
- PM_LIST *lp;
+ pmlist_t *lp;
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_DEPMISS *miss = alpm_list_getdata(lp);
+ pmdepmissing_t *miss = alpm_list_getdata(lp);
MSG(NL, _(" %s: is required by %s\n"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
alpm_dep_getinfo(miss, PM_DEP_NAME));
}
@@ -119,12 +119,12 @@ int pacman_remove(list_t *targets)
/* Warn user in case of dangerous operation
*/
if(config->flags & PM_TRANS_FLAG_RECURSE || config->flags & PM_TRANS_FLAG_CASCADE) {
- PM_LIST *lp;
+ pmlist_t *lp;
/* list transaction targets */
i = NULL;
for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
- i = list_add(i, strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME)));
+ pmpkg_t *pkg = alpm_list_getdata(lp);
+ i = list_add(i, strdup(alpm_pkg_get_name(pkg)));
}
list_display(_("\nTargets:"), i);
FREELIST(i);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 345f9fd4..e40a27bc 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -54,14 +54,11 @@ extern list_t *pmc_syncs;
static int sync_cleancache(int level)
{
- long lroot, lcachedir;
- char *root, *cachedir;
+ const char *root, *cachedir;
char dirpath[PATH_MAX];
- alpm_get_option(PM_OPT_ROOT, &lroot);
- root = (void *)lroot;
- alpm_get_option(PM_OPT_CACHEDIR, &lcachedir);
- cachedir = (void *)lcachedir;
+ root = alpm_option_get_root();
+ cachedir = alpm_option_get_cachedir();
snprintf(dirpath, PATH_MAX, "%s%s", root, cachedir);
@@ -191,40 +188,41 @@ static int sync_synctree(int level, list_t *syncs)
static int sync_search(list_t *syncs, list_t *targets)
{
list_t *i;
- PM_LIST *ret;
+ pmlist_t *ret;
for(i = targets; i; i = i->next) {
- alpm_set_option(PM_OPT_NEEDLES, (long)i->data);
+ alpm_option_add_needle(i->data);
}
+
for(i = syncs; i; i = i->next) {
sync_t *sync = i->data;
if(targets) {
- PM_LIST *lp;
+ pmlist_t *lp;
ret = alpm_db_search(sync->db);
if(ret == NULL) {
continue;
}
for(lp = ret; lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
+ pmpkg_t *pkg = alpm_list_getdata(lp);
- char *group = (char *)alpm_list_getdata(alpm_pkg_getinfo(pkg,PM_PKG_GROUPS));
+ char *group = (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg));
printf("%s/%s %s %s%s%s\n ",
- (char *)alpm_db_getinfo(sync->db, PM_DB_TREENAME),
- (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION),
+ alpm_db_get_name(sync->db),
+ alpm_pkg_get_name(pkg),
+ alpm_pkg_get_version(pkg),
(group ? " (" : ""), (group ? group : ""), (group ? ") " : ""));
- indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
+ indentprint(alpm_pkg_get_desc(pkg), 4);
printf("\n\n");
}
alpm_list_free_outer(ret);
} else {
- PM_LIST *lp;
+ pmlist_t *lp;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
+ pmpkg_t *pkg = alpm_list_getdata(lp);
- MSG(NL, "%s/%s %s\n ", sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
- indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
+ MSG(NL, "%s/%s %s\n ", sync->treename, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ indentprint(alpm_pkg_get_desc(pkg), 4);
MSG(NL, "\n");
}
}
@@ -241,25 +239,25 @@ static int sync_group(int level, list_t *syncs, list_t *targets)
for(i = targets; i; i = i->next) {
for(j = syncs; j; j = j->next) {
sync_t *sync = j->data;
- PM_GRP *grp = alpm_db_readgrp(sync->db, i->data);
+ pmgrp_t *grp = alpm_db_readgrp(sync->db, i->data);
if(grp) {
- MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
- PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
+ MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp));
+ pmlist_display(" ", alpm_grp_get_packages(grp));
}
}
}
} else {
for(j = syncs; j; j = j->next) {
sync_t *sync = j->data;
- PM_LIST *lp;
+ pmlist_t *lp;
for(lp = alpm_db_getgrpcache(sync->db); lp; lp = alpm_list_next(lp)) {
- PM_GRP *grp = alpm_list_getdata(lp);
+ pmgrp_t *grp = alpm_list_getdata(lp);
- MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
+ MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp));
if(grp && level > 1) {
- PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
+ pmlist_display(" ", alpm_grp_get_packages(grp));
}
}
}
@@ -278,12 +276,12 @@ static int sync_info(list_t *syncs, list_t *targets)
for(j = syncs; j && !found; j = j->next) {
sync_t *sync = j->data;
- PM_LIST *lp;
+ pmlist_t *lp;
for(lp = alpm_db_getpkgcache(sync->db); !found && lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
+ pmpkg_t *pkg = alpm_list_getdata(lp);
- if(!strcmp(alpm_pkg_getinfo(pkg, PM_PKG_NAME), i->data)) {
+ if(!strcmp(alpm_pkg_get_name(pkg), i->data)) {
dump_pkg_sync(pkg, sync->treename);
MSG(NL, "\n");
found = 1;
@@ -298,7 +296,7 @@ static int sync_info(list_t *syncs, list_t *targets)
} else {
for(j = syncs; j; j = j->next) {
sync_t *sync = j->data;
- PM_LIST *lp;
+ pmlist_t *lp;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
dump_pkg_sync(alpm_list_getdata(lp), sync->treename);
@@ -341,13 +339,13 @@ static int sync_list(list_t *syncs, list_t *targets)
}
for(i = ls; i; i = i->next) {
- PM_LIST *lp;
+ pmlist_t *lp;
sync_t *sync = i->data;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
+ pmpkg_t *pkg = alpm_list_getdata(lp);
- MSG(NL, "%s %s %s\n", (char *)sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
+ MSG(NL, "%s %s %s\n", (char *)sync->treename, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
}
}
@@ -363,7 +361,7 @@ int pacman_sync(list_t *targets)
int confirm = 0;
int retval = 0;
list_t *i = NULL;
- PM_LIST *packages, *data, *lp;
+ pmlist_t *packages, *data, *lp;
if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
ERR(NL, _("no usable package repositories configured.\n"));
@@ -428,9 +426,9 @@ int pacman_sync(list_t *targets)
*/
data = alpm_trans_getinfo(PM_TRANS_PACKAGES);
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_SYNCPKG *sync = alpm_list_getdata(lp);
- PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
- if(!strcmp("pacman", alpm_pkg_getinfo(spkg, PM_PKG_NAME)) && alpm_list_count(data) > 1) {
+ pmsyncpkg_t *sync = alpm_list_getdata(lp);
+ pmpkg_t *spkg = alpm_sync_get_package(sync);
+ if(!strcmp("pacman", alpm_pkg_get_name(spkg)) && alpm_list_count(data) > 1) {
MSG(NL, _("\n:: pacman has detected a newer version of the \"pacman\" package.\n"));
MSG(NL, _(":: It is recommended that you allow pacman to upgrade itself\n"));
MSG(NL, _(":: first, then you can re-run the operation with the newer version.\n"));
@@ -463,7 +461,7 @@ int pacman_sync(list_t *targets)
for(i = targets; i; i = i->next) {
char *targ = i->data;
if(alpm_trans_addtarget(targ) == -1) {
- PM_GRP *grp = NULL;
+ pmgrp_t *grp = NULL;
list_t *j;
int found=0;
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
@@ -480,14 +478,14 @@ int pacman_sync(list_t *targets)
sync_t *sync = j->data;
grp = alpm_db_readgrp(sync->db, targ);
if(grp) {
- PM_LIST *pmpkgs;
+ pmlist_t *pmpkgs;
list_t *k, *pkgs;
found++;
MSG(NL, _(":: group %s:\n"), targ);
- pmpkgs = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
+ pmpkgs = alpm_grp_get_packages(grp);
/* remove dupe entries in case a package exists in multiple repos */
- /* (the dupe function takes a PM_LIST* and returns a list_t*) */
- pkgs = PM_LIST_remove_dupes(pmpkgs);
+ /* (the dupe function takes a pmlist_t* and returns a list_t*) */
+ pkgs = pmlist_remove_dupes(pmpkgs);
list_display(" ", pkgs);
if(yesno(_(":: Install whole content? [Y/n] "))) {
for(k = pkgs; k; k = k->next) {
@@ -506,14 +504,14 @@ int pacman_sync(list_t *targets)
}
if(!found) {
/* targ not found in sync db, searching for providers... */
- PM_LIST *k = NULL;
- PM_PKG *pkg;
- char *pname = NULL;
+ pmlist_t *k = NULL;
+ pmpkg_t *pkg;
+ const char *pname = NULL;
for(j = pmc_syncs; j && !k; j = j->next) {
sync_t *sync = j->data;
k = alpm_db_whatprovides(sync->db, targ);
- pkg = (PM_PKG*)alpm_list_getdata(alpm_list_first(k));
- pname = (char*)alpm_pkg_getinfo(pkg, PM_PKG_NAME);
+ pkg = (pmpkg_t*)alpm_list_getdata(alpm_list_first(k));
+ pname = alpm_pkg_get_name(pkg);
}
if(pname != NULL) {
/* targ is provided by pname */
@@ -536,7 +534,7 @@ int pacman_sync(list_t *targets)
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_DEPMISS *miss = alpm_list_getdata(lp);
+ pmdepmissing_t *miss = alpm_list_getdata(lp);
MSG(NL, ":: %s: %s %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
(long)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? _("requires") : _("is required by"),
alpm_dep_getinfo(miss, PM_DEP_NAME));
@@ -550,7 +548,7 @@ int pacman_sync(list_t *targets)
break;
case PM_ERR_CONFLICTING_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_DEPMISS *miss = alpm_list_getdata(lp);
+ pmdepmissing_t *miss = alpm_list_getdata(lp);
MSG(NL, _(":: %s: conflicts with %s"),
alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME));
@@ -588,26 +586,26 @@ int pacman_sync(list_t *targets)
double mb, umb;
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
- PM_SYNCPKG *sync = alpm_list_getdata(lp);
- PM_PKG *pkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
- char *pkgname, *pkgver;
+ pmsyncpkg_t *sync = alpm_list_getdata(lp);
+ pmpkg_t *pkg = alpm_sync_get_package(sync);
+ const char *pkgname, *pkgver;
- if((long)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
- PM_LIST *j, *data;
- data = alpm_sync_getinfo(sync, PM_SYNC_DATA);
+ if(alpm_sync_get_type(sync) == PM_SYNC_TYPE_REPLACE) {
+ pmlist_t *j, *data;
+ data = alpm_sync_get_data(sync);
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
- PM_PKG *p = alpm_list_getdata(j);
- char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME);
+ pmpkg_t *p = alpm_list_getdata(j);
+ const char *pkgname = alpm_pkg_get_name(p);
if(!list_is_strin(pkgname, list_remove)) {
list_remove = list_add(list_remove, strdup(pkgname));
}
}
}
- pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
- pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
- totalsize += (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
- totalusize += (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE);
+ pkgname = alpm_pkg_get_name(pkg);
+ pkgver = alpm_pkg_get_version(pkg);
+ totalsize += alpm_pkg_get_size(pkg);
+ totalusize += alpm_pkg_get_usize(pkg);
asprintf(&str, "%s-%s", pkgname, pkgver);
list_install = list_add(list_install, str);
@@ -673,7 +671,7 @@ int pacman_sync(list_t *targets)
switch(pm_errno) {
case PM_ERR_FILE_CONFLICTS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
- PM_CONFLICT *conflict = alpm_list_getdata(lp);
+ pmconflict_t *conflict = alpm_list_getdata(lp);
switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
case PM_CONFLICT_TYPE_TARGET:
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),
diff --git a/src/pacman/sync.h b/src/pacman/sync.h
index 0452f1c2..e61668e4 100644
--- a/src/pacman/sync.h
+++ b/src/pacman/sync.h
@@ -24,7 +24,7 @@
/* Repositories */
typedef struct __sync_t {
char *treename;
- PM_DB *db;
+ pmdb_t *db;
} sync_t;
int pacman_sync(list_t *targets);
diff --git a/src/pacman/trans.c b/src/pacman/trans.c
index ce032dc4..0b141906 100644
--- a/src/pacman/trans.c
+++ b/src/pacman/trans.c
@@ -84,7 +84,7 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
break;
case PM_TRANS_EVT_ADD_START:
if(config->noprogressbar) {
- MSG(NL, _("installing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ MSG(NL, _("installing %s... "), alpm_pkg_get_name(data1));
}
break;
case PM_TRANS_EVT_ADD_DONE:
@@ -92,13 +92,13 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
MSG(CL, _("done.\n"));
}
snprintf(str, LOG_STR_LEN, _("installed %s (%s)"),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data1));
alpm_logaction(str);
break;
case PM_TRANS_EVT_REMOVE_START:
if(config->noprogressbar) {
- MSG(NL, _("removing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ MSG(NL, _("removing %s... "), alpm_pkg_get_name(data1));
}
break;
case PM_TRANS_EVT_REMOVE_DONE:
@@ -106,13 +106,13 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
MSG(CL, _("done.\n"));
}
snprintf(str, LOG_STR_LEN, _("removed %s (%s)"),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data1));
alpm_logaction(str);
break;
case PM_TRANS_EVT_UPGRADE_START:
if(config->noprogressbar) {
- MSG(NL, _("upgrading %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ MSG(NL, _("upgrading %s... "), alpm_pkg_get_name(data1));
}
break;
case PM_TRANS_EVT_UPGRADE_DONE:
@@ -120,9 +120,9 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
MSG(CL, _("done.\n"));
}
snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ (char *)alpm_pkg_get_name(data1),
+ (char *)alpm_pkg_get_version(data2),
+ (char *)alpm_pkg_get_version(data1));
alpm_logaction(str);
break;
case PM_TRANS_EVT_INTEGRITY_START:
@@ -178,8 +178,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
}
} else {
snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_name(data2));
*response = yesno(str);
}
break;
@@ -192,7 +192,7 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
}
} else {
snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ alpm_pkg_get_name(data1));
*response = yesno(str);
}
break;
@@ -205,9 +205,9 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
}
} else {
snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
+ alpm_pkg_get_name(data1),
(char *)data3,
- (char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
+ alpm_pkg_get_name(data2));
*response = yesno(str);
}
break;
@@ -236,8 +236,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} else {
if(!config->op_s_downloadonly) {
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data1));
*response = yesno(str);
} else {
*response = 1;
@@ -254,8 +254,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} else {
if(!config->op_s_downloadonly) {
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data1));
*response = yesno(str);
} else {
*response = 1;
@@ -349,7 +349,7 @@ void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howm
break;
}
- alpm_get_option(PM_OPT_CHOMP, &chomp);
+ chomp = alpm_option_get_chomp();
/* hide the cursor, prevent flicker during fancy graphics
printf("\033[?25l\033[?1c[");
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8dd0f11d..68f39e38 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -49,6 +49,16 @@ extern int maxcols;
extern config_t *config;
extern int neednl;
+/* gets the current screen column width */
+int getcols()
+{
+ const char *cenv = getenv("COLUMNS");
+ if(cenv != NULL) {
+ return atoi(cenv);
+ }
+ return -1;
+}
+
/* does the same thing as 'mkdir -p' */
int makepath(char *path)
{
@@ -126,14 +136,14 @@ int rmrf(char *path)
/* output a string, but wrap words properly with a specified indentation
*/
-void indentprint(char *str, int indent)
+void indentprint(const char *str, int indent)
{
- char *p = str;
+ const char *p = str;
int cidx = indent;
while(*p) {
if(*p == ' ') {
- char *next = NULL;
+ const char *next = NULL;
int len;
p++;
if(p == NULL || *p == ' ') continue;
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 2eab6c79..b1730385 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -43,10 +43,10 @@
} while(0)
#define _(str) gettext(str)
-
+int getcols();
int makepath(char *path);
int rmrf(char *path);
-void indentprint(char *str, int indent);
+void indentprint(const char *str, int indent);
char *buildstring(list_t *strlist);
char *strtoupper(char *str);
char *strtrim(char *str);