* repo-add script - to add entries to a db file directly from package data (no PKGBUILD)

* libalpm api changes - move from a _getinfo(p, WHAT_WE_WANT) scheme to a
  typesafe _get_what_we_want(p) scheme [not 100% complete yet]
* some const correctness changes
* removal of PM_* types in alpm.h in favor of the pm*_t types used throughout
  libalpm
This commit is contained in:
Aaron Griffin 2006-11-20 09:10:23 +00:00
parent b8b9596b13
commit aa1c0ba9f8
49 changed files with 1297 additions and 1082 deletions

View file

@ -13,11 +13,11 @@
%pointer_cast(void *, long *, void_to_long); %pointer_cast(void *, long *, void_to_long);
%pointer_cast(void *, char *, void_to_char); %pointer_cast(void *, char *, void_to_char);
%pointer_cast(void *, unsigned long, void_to_unsigned_long); %pointer_cast(void *, unsigned long, void_to_unsigned_long);
%pointer_cast(void *, PM_LIST *, void_to_PM_LIST); %pointer_cast(void *, pmlist_t *, void_to_pmlist);
%pointer_cast(void *, PM_PKG *, void_to_PM_PKG); %pointer_cast(void *, pmpkg_t *, void_to_pmpkg);
%pointer_cast(void *, PM_GRP *, void_to_PM_GRP); %pointer_cast(void *, pmgrp_t *, void_to_pmgrp);
%pointer_cast(void *, PM_SYNCPKG *, void_to_PM_SYNCPKG); %pointer_cast(void *, pmsyncpkg_t *, void_to_pmsyncpkg);
%pointer_cast(void *, PM_DB *, void_to_PM_DB); %pointer_cast(void *, pmdb_t *, void_to_pmdb);
%pointer_cast(void *, PM_CONFLICT *, void_to_PM_CONFLICT); %pointer_cast(void *, pmconflict_t *, void_to_pmconflict);
%include "alpm.h" %include "alpm.h"

View file

@ -39,7 +39,7 @@ dnl Put out version numbers to config.h
AC_DEFINE_UNQUOTED([PM_VERSION], ["$PM_VERSION"], [libalpm version number]) AC_DEFINE_UNQUOTED([PM_VERSION], ["$PM_VERSION"], [libalpm version number])
dnl Configuration files 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_PROG_CC
AC_HEADER_STDC AC_HEADER_STDC
@ -353,6 +353,8 @@ doc/libalpm.3
doc/pacman.8 doc/pacman.8
doc/hu/Makefile doc/hu/Makefile
etc/Makefile etc/Makefile
etc/makepkg.conf
etc/pacman.conf
etc/pacman.d/Makefile etc/pacman.d/Makefile
bindings/perl/Makefile bindings/perl/Makefile
bindings/python/Makefile bindings/python/Makefile

View file

@ -21,8 +21,8 @@
#ifndef _ALPM_ADD_H #ifndef _ALPM_ADD_H
#define _ALPM_ADD_H #define _ALPM_ADD_H
#include "list.h"
#include "db.h" #include "db.h"
#include "list.h"
#include "trans.h" #include "trans.h"
int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name); int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);

View file

@ -65,7 +65,7 @@
pmhandle_t *handle = NULL; pmhandle_t *handle = NULL;
enum __pmerrno_t pm_errno; enum __pmerrno_t pm_errno;
/** @defgroup alpm_interface Interface Functions /** \addtogroup alpm_interface Interface Functions
* @brief Function to initialize and release libalpm * @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 /) * @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) * @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]; 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 * @brief Functions to set and get libalpm options
* @{ * @{
*/ */
/** Set a library option. /** \addtogroup alpm_databases Database Functions
* @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
* @brief Frunctions to query and manipulate the database of libalpm * @brief Frunctions to query and manipulate the database of libalpm
* @{ * @{
*/ */
@ -224,36 +196,6 @@ int alpm_db_unregister(pmdb_t *db)
return(0); 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. /** Set the serverlist of a database.
* @param db database pointer * @param db database pointer
* @param url url of the server * @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 * @return 0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up
* to date * to date
*/ */
int alpm_db_update(int force, PM_DB *db) int alpm_db_update(int force, pmdb_t *db)
{ {
pmlist_t *lp; pmlist_t *lp;
char path[PATH_MAX]; 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 * @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. /** Create a package from a file.
* @param filename location of the package tarball * @param filename location of the package tarball
* @param pkg address of the package pointer * @param pkg address of the package pointer
@ -746,64 +587,11 @@ char *alpm_pkg_name_hasarch(char *pkgname)
/** @} */ /** @} */
/** @defgroup alpm_groups Group Functions /** \addtogroup alpm_sync Sync 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
* @brief Functions to get informations about libalpm syncs * @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 /** Searches a database
* @param db pointer to the package database to search in * @param db pointer to the package database to search in
* @return the list of packages on success, NULL on error * @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 * @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 * @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 * @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 * @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 * @brief Functions to manipulate libalpm linked lists
* @{ * @{
*/ */
@ -1128,7 +916,7 @@ pmlist_t *alpm_list_next(pmlist_t *entry)
* @param entry the list entry * @param entry the list entry
* @return the data on success, NULL on error * @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)); ASSERT(entry != NULL, return(NULL));
@ -1165,7 +953,7 @@ int alpm_list_free_outer(pmlist_t *entry)
* @param list the list to count * @param list the list to count
* @return number of entries on success, NULL on error * @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)); 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 * @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; char *key = NULL;
int linenum = 0; int linenum = 0;
char section[256] = ""; char section[256] = "";
PM_DB *db = NULL; pmdb_t *db = NULL;
fp = fopen(file, "r"); fp = fopen(file, "r");
if(fp == NULL) { 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(ptr == NULL) {
if(!strcmp(key, "NOPASSIVEFTP")) { 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")) { } 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")); _alpm_log(PM_LOG_DEBUG, _("config: usesyslog"));
} else if(!strcmp(key, "ILOVECANDY")) { } 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 { } else {
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1); 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")) { if(!strcmp(key, "NOUPGRADE")) {
char *p = ptr; char *p = ptr;
char *q; char *q;
while((q = strchr(p, ' '))) { while((q = strchr(p, ' '))) {
*q = '\0'; *q = '\0';
if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) { alpm_option_add_noupgrade(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
p = q; p = q;
p++; p++;
} }
if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) { alpm_option_add_noupgrade(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
} else if(!strcmp(key, "NOEXTRACT")) { } else if(!strcmp(key, "NOEXTRACT")) {
char *p = ptr; char *p = ptr;
char *q; char *q;
while((q = strchr(p, ' '))) { while((q = strchr(p, ' '))) {
*q = '\0'; *q = '\0';
if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) { alpm_option_add_noextract(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
p = q; p = q;
p++; p++;
} }
if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) { alpm_option_add_noextract(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
} else if(!strcmp(key, "IGNOREPKG")) { } else if(!strcmp(key, "IGNOREPKG")) {
char *p = ptr; char *p = ptr;
char *q; char *q;
while((q = strchr(p, ' '))) { while((q = strchr(p, ' '))) {
*q = '\0'; *q = '\0';
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) { alpm_option_add_ignorepkg(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
p = q; p = q;
p++; p++;
} }
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) { alpm_option_add_ignorepkg(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
} else if(!strcmp(key, "HOLDPKG")) { } else if(!strcmp(key, "HOLDPKG")) {
char *p = ptr; char *p = ptr;
char *q; char *q;
while((q = strchr(p, ' '))) { while((q = strchr(p, ' '))) {
*q = '\0'; *q = '\0';
if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) { alpm_option_add_holdpkg(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
p = q; p = q;
p++; p++;
} }
if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) { alpm_option_add_holdpkg(p);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p); _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
} else if(!strcmp(key, "DBPATH")) { } else if(!strcmp(key, "DBPATH")) {
/* shave off the leading slash, if there is one */ /* shave off the leading slash, if there is one */
if(*ptr == '/') { if(*ptr == '/') {
ptr++; ptr++;
} }
if(alpm_set_option(PM_OPT_DBPATH, (long)ptr) == -1) { alpm_option_set_dbpath(ptr);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr); _alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr);
} else if(!strcmp(key, "CACHEDIR")) { } else if(!strcmp(key, "CACHEDIR")) {
/* shave off the leading slash, if there is one */ /* shave off the leading slash, if there is one */
if(*ptr == '/') { if(*ptr == '/') {
ptr++; ptr++;
} }
if(alpm_set_option(PM_OPT_CACHEDIR, (long)ptr) == -1) { alpm_option_set_cachedir(ptr);
/* pm_errno is set by alpm_set_option */
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr); _alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr);
} else if (!strcmp(key, "LOGFILE")) { } else if (!strcmp(key, "LOGFILE")) {
if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) { alpm_option_set_logfile(ptr);
/* pm_errno is set by alpm_set_option */ _alpm_log(PM_LOG_DEBUG, _("config: logfile: %s"), ptr);
return(-1);
}
_alpm_log(PM_LOG_DEBUG, _("config: log file: %s"), ptr);
} else if (!strcmp(key, "XFERCOMMAND")) { } else if (!strcmp(key, "XFERCOMMAND")) {
if(alpm_set_option(PM_OPT_XFERCOMMAND, (long)ptr) == -1) { alpm_option_set_xfercommand(ptr);
/* pm_errno is set by alpm_set_option */ _alpm_log(PM_LOG_DEBUG, _("config: xfercommand: %s"), ptr);
return(-1);
}
} else if (!strcmp(key, "UPGRADEDELAY")) { } else if (!strcmp(key, "UPGRADEDELAY")) {
/* The config value is in days, we use seconds */ /* The config value is in days, we use seconds */
_alpm_log(PM_LOG_DEBUG, _("config: UpgradeDelay: %i"), (60*60*24) * atol(ptr)); long ud = atol(ptr) * 60 * 60 *24;
if(alpm_set_option(PM_OPT_UPGRADEDELAY, (60*60*24) * atol(ptr)) == -1) { alpm_option_set_upgradedelay(ud);
/* pm_errno is set by alpm_set_option */ _alpm_log(PM_LOG_DEBUG, _("config: upgradedelay: %d"), ud);
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);
}
} else { } else {
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1); RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
} }

View file

@ -28,6 +28,8 @@
extern "C" { extern "C" {
#endif #endif
#include <time.h> /* for time_t */
/* /*
* Arch Linux Package Management library * Arch Linux Package Management library
*/ */
@ -42,23 +44,25 @@ extern "C" {
#define PM_EXT_DB ".db.tar.gz" #define PM_EXT_DB ".db.tar.gz"
/* /*
* Structures (opaque) * Structures
*/ */
typedef struct __pmlist_t PM_LIST; typedef struct __pmlist_t pmlist_t;
typedef struct __pmdb_t PM_DB; typedef struct __pmdb_t pmdb_t;
typedef struct __pmpkg_t PM_PKG; typedef struct __pmpkg_t pmpkg_t;
typedef struct __pmgrp_t PM_GRP; typedef struct __pmgrp_t pmgrp_t;
typedef struct __pmsyncpkg_t PM_SYNCPKG; typedef struct __pmserver_t pmserver_t;
typedef struct __pmtrans_t PM_TRANS; typedef struct __pmtrans_t pmtrans_t;
typedef struct __pmdepmissing_t PM_DEPMISS; typedef struct __pmsyncpkg_t pmsyncpkg_t;
typedef struct __pmconflict_t PM_CONFLICT; typedef struct __pmdepend_t pmdepend_t;
typedef struct __pmdepmissing_t pmdepmissing_t;
typedef struct __pmconflict_t pmconflict_t;
/* /*
* Library * Library
*/ */
int alpm_initialize(char *root); int alpm_initialize(const char *root);
int alpm_release(void); int alpm_release(void);
/* /*
@ -74,120 +78,110 @@ int alpm_release(void);
#define PM_LOG_FUNCTION 0x20 #define PM_LOG_FUNCTION 0x20
#define PM_LOG_DOWNLOAD 0x40 #define PM_LOG_DOWNLOAD 0x40
typedef void (*alpm_cb_log)(unsigned short, char *);
int alpm_logaction(char *fmt, ...); int alpm_logaction(char *fmt, ...);
/*
* Downloading
*/
typedef void (*alpm_cb_download)(const char *filename, int xfered, int total);
/* /*
* Options * Options
*/ */
#define PM_DLFNM_LEN 22 #define PM_DLFNM_LEN 22
/* Parameters */ alpm_cb_log alpm_option_get_logcb();
enum { void alpm_option_set_logcb(alpm_cb_log cb);
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
};
int alpm_set_option(unsigned char parm, unsigned long data); alpm_cb_download alpm_option_get_dlcb();
int alpm_get_option(unsigned char parm, long *data); 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);
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 * Databases
*/ */
/* Info parameters */
enum {
PM_DB_TREENAME = 1,
PM_DB_FIRSTSERVER
};
/* Database registration callback */ /* Database registration callback */
typedef void (*alpm_cb_db_register)(char *, PM_DB *); typedef void (*alpm_cb_db_register)(char *, pmdb_t *);
PM_DB *alpm_db_register(char *treename); pmdb_t *alpm_db_register(char *treename);
int alpm_db_unregister(PM_DB *db); int alpm_db_unregister(pmdb_t *db);
void *alpm_db_getinfo(PM_DB *db, unsigned char parm); const char *alpm_db_get_name(pmdb_t *db);
int alpm_db_setserver(PM_DB *db, const char *url); const char *alpm_db_get_url(pmdb_t *db);
int alpm_db_update(int level, PM_DB *db); int alpm_db_setserver(pmdb_t *db, const char *url);
PM_PKG *alpm_db_readpkg(PM_DB *db, char *name); int alpm_db_update(int level, pmdb_t *db);
PM_LIST *alpm_db_getpkgcache(PM_DB *db);
PM_LIST *alpm_db_whatprovides(PM_DB *db, char *name);
PM_GRP *alpm_db_readgrp(PM_DB *db, char *name); pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name);
PM_LIST *alpm_db_getgrpcache(PM_DB *db); pmlist_t *alpm_db_getpkgcache(pmdb_t *db);
PM_LIST *alpm_db_search(PM_DB *db); pmlist_t *alpm_db_whatprovides(pmdb_t *db, char *name);
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 * Packages
*/ */
/* Info parameters */ /* 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 */ /* reasons -- ie, why the package was installed */
#define PM_PKG_REASON_EXPLICIT 0 /* explicitly requested by the user */ #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_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 */ #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, pmpkg_t **pkg);
int alpm_pkg_load(char *filename, PM_PKG **pkg); int alpm_pkg_free(pmpkg_t *pkg);
int alpm_pkg_free(PM_PKG *pkg); int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
int alpm_pkg_checkmd5sum(PM_PKG *pkg); int alpm_pkg_checksha1sum(pmpkg_t *pkg);
int alpm_pkg_checksha1sum(PM_PKG *pkg);
char *alpm_fetch_pkgurl(char *url); char *alpm_fetch_pkgurl(char *url);
int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section); 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); int alpm_pkg_vercmp(const char *ver1, const char *ver2);
char *alpm_pkg_name_hasarch(char *pkgname); 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 * Groups
*/ */
const char *alpm_grp_get_name(pmgrp_t *grp);
/* Info parameters */ pmlist_t *alpm_grp_get_packages(pmgrp_t *grp);
enum {
PM_GRP_NAME = 1,
PM_GRP_PKGNAMES
};
void *alpm_grp_getinfo(PM_GRP *grp, unsigned char parm);
/* /*
* Sync * Sync
@ -229,14 +242,10 @@ enum {
PM_SYNC_TYPE_UPGRADE, PM_SYNC_TYPE_UPGRADE,
PM_SYNC_TYPE_DEPEND 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 * 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_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_sysupgrade(void);
int alpm_trans_addtarget(char *target); int alpm_trans_addtarget(char *target);
int alpm_trans_prepare(PM_LIST **data); int alpm_trans_prepare(pmlist_t **data);
int alpm_trans_commit(PM_LIST **data); int alpm_trans_commit(pmlist_t **data);
int alpm_trans_release(void); int alpm_trans_release(void);
/* /*
@ -362,7 +371,7 @@ enum {
PM_DEP_VERSION 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 * File conflicts
@ -380,19 +389,19 @@ enum {
PM_CONFLICT_CTARGET PM_CONFLICT_CTARGET
}; };
void *alpm_conflict_getinfo(PM_CONFLICT *conflict, unsigned char parm); void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm);
/* /*
* Helpers * Helpers
*/ */
/* PM_LIST */ /* pmlist_t */
PM_LIST *alpm_list_first(PM_LIST *list); pmlist_t *alpm_list_first(pmlist_t *list);
PM_LIST *alpm_list_next(PM_LIST *entry); pmlist_t *alpm_list_next(pmlist_t *entry);
void *alpm_list_getdata(PM_LIST *entry); void *alpm_list_getdata(const pmlist_t *entry);
int alpm_list_free(PM_LIST *entry); int alpm_list_free(pmlist_t *entry);
int alpm_list_free_outer(PM_LIST *entry); int alpm_list_free_outer(pmlist_t *entry);
int alpm_list_count(PM_LIST *list); int alpm_list_count(const pmlist_t *list);
/* md5sums */ /* md5sums */
char *alpm_get_md5sum(char *name); char *alpm_get_md5sum(char *name);
@ -401,7 +410,6 @@ char *alpm_get_sha1sum(char *name);
/* /*
* Errors * Errors
*/ */
extern enum __pmerrno_t { extern enum __pmerrno_t {
PM_ERR_MEMORY = 1, PM_ERR_MEMORY = 1,
PM_ERR_SYSTEM, PM_ERR_SYSTEM,

View file

@ -43,6 +43,7 @@
#include "alpm.h" #include "alpm.h"
#include "error.h" #include "error.h"
#include "handle.h" #include "handle.h"
#include "package.h"
/* This function is used to convert the downloaded db file to the proper backend /* 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); _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); snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
if(stat(path, &buf)) { if(stat(path, &buf)) {
/* directory doesn't exist or can't be opened */ /* 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 */ /* INSTALL */
if(inforeq & INFRQ_SCRIPLET) { if(inforeq & INFRQ_SCRIPTLET) {
snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version); snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
if(!stat(path, &buf)) { if(!stat(path, &buf)) {
info->scriptlet = 1; info->scriptlet = 1;

View file

@ -21,10 +21,10 @@
#ifndef _ALPM_CACHE_H #ifndef _ALPM_CACHE_H
#define _ALPM_CACHE_H #define _ALPM_CACHE_H
#include "list.h"
#include "package.h"
#include "group.h"
#include "db.h" #include "db.h"
#include "list.h"
#include "group.h"
#include "package.h"
/* packages */ /* packages */
int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel); int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel);

View file

@ -35,6 +35,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <libintl.h> #include <libintl.h>
/* pacman */ /* pacman */
#include "list.h"
#include "trans.h"
#include "util.h" #include "util.h"
#include "error.h" #include "error.h"
#include "log.h" #include "log.h"

View file

@ -22,15 +22,16 @@
#define _ALPM_CONFLICT_H #define _ALPM_CONFLICT_H
#include "db.h" #include "db.h"
#include "alpm.h"
#define CONFLICT_FILE_LEN 512 #define CONFLICT_FILE_LEN 512
typedef struct __pmconflict_t { struct __pmconflict_t {
char target[PKG_NAME_LEN]; char target[PKG_NAME_LEN];
unsigned char type; unsigned char type;
char file[CONFLICT_FILE_LEN]; char file[CONFLICT_FILE_LEN];
char ctarget[PKG_NAME_LEN]; char ctarget[PKG_NAME_LEN];
} pmconflict_t; };
pmlist_t *_alpm_checkconflicts(pmdb_t *db, pmlist_t *packages); 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); pmlist_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root, pmlist_t **skip_list);

View file

@ -223,4 +223,29 @@ pmdb_t *_alpm_db_register(char *treename, alpm_cb_db_register callback)
return(db); 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: */ /* vim: set noet: */

View file

@ -23,36 +23,31 @@
#ifndef _ALPM_DB_H #ifndef _ALPM_DB_H
#define _ALPM_DB_H #define _ALPM_DB_H
#include <limits.h>
#include "package.h"
#include "alpm.h" #include "alpm.h"
#include <limits.h>
/* Database entries */ /* Database entries */
#define INFRQ_NONE 0x00 #define INFRQ_NONE 0x00
#define INFRQ_DESC 0x01 #define INFRQ_DESC 0x01
#define INFRQ_DEPENDS 0x02 #define INFRQ_DEPENDS 0x02
#define INFRQ_FILES 0x04 #define INFRQ_FILES 0x04
#define INFRQ_SCRIPLET 0x08 #define INFRQ_SCRIPTLET 0x08
#define INFRQ_ALL 0xFF #define INFRQ_ALL 0xFF
#define DB_O_CREATE 0x01
/* Database */ /* Database */
typedef struct __pmdb_t { struct __pmdb_t {
char *path; char *path;
char treename[PATH_MAX]; char treename[PATH_MAX];
void *handle; void *handle;
pmlist_t *pkgcache; pmlist_t *pkgcache;
pmlist_t *grpcache; pmlist_t *grpcache;
pmlist_t *servers; pmlist_t *servers;
} pmdb_t; };
pmdb_t *_alpm_db_new(char *root, char *dbpath, char *treename); pmdb_t *_alpm_db_new(char *root, char *dbpath, char *treename);
void _alpm_db_free(void *data); void _alpm_db_free(void *data);
int _alpm_db_cmp(const void *db1, const void *db2); int _alpm_db_cmp(const void *db1, const void *db2);
pmlist_t *_alpm_db_search(pmdb_t *db, pmlist_t *needles); 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_install(pmdb_t *db, const char *dbfile);
int _alpm_db_open(pmdb_t *db); int _alpm_db_open(pmdb_t *db);
void _alpm_db_close(pmdb_t *db); void _alpm_db_close(pmdb_t *db);

View file

@ -25,18 +25,21 @@
#include "db.h" #include "db.h"
#include "sync.h" #include "sync.h"
#include "alpm.h"
typedef struct __pmdepend_t { /* Dependency */
struct __pmdepend_t {
unsigned char mod; unsigned char mod;
char name[PKG_NAME_LEN]; char name[PKG_NAME_LEN];
char version[PKG_VERSION_LEN]; char version[PKG_VERSION_LEN];
} pmdepend_t; };
typedef struct __pmdepmissing_t { /* Missing dependency */
struct __pmdepmissing_t {
char target[PKG_NAME_LEN]; char target[PKG_NAME_LEN];
unsigned char type; unsigned char type;
pmdepend_t depend; pmdepend_t depend;
} pmdepmissing_t; };
pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod, pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod,
const char *depname, const char *depversion); const char *depname, const char *depversion);

View file

@ -29,6 +29,7 @@
#include "error.h" #include "error.h"
#include "log.h" #include "log.h"
#include "group.h" #include "group.h"
#include "list.h"
#include "alpm.h" #include "alpm.h"
pmgrp_t *_alpm_grp_new() 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)); 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: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -21,18 +21,17 @@
#ifndef _ALPM_GROUP_H #ifndef _ALPM_GROUP_H
#define _ALPM_GROUP_H #define _ALPM_GROUP_H
#include "list.h" /* Groups */
#define GRP_NAME_LEN 256 #define GRP_NAME_LEN 256
/* Groups structure */ #include "alpm.h"
typedef struct __pmgrp_t {
struct __pmgrp_t {
char name[GRP_NAME_LEN]; char name[GRP_NAME_LEN];
pmlist_t *packages; /* List of strings */ pmlist_t *packages; /* List of strings */
} pmgrp_t; };
#define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0) #define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0)
#define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free) #define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free)
pmgrp_t *_alpm_grp_new(void); pmgrp_t *_alpm_grp_new(void);

View file

@ -31,7 +31,6 @@
#include <syslog.h> #include <syslog.h>
#include <libintl.h> #include <libintl.h>
#include <time.h> #include <time.h>
/////#include <ftplib.h>
/* pacman */ /* pacman */
#include "util.h" #include "util.h"
#include "log.h" #include "log.h"
@ -105,7 +104,6 @@ int _alpm_handle_free(pmhandle_t *handle)
FREE(handle->dbpath); FREE(handle->dbpath);
FREE(handle->cachedir); FREE(handle->cachedir);
FREE(handle->logfile); FREE(handle->logfile);
FREE(handle->proxyhost);
FREE(handle->xfercommand); FREE(handle->xfercommand);
FREELIST(handle->dbs_sync); FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade); FREELIST(handle->noupgrade);
@ -118,242 +116,130 @@ int _alpm_handle_free(pmhandle_t *handle)
return(0); 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; }
/* Sanity checks */ unsigned char alpm_option_get_logmask() { return handle->logmask; }
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); 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; }
char *p; pmdb_t *alpm_option_get_localdb(pmhandle_t *handle) { return handle->db_local; }
switch(val) { pmlist_t *alpm_option_get_syncdbs(pmhandle_t *handle) { return handle->dbs_sync; }
case PM_OPT_DBPATH:
if(handle->dbpath) { void alpm_option_set_logcb(alpm_cb_log cb) { handle->logcb = cb; }
FREE(handle->dbpath);
} void alpm_option_set_dlcb(alpm_cb_download cb) { handle->dlcb = cb; }
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); void alpm_option_set_logmask(unsigned char mask) { handle->logmask = mask; }
break;
case PM_OPT_CACHEDIR: void alpm_option_set_root(const char *root)
if(handle->cachedir) { {
FREE(handle->cachedir); if(handle->root) FREE(handle->root);
} if(root) handle->root = strdup(root);
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; void alpm_option_set_dbpath(const char *dbpath)
case PM_OPT_LOGFILE: {
if((char *)data == NULL || handle->uid != 0) { if(handle->dbpath) FREE(handle->dbpath);
return(0); 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) { if(handle->logfile) {
FREE(handle->logfile); FREE(handle->logfile);
}
if(handle->logfd) { if(handle->logfd) {
if(fclose(handle->logfd) != 0) { fclose(handle->logfd);
handle->logfd = NULL;
RET_ERR(PM_ERR_OPT_LOGFILE, -1);
}
handle->logfd = NULL; 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); if(logfile) {
_alpm_log(PM_LOG_FLOW2, _("PM_OPT_LOGFILE set to '%s'"), (char *)data); handle->logfile = strdup(logfile);
break; handle->logfd = fopen(logfile, "a");
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);
}
return(0);
} }
int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data) void alpm_option_set_usesyslog(unsigned char usesyslog) { handle->usesyslog = usesyslog; }
void alpm_option_add_noupgrade(char *pkg)
{ {
/* Sanity checks */ handle->noupgrade = _alpm_list_add(handle->noupgrade, strdup(pkg));
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); }
void alpm_option_set_noupgrades(pmlist_t *noupgrade)
switch(val) { {
case PM_OPT_ROOT: *data = (long)handle->root; break; if(handle->noupgrade) FREELIST(handle->noupgrade);
case PM_OPT_DBPATH: *data = (long)handle->dbpath; break; if(noupgrade) handle->noupgrade = noupgrade;
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;
}
return(0);
} }
/* vim: set ts=2 sw=2 noet: */ void alpm_option_add_noextract(char *pkg)
{
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;
}
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;
}
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 et: */

View file

@ -21,17 +21,19 @@
#ifndef _ALPM_HANDLE_H #ifndef _ALPM_HANDLE_H
#define _ALPM_HANDLE_H #define _ALPM_HANDLE_H
#include "list.h"
#include "db.h" #include "db.h"
#include "trans.h" #include "log.h"
#include "list.h"
#include "alpm.h" #include "alpm.h"
#include "trans.h"
typedef enum __pmaccess_t { typedef enum _pmaccess_t {
PM_ACCESS_RO, PM_ACCESS_RO,
PM_ACCESS_RW PM_ACCESS_RW
} pmaccess_t; } pmaccess_t;
typedef struct __pmhandle_t { typedef struct _pmhandle_t {
/* Internal */
pmaccess_t access; pmaccess_t access;
uid_t uid; uid_t uid;
pmdb_t *db_local; pmdb_t *db_local;
@ -39,24 +41,29 @@ typedef struct __pmhandle_t {
FILE *logfd; FILE *logfd;
int lckfd; int lckfd;
pmtrans_t *trans; pmtrans_t *trans;
/* parameters */
char *root; /* options */
char *dbpath; alpm_cb_log logcb; /* Log callback function */
char *cachedir; alpm_cb_download dlcb; /* Download callback function */
char *logfile; unsigned char logmask; /* Output mask for logging functions */
pmlist_t *noupgrade; /* List of strings */ char *root; /* Root path, default '/' */
pmlist_t *noextract; /* List of strings */ char *dbpath; /* Base path to pacman's DBs */
pmlist_t *ignorepkg; /* List of strings */ char *cachedir; /* Base path to pacman's cache */
pmlist_t *holdpkg; /* List of strings */ char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
unsigned char usesyslog; unsigned char usesyslog; /* Use syslog instead of logfile? */
time_t upgradedelay;
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 */ /* servers */
char *proxyhost; char *xfercommand; /* External download command */
unsigned short proxyport; unsigned short nopassiveftp; /* Don't use PASV ftp connections */
char *xfercommand; unsigned short chomp; /* I Love Candy! */
unsigned short nopassiveftp; pmlist_t *needles; /* needles for searching */ /* TODO why is this here? */
unsigned short chomp; /* if eye-candy features should be enabled or not */ unsigned short use_color; /* enable colorful output */
pmlist_t *needles; /* for searching */
} pmhandle_t; } pmhandle_t;
extern pmhandle_t *handle; extern pmhandle_t *handle;
@ -65,8 +72,6 @@ extern pmhandle_t *handle;
pmhandle_t *_alpm_handle_new(void); pmhandle_t *_alpm_handle_new(void);
int _alpm_handle_free(pmhandle_t *handle); 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 */ #endif /* _ALPM_HANDLE_H */

View file

@ -187,10 +187,10 @@ pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, v
return(haystack); return(haystack);
} }
int _alpm_list_count(pmlist_t *list) int _alpm_list_count(const pmlist_t *list)
{ {
int i; int i;
pmlist_t *lp; const pmlist_t *lp;
for(lp = list, i = 0; lp; lp = lp->next, i++); for(lp = list, i = 0; lp; lp = lp->next, i++);

View file

@ -21,13 +21,15 @@
#ifndef _ALPM_LIST_H #ifndef _ALPM_LIST_H
#define _ALPM_LIST_H #define _ALPM_LIST_H
#include "alpm.h"
/* Chained list struct */ /* Chained list struct */
typedef struct __pmlist_t { struct __pmlist_t {
void *data; void *data;
struct __pmlist_t *prev; struct __pmlist_t *prev;
struct __pmlist_t *next; struct __pmlist_t *next;
struct __pmlist_t *last; /* Quick access to last item in list */ 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, f) do { if(p) { _alpm_list_free(p, f); p = NULL; } } while(0)
#define FREELIST(p) _FREELIST(p, free) #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(pmlist_t *list, void *data);
pmlist_t *_alpm_list_add_sorted(pmlist_t *list, void *data, _alpm_fn_cmp fn); 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); 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_in(void *needle, pmlist_t *haystack);
int _alpm_list_is_strin(char *needle, pmlist_t *haystack); int _alpm_list_is_strin(char *needle, pmlist_t *haystack);
pmlist_t *_alpm_list_last(pmlist_t *list); pmlist_t *_alpm_list_last(pmlist_t *list);

View file

@ -27,17 +27,14 @@
#include "alpm.h" #include "alpm.h"
#include "log.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, ...) void _alpm_log(unsigned char flag, char *fmt, ...)
{ {
if(pm_logcb == NULL) { alpm_cb_log logcb = alpm_option_get_logcb();
if(logcb == NULL) {
return; return;
} }
if(flag & pm_logmask) { if(flag & alpm_option_get_logmask()) {
char str[LOG_STR_LEN]; char str[LOG_STR_LEN];
va_list args; va_list args;
@ -45,7 +42,7 @@ void _alpm_log(unsigned char flag, char *fmt, ...)
vsnprintf(str, LOG_STR_LEN, fmt, args); vsnprintf(str, LOG_STR_LEN, fmt, args);
va_end(args); va_end(args);
pm_logcb(flag, str); logcb(flag, str);
} }
} }

View file

@ -21,12 +21,7 @@
#ifndef _ALPM_LOG_H #ifndef _ALPM_LOG_H
#define _ALPM_LOG_H #define _ALPM_LOG_H
#define LOG_STR_LEN 256 #define LOG_STR_LEN 1024
typedef void (*alpm_cb_log)(unsigned short, char *);
extern alpm_cb_log pm_logcb;
extern unsigned char pm_logmask;
void _alpm_log(unsigned char flag, char *fmt, ...); void _alpm_log(unsigned char flag, char *fmt, ...);

View file

@ -36,6 +36,8 @@
#include "error.h" #include "error.h"
#include "list.h" #include "list.h"
#include "package.h" #include "package.h"
#include "db.h"
#include "handle.h"
#include "alpm.h" #include "alpm.h"
pmpkg_t *_alpm_pkg_new(const char *name, const char *version) 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")) { } else if(!strcmp(key, "SIZE")) {
char tmp[32]; char tmp[32];
STRNCPY(tmp, ptr, sizeof(tmp)); STRNCPY(tmp, ptr, sizeof(tmp));
info->size = atol(tmp); info->size = atol(ptr);
} else if(!strcmp(key, "USIZE")) { } else if(!strcmp(key, "USIZE")) {
char tmp[32]; char tmp[32];
STRNCPY(tmp, ptr, sizeof(tmp)); STRNCPY(tmp, ptr, sizeof(tmp));
info->usize = atol(tmp); info->usize = atol(ptr);
} else if(!strcmp(key, "DEPEND")) { } else if(!strcmp(key, "DEPEND")) {
info->depends = _alpm_list_add(info->depends, strdup(ptr)); info->depends = _alpm_list_add(info->depends, strdup(ptr));
} else if(!strcmp(key, "REMOVE")) { } else if(!strcmp(key, "REMOVE")) {
@ -509,4 +511,302 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
return(0); 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: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -28,13 +28,15 @@
#if defined(__APPLE__) || defined(__sun__) #if defined(__APPLE__) || defined(__sun__)
#include <time.h> #include <time.h>
#endif #endif
#include "list.h"
#include "alpm.h"
enum { enum {
PKG_FROM_CACHE = 1, PKG_FROM_CACHE = 1,
PKG_FROM_FILE PKG_FROM_FILE
}; };
/* Packages */
#define PKG_NAME_LEN 256 #define PKG_NAME_LEN 256
#define PKG_VERSION_LEN 64 #define PKG_VERSION_LEN 64
#define PKG_FULLNAME_LEN (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1 #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_SHA1SUM_LEN 41
#define PKG_ARCH_LEN 32 #define PKG_ARCH_LEN 32
typedef struct __pmpkg_t { struct __pmpkg_t {
char name[PKG_NAME_LEN]; char name[PKG_NAME_LEN];
char version[PKG_VERSION_LEN]; char version[PKG_VERSION_LEN];
char desc[PKG_DESC_LEN]; char desc[PKG_DESC_LEN];
@ -80,16 +82,9 @@ typedef struct __pmpkg_t {
unsigned char origin; unsigned char origin;
void *data; void *data;
unsigned char infolevel; 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) #define FREELISTPKGS(p) _FREELIST(p, _alpm_pkg_free)
pmpkg_t* _alpm_pkg_new(const char *name, const char *version); 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); char *_alpm_pkg_makefilename(pmpkg_t *pkg);
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch); int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
#endif /* _ALPM_PACKAGE_H */ #endif /* _ALPM_PACKAGE_H */
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -21,10 +21,9 @@
#ifndef _ALPM_PROVIDE_H #ifndef _ALPM_PROVIDE_H
#define _ALPM_PROVIDE_H #define _ALPM_PROVIDE_H
#include "config.h"
#include "list.h"
#include "db.h" #include "db.h"
#include "list.h"
#include "config.h"
pmlist_t *_alpm_db_whatprovides(pmdb_t *db, char *package); pmlist_t *_alpm_db_whatprovides(pmdb_t *db, char *package);

View file

@ -21,8 +21,8 @@
#ifndef _ALPM_REMOVE_H #ifndef _ALPM_REMOVE_H
#define _ALPM_REMOVE_H #define _ALPM_REMOVE_H
#include "list.h"
#include "db.h" #include "db.h"
#include "list.h"
#include "trans.h" #include "trans.h"
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name); int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);

View file

@ -38,8 +38,6 @@
#include "handle.h" #include "handle.h"
#include "log.h" #include "log.h"
download_progress_cb pm_dlcb = NULL;
pmserver_t *_alpm_server_new(const char *url) pmserver_t *_alpm_server_new(const char *url)
{ {
struct url *u; struct url *u;
@ -172,10 +170,10 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
downloadTimeout = 10000; downloadTimeout = 10000;
/* Make libdownload super verbose... worthwhile for testing */ /* Make libdownload super verbose... worthwhile for testing */
if(pm_logmask & PM_LOG_DOWNLOAD) { if(alpm_option_get_logmask() & PM_LOG_DOWNLOAD) {
downloadDebug = 1; 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")); dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp"));
} else { } else {
dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p")); 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 */ /* Progress 0 - initialize */
if(pm_dlcb) pm_dlcb(fn, 0, ust.size); if(handle->dlcb) handle->dlcb(fn, 0, ust.size);
int nread = 0; int nread = 0;
char buffer[PM_DLBUF_LEN]; 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) ; while((nwritten += fwrite(buffer, 1, (nread - nwritten), localf)) < nread) ;
dltotal_bytes += 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); fclose(localf);

View file

@ -22,30 +22,22 @@
#define _ALPM_SERVER_H #define _ALPM_SERVER_H
#include "list.h" #include "list.h"
#include <time.h> #include "alpm.h"
#include <time.h>
#include <download.h> #include <download.h>
#define FREESERVER(p) \ #define FREESERVER(p) do { if(p){_alpm_server_free(p); p = NULL;}} while(0)
do { \
if(p) { \
_alpm_server_free(p); \
p = NULL; \
} \
} while(0)
#define FREELISTSERVERS(p) _FREELIST(p, _alpm_server_free) #define FREELISTSERVERS(p) _FREELIST(p, _alpm_server_free)
/* Servers */ /* Servers */
typedef struct __pmserver_t { struct __pmserver_t {
char *path; char *path;
struct url *s_url; struct url *s_url;
} pmserver_t; };
#define PM_DLBUF_LEN (1024 * 10) #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); pmserver_t *_alpm_server_new(const char *url);
void _alpm_server_free(void *data); void _alpm_server_free(void *data);
int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *files); 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); char *_alpm_fetch_pkgurl(char *target);
extern download_progress_cb pm_dlcb;
#endif /* _ALPM_SERVER_H */ #endif /* _ALPM_SERVER_H */
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -790,7 +790,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
fname = _alpm_pkg_makefilename(spkg); fname = _alpm_pkg_makefilename(spkg);
if(trans->flags & PM_TRANS_FLAG_PRINTURIS) { 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 { } else {
struct stat buf; struct stat buf;
snprintf(path, PATH_MAX, "%s/%s", ldir, fname); 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_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
alpm_logaction(_("warning: couldn't create package cache, using /tmp instead")); alpm_logaction(_("warning: couldn't create package cache, using /tmp instead"));
snprintf(ldir, PATH_MAX, "%s/tmp", handle->root); snprintf(ldir, PATH_MAX, "%stmp", alpm_option_get_root());
if(_alpm_handle_set_option(handle, PM_OPT_CACHEDIR, (long)"/tmp") == -1) { alpm_option_set_cachedir(ldir);
_alpm_log(PM_LOG_WARNING, _("failed to set option CACHEDIR (%s)\n"), alpm_strerror(pm_errno));
RET_ERR(PM_ERR_RETRIEVE, -1);
}
varcache = 0; varcache = 0;
} }
} }
@ -1054,4 +1051,28 @@ error:
return(-1); 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: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -23,15 +23,14 @@
#ifndef _ALPM_SYNC_H #ifndef _ALPM_SYNC_H
#define _ALPM_SYNC_H #define _ALPM_SYNC_H
#include "db.h" #include "alpm.h"
#include "package.h"
#include "trans.h"
typedef struct __pmsyncpkg_t { /* Sync package */
struct __pmsyncpkg_t {
unsigned char type; unsigned char type;
pmpkg_t *pkg; pmpkg_t *pkg;
void *data; void *data;
} pmsyncpkg_t; };
#define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0) #define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0)

View file

@ -24,19 +24,10 @@
#ifndef _ALPM_TRANS_H #ifndef _ALPM_TRANS_H
#define _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" #include "alpm.h"
typedef struct __pmtrans_t { /* Transaction */
struct __pmtrans_t {
unsigned char type; unsigned char type;
unsigned int flags; unsigned int flags;
unsigned char state; unsigned char state;
@ -46,7 +37,17 @@ typedef struct __pmtrans_t {
alpm_trans_cb_event cb_event; alpm_trans_cb_event cb_event;
alpm_trans_cb_conv cb_conv; alpm_trans_cb_conv cb_conv;
alpm_trans_cb_progress cb_progress; 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) \ #define FREETRANS(p) \
do { \ do { \

View file

@ -63,6 +63,7 @@
#include "sync.h" #include "sync.h"
#include "util.h" #include "util.h"
#include "error.h" #include "error.h"
#include "package.h"
#include "alpm.h" #include "alpm.h"
#ifdef __sun__ #ifdef __sun__

237
scripts/repo-add Executable file
View file

@ -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

View file

@ -5,8 +5,7 @@ SUBDIRS = po
localedir = $(datadir)/locale localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
AM_CFLAGS = $(CFLAGS) -D_GNU_SOURCE \ AM_CFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/lib/libalpm $(CFLAGS)
-I$(top_srcdir)/lib/libalpm
pacman_SOURCES = util.c log.c list.c package.c downloadprog.c trans.c add.c \ 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 remove.c upgrade.c query.c sync.c conf.c deptest.c pacman.c

View file

@ -38,7 +38,7 @@ extern config_t *config;
int pacman_add(list_t *targets) int pacman_add(list_t *targets)
{ {
PM_LIST *data; pmlist_t *data;
list_t *i; list_t *i;
int retval = 0; int retval = 0;
@ -87,13 +87,13 @@ int pacman_add(list_t *targets)
*/ */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
long long *pkgsize, *freespace; long long *pkgsize, *freespace;
PM_LIST *i; pmlist_t *i;
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno)); ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { 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), MSG(NL, _(":: %s: requires %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
alpm_dep_getinfo(miss, PM_DEP_NAME)); alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) { switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
@ -107,7 +107,7 @@ int pacman_add(list_t *targets)
break; break;
case PM_ERR_CONFLICTING_DEPS: case PM_ERR_CONFLICTING_DEPS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { 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"), MSG(NL, _(":: %s: conflicts with %s"),
alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); 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; break;
case PM_ERR_FILE_CONFLICTS: case PM_ERR_FILE_CONFLICTS:
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { 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)) { switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
case PM_CONFLICT_TYPE_TARGET: case PM_CONFLICT_TYPE_TARGET:
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),

View file

@ -53,7 +53,6 @@ int config_free(config_t *config)
return(-1); return(-1);
} }
FREE(config->root);
FREE(config->configfile); FREE(config->configfile);
FREELIST(config->op_s_ignore); FREELIST(config->op_s_ignore);
free(config); free(config);
@ -61,7 +60,7 @@ int config_free(config_t *config)
return(0); return(0);
} }
void cb_db_register(char *section, PM_DB *db) void cb_db_register(char *section, pmdb_t *db)
{ {
sync_t *sync; sync_t *sync;

View file

@ -23,9 +23,9 @@
typedef struct __config_t { typedef struct __config_t {
/* command line options */ /* command line options */
char *root; const char *root;
char *dbpath; const char *dbpath;
char *cachedir; const char *cachedir;
char *configfile; char *configfile;
unsigned short op; unsigned short op;
unsigned short verbose; unsigned short verbose;
@ -63,7 +63,7 @@ typedef struct __config_t {
config_t *config_new(void); config_t *config_new(void);
int config_free(config_t *config); 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 */ #endif /* _PM_CONF_H */

View file

@ -38,7 +38,7 @@ extern config_t *config;
int pacman_deptest(list_t *targets) int pacman_deptest(list_t *targets)
{ {
PM_LIST *data; pmlist_t *data;
list_t *i; list_t *i;
char *str; char *str;
int retval = 0; int retval = 0;
@ -94,7 +94,7 @@ int pacman_deptest(list_t *targets)
FREE(str); FREE(str);
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
PM_LIST *lp; pmlist_t *lp;
list_t *synctargs = NULL; list_t *synctargs = NULL;
retval = 126; retval = 126;
/* return 126 = deps were missing, but successfully resolved /* return 126 = deps were missing, but successfully resolved
@ -105,7 +105,7 @@ int pacman_deptest(list_t *targets)
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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) { if(!config->op_d_resolve) {
MSG(NL, _("requires: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME)); MSG(NL, _("requires: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) { switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
@ -122,7 +122,7 @@ int pacman_deptest(list_t *targets)
case PM_ERR_CONFLICTING_DEPS: case PM_ERR_CONFLICTING_DEPS:
/* we can't auto-resolve conflicts */ /* we can't auto-resolve conflicts */
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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)); MSG(NL, _("conflict: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME));
} }
retval = 127; retval = 127;

View file

@ -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. ;) */ /* 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); gettimeofday(&current_time, NULL);
total_timediff = current_time.tv_sec-initial_time.tv_sec total_timediff = current_time.tv_sec-initial_time.tv_sec

View file

@ -101,7 +101,7 @@ static list_t *list_last(list_t *list)
/* Test for existence of a string in a list_t /* 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; 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; int cols, len;
len = strlen(title); 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 * Not the most efficient way, but simple to implement -- we assemble
* a new list, using is_in() to check for dupes at each iteration. * 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; list_t *newlist = NULL;
for(i = alpm_list_first(list); i; i = alpm_list_next(i)) { for(i = alpm_list_first(list); i; i = alpm_list_next(i)) {

View file

@ -18,8 +18,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA. * USA.
*/ */
#ifndef _PM_LIST_H #ifndef _LIST_H
#define _PM_LIST_H #define _LIST_H
#include <alpm.h> #include <alpm.h>
@ -42,12 +42,12 @@ list_t *list_new(void);
void list_free(list_t *list); void list_free(list_t *list);
list_t *list_add(list_t *list, void *data); list_t *list_add(list_t *list, void *data);
int list_count(list_t *list); 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 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);
list_t *PM_LIST_remove_dupes(PM_LIST *list); list_t *pmlist_remove_dupes(pmlist_t *list);
#endif /* _PM_LIST_H */ #endif /*_LIST_H*/
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -35,36 +35,36 @@
/* Display the content of an installed package /* 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) { if(pkg == NULL) {
return; return;
} }
printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME)); printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); 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(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg));
printf("URL : %s\n", (char *)alpm_pkg_getinfo(pkg, PM_PKG_URL)); printf("URL : %s\n", (char *)alpm_pkg_get_url(pkg));
PM_LIST_display(_("License :"), alpm_pkg_getinfo(pkg, PM_PKG_LICENSE)); pmlist_display(_("License :"), alpm_pkg_get_licenses(pkg));
printf(_("Architecture : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_ARCH)); printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg));
printf(_("Size : %ld\n"), (long int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE)); 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" : ""); 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")); 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 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 : ")); printf(_("Reason : "));
switch((long)alpm_pkg_getinfo(pkg, PM_PKG_REASON)) { switch((long)alpm_pkg_get_reason(pkg)) {
case PM_PKG_REASON_EXPLICIT: case PM_PKG_REASON_EXPLICIT:
printf(_("Explicitly installed\n")); printf(_("Explicitly installed\n"));
break; break;
@ -76,24 +76,21 @@ void dump_pkg_full(PM_PKG *pkg, int level)
break; break;
} }
PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES)); pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS)); pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES)); pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg));
PM_LIST_display(_("Required By :"), alpm_pkg_getinfo(pkg, PM_PKG_REQUIREDBY)); pmlist_display(_("Required By :"), alpm_pkg_get_requiredby(pkg));
PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
printf(_("Description : ")); printf(_("Description : "));
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 17); indentprint(alpm_pkg_get_desc(pkg), 17);
printf("\n"); printf("\n");
if(level > 1) { if(level > 1) {
PM_LIST *i; pmlist_t *i;
long lroot; const char *root = alpm_option_get_root();
char *root;
alpm_get_option(PM_OPT_ROOT, &lroot);
root = (void *)lroot;
fprintf(stdout, "\n"); 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; struct stat buf;
char path[PATH_MAX]; char path[PATH_MAX];
char *str = strdup(alpm_list_getdata(i)); 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 /* 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) { if(pkg == NULL) {
return; return;
} }
printf(_("Repository : %s\n"), treename); printf(_("Repository : %s\n"), treename);
printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME)); printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); 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));
PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES)); pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS)); pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES)); pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg));
PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
PM_LIST_display(_("Replaces :"), alpm_pkg_getinfo(pkg, PM_PKG_REPLACES)); pmlist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE)); printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_get_size(pkg));
printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE)); printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_get_usize(pkg));
printf(_("Description : ")); printf(_("Description : "));
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 20); indentprint(alpm_pkg_get_desc(pkg), 20);
tmp1 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM);
if (tmp1 != NULL && tmp1[0] != '\0') { sum = (char *)alpm_pkg_get_md5sum(pkg);
printf(_("\nMD5 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM)); if (sum != NULL && sum[0] != '\0') {
printf(_("\nMD5 Sum : %s"), sum);
} }
tmp2 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM); sum = (char *)alpm_pkg_get_sha1sum(pkg);
if (tmp2 != NULL && tmp2[0] != '\0') { if (sum != NULL && sum[0] != '\0') {
printf(_("\nSHA1 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM)); printf(_("\nSHA1 Sum : %s"), sum);
} }
printf("\n"); printf("\n");
} }
void dump_pkg_files(PM_PKG *pkg) void dump_pkg_files(pmpkg_t *pkg)
{ {
char *pkgname; const char *pkgname;
PM_LIST *i, *pkgfiles; pmlist_t *i, *pkgfiles;
pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME); pkgname = alpm_pkg_get_name(pkg);
pkgfiles = alpm_pkg_getinfo(pkg, PM_PKG_FILES); pkgfiles = alpm_pkg_get_files(pkg);
for(i = pkgfiles; i; i = alpm_list_next(i)) { for(i = pkgfiles; i; i = alpm_list_next(i)) {
fprintf(stdout, "%s %s\n", (char *)pkgname, (char *)alpm_list_getdata(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 /* 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; FILE* fp = NULL;
char line[PATH_MAX+1]; char line[PATH_MAX+1];

View file

@ -21,11 +21,11 @@
#ifndef _PM_PACKAGE_H #ifndef _PM_PACKAGE_H
#define _PM_PACKAGE_H #define _PM_PACKAGE_H
void dump_pkg_full(PM_PKG *pkg, int level); void dump_pkg_full(pmpkg_t *pkg, int level);
void dump_pkg_sync(PM_PKG *pkg, char *treename); void dump_pkg_sync(pmpkg_t *pkg, char *treename);
void dump_pkg_files(PM_PKG *pkg); void dump_pkg_files(pmpkg_t *pkg);
void dump_pkg_changelog(char *clfile, char *pkgname); void dump_pkg_changelog(char *clfile, const char *pkgname);
int split_pkgname(char *target, char *name, char *version); int split_pkgname(char *target, char *name, char *version);

View file

@ -75,7 +75,7 @@ enum {
config_t *config = NULL; config_t *config = NULL;
PM_DB *db_local; pmdb_t *db_local;
/* list of (sync_t *) structs for sync locations */ /* list of (sync_t *) structs for sync locations */
list_t *pmc_syncs = NULL; list_t *pmc_syncs = NULL;
/* list of targets specified on command line */ /* list of targets specified on command line */
@ -322,10 +322,8 @@ static int parseargs(int argc, char *argv[])
config->op_d_vertest = 1; config->op_d_vertest = 1;
break; break;
case 'b': case 'b':
if(config->dbpath) { alpm_option_set_dbpath(optarg);
FREE(config->dbpath); config->dbpath = alpm_option_get_dbpath(optarg);
}
config->dbpath = strdup(optarg);
break; break;
case 'c': case 'c':
config->op_s_clean++; config->op_s_clean++;
@ -355,10 +353,8 @@ static int parseargs(int argc, char *argv[])
perror(_("bad root path")); perror(_("bad root path"));
return(1); return(1);
} }
if(config->root) { alpm_option_set_root(root);
free(config->root); config->root = alpm_option_get_root();
}
config->root = strdup(root);
break; break;
case 's': case 's':
config->op_s_search = 1; config->op_s_search = 1;
@ -404,7 +400,7 @@ static int parseargs(int argc, char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret = 0; int ret = 0;
char *cenv = NULL, *lang = NULL; char *lang = NULL;
#ifndef CYGWIN #ifndef CYGWIN
uid_t myuid; uid_t myuid;
#endif #endif
@ -414,10 +410,7 @@ int main(int argc, char *argv[])
/*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/ /*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/
mtrace(); mtrace();
#endif #endif
cenv = getenv("COLUMNS"); maxcols = getcols();
if(cenv != NULL) {
maxcols = atoi(cenv);
}
/* set signal handlers */ /* set signal handlers */
signal(SIGINT, cleanup); signal(SIGINT, cleanup);
@ -490,34 +483,33 @@ int main(int argc, char *argv[])
#endif #endif
if(config->root == NULL) { if(config->root == NULL) {
config->root = strdup(PM_ROOT); config->root = PM_ROOT;
} }
char *initroot = NULL;
/* add a trailing '/' if there isn't one */ /* add a trailing '/' if there isn't one */
if(config->root[strlen(config->root)-1] != '/') { if(config->root[strlen(config->root)-1] != '/') {
char *ptr; char *ptr;
MALLOC(ptr, strlen(config->root)+2); MALLOC(ptr, strlen(config->root)+2);
strcpy(ptr, config->root); strcpy(ptr, config->root);
strcat(ptr, "/"); strcat(ptr, "/");
FREE(config->root); initroot = ptr;
config->root = ptr; } else {
initroot = strdup(config->root);
} }
/* initialize pm library */ /* 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)); ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno));
cleanup(1); cleanup(1);
} }
FREE(initroot);
config->root = alpm_option_get_root();
/* Setup logging as soon as possible, to print out maximum debugging info */ /* Setup logging as soon as possible, to print out maximum debugging info */
if(alpm_set_option(PM_OPT_LOGMASK, (long)config->debug) == -1) { alpm_option_set_logmask(config->debug);
ERR(NL, _("failed to set option LOGMASK (%s)\n"), alpm_strerror(pm_errno)); alpm_option_set_logcb(cb_log);
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);
}
if(config->configfile == NULL) { if(config->configfile == NULL) {
config->configfile = strdup(PACCONF); config->configfile = strdup(PACCONF);
@ -528,23 +520,13 @@ int main(int argc, char *argv[])
} }
/* set library parameters */ /* set library parameters */
if(alpm_set_option(PM_OPT_DLCB, (long)log_progress) == -1) { alpm_option_set_dlcb(log_progress);
ERR(NL, _("failed to set option DLCB (%s)\n"), alpm_strerror(pm_errno));
cleanup(1); config->dbpath = alpm_option_get_dbpath();
} config->cachedir = alpm_option_get_cachedir();
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;
for(lp = config->op_s_ignore; lp; lp = lp->next) { for(lp = config->op_s_ignore; lp; lp = lp->next) {
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)lp->data) == -1) { alpm_option_add_ignorepkg(lp->data);
ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno));
cleanup(1);
}
} }
if(config->verbose > 0) { if(config->verbose > 0) {

View file

@ -37,17 +37,16 @@
#include "util.h" #include "util.h"
extern config_t *config; extern config_t *config;
extern PM_DB *db_local; extern pmdb_t *db_local;
extern list_t *pmc_syncs; 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; struct stat buf;
int gotcha = 0; int gotcha = 0;
char rpath[PATH_MAX]; char rpath[PATH_MAX];
PM_LIST *lp; pmlist_t *lp;
long lroot; const char *root;
char *root;
if(db == NULL) { if(db == NULL) {
return(0); return(0);
@ -62,23 +61,22 @@ static int query_fileowner(PM_DB *db, char *filename)
return(1); return(1);
} }
alpm_get_option(PM_OPT_ROOT, &lroot); root = alpm_option_get_root();
root = (char *)lroot;
for(lp = alpm_db_getpkgcache(db); lp && !gotcha; lp = alpm_list_next(lp)) { for(lp = alpm_db_getpkgcache(db); lp && !gotcha; lp = alpm_list_next(lp)) {
PM_PKG *info; pmpkg_t *info;
PM_LIST *i; pmlist_t *i;
info = alpm_list_getdata(lp); 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 path[PATH_MAX];
char *filename = (char *)alpm_list_getdata(i); char *filename = (char *)alpm_list_getdata(i);
snprintf(path, PATH_MAX, "%s%s", root, filename); snprintf(path, PATH_MAX, "%s%s", root, filename);
if(!strcmp(path, rpath)) { if(!strcmp(path, rpath)) {
printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_getinfo(info, PM_PKG_NAME), printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_get_name(info),
(char *)alpm_pkg_getinfo(info, PM_PKG_VERSION)); (char *)alpm_pkg_get_version(info));
gotcha = 1; gotcha = 1;
break; break;
} }
@ -94,29 +92,29 @@ static int query_fileowner(PM_DB *db, char *filename)
int pacman_query(list_t *targets) int pacman_query(list_t *targets)
{ {
PM_PKG *info = NULL; pmpkg_t *info = NULL;
list_t *targ; list_t *targ;
list_t *i; list_t *i;
PM_LIST *j, *ret; pmlist_t *j, *ret;
char *package = NULL; char *package = NULL;
int done = 0; int done = 0;
if(config->op_q_search) { if(config->op_q_search) {
for(i = targets; i; i = i->next) { 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); ret = alpm_db_search(db_local);
if(ret == NULL) { if(ret == NULL) {
return(1); return(1);
} }
for(j = ret; j; j = alpm_list_next(j)) { 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 ", printf("local/%s/%s %s\n ",
(char*)alpm_list_getdata(alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)), (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg)),
(char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), alpm_pkg_get_name(pkg),
(char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); alpm_pkg_get_version(pkg));
indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
printf("\n"); printf("\n");
} }
alpm_list_free_outer(ret); alpm_list_free_outer(ret);
@ -142,24 +140,24 @@ int pacman_query(list_t *targets)
/* looking for groups */ /* looking for groups */
if(config->group) { if(config->group) {
PM_LIST *lp; pmlist_t *lp;
if(targets == NULL) { if(targets == NULL) {
for(lp = alpm_db_getgrpcache(db_local); lp; lp = alpm_list_next(lp)) { for(lp = alpm_db_getgrpcache(db_local); lp; lp = alpm_list_next(lp)) {
PM_GRP *grp = alpm_list_getdata(lp); pmgrp_t *grp = alpm_list_getdata(lp);
PM_LIST *i, *pkgnames; pmlist_t *i, *pkgnames;
char *grpname; const char *grpname;
grpname = alpm_grp_getinfo(grp, PM_GRP_NAME); grpname = alpm_grp_get_name(grp);
pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES); pkgnames = alpm_grp_get_packages(grp);
for(i = pkgnames; i; i = alpm_list_next(i)) { for(i = pkgnames; i; i = alpm_list_next(i)) {
MSG(NL, "%s %s\n", grpname, (char *)alpm_list_getdata(i)); MSG(NL, "%s %s\n", grpname, (char *)alpm_list_getdata(i));
} }
} }
} else { } else {
PM_GRP *grp = alpm_db_readgrp(db_local, package); pmgrp_t *grp = alpm_db_readgrp(db_local, package);
if(grp) { 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)) { for(i = pkgnames; i; i = alpm_list_next(i)) {
MSG(NL, "%s %s\n", package, (char *)alpm_list_getdata(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); dump_pkg_files(info);
} }
if(!config->op_q_info && !config->op_q_list) { if(!config->op_q_info && !config->op_q_list) {
MSG(NL, "%s %s\n", (char *)alpm_pkg_getinfo(info, PM_PKG_NAME), MSG(NL, "%s %s\n", alpm_pkg_get_name(info),
(char *)alpm_pkg_getinfo(info, PM_PKG_VERSION)); alpm_pkg_get_version(info));
} }
FREEPKG(info); FREEPKG(info);
continue; continue;
@ -203,17 +201,17 @@ int pacman_query(list_t *targets)
/* find packages in the db */ /* find packages in the db */
if(package == NULL) { if(package == NULL) {
PM_LIST *lp; pmlist_t *lp;
/* no target */ /* no target */
for(lp = alpm_db_getpkgcache(db_local); lp; lp = alpm_list_next(lp)) { for(lp = alpm_db_getpkgcache(db_local); lp; lp = alpm_list_next(lp)) {
PM_PKG *tmpp = alpm_list_getdata(lp); pmpkg_t *tmpp = alpm_list_getdata(lp);
char *pkgname, *pkgver; const char *pkgname, *pkgver;
pkgname = alpm_pkg_getinfo(tmpp, PM_PKG_NAME); pkgname = alpm_pkg_get_name(tmpp);
pkgver = alpm_pkg_getinfo(tmpp, PM_PKG_VERSION); pkgver = alpm_pkg_get_version(tmpp);
if(config->op_q_list || config->op_q_orphans || config->op_q_foreign) { 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) { if(info == NULL) {
/* something weird happened */ /* something weird happened */
ERR(NL, _("package \"%s\" not found\n"), pkgname); 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) { for(i = pmc_syncs; i; i = i->next) {
sync_t *sync = (sync_t *)i->data; sync_t *sync = (sync_t *)i->data;
for(j = alpm_db_getpkgcache(sync->db); j; j = alpm_list_next(j)) { 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 *haystack;
char *needle; char *needle;
haystack = strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME)); haystack = strdup(alpm_pkg_get_name(pkg));
needle = strdup(alpm_pkg_getinfo(info, PM_PKG_NAME)); needle = strdup(alpm_pkg_get_name(info));
if(!strcmp(haystack, needle)) { if(!strcmp(haystack, needle)) {
match = 1; match = 1;
} }
@ -244,8 +242,8 @@ int pacman_query(list_t *targets)
dump_pkg_files(info); dump_pkg_files(info);
} }
if(config->op_q_orphans) { if(config->op_q_orphans) {
if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL if(alpm_pkg_get_requiredby(info) == NULL
&& (long)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_DEPEND) { && (long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND) {
MSG(NL, "%s %s\n", pkgname, pkgver); MSG(NL, "%s %s\n", pkgname, pkgver);
} }
} }
@ -254,7 +252,8 @@ int pacman_query(list_t *targets)
} }
} }
} else { } 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); info = alpm_db_readpkg(db_local, package);
if(info == NULL) { if(info == NULL) {
@ -265,16 +264,14 @@ int pacman_query(list_t *targets)
/* find a target */ /* find a target */
if(config->op_q_changelog || config->op_q_info || config->op_q_list) { if(config->op_q_changelog || config->op_q_info || config->op_q_list) {
if(config->op_q_changelog) { if(config->op_q_changelog) {
long ldbpath; const char *dbpath;
char *dbpath; dbpath = alpm_option_get_dbpath();
alpm_get_option(PM_OPT_DBPATH, &ldbpath);
dbpath = (char *)ldbpath;
snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog", snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog",
config->root, dbpath, config->root, dbpath,
(char*)alpm_db_getinfo(db_local, PM_DB_TREENAME), alpm_db_get_name(db_local),
(char*)alpm_pkg_getinfo(info, PM_PKG_NAME), alpm_pkg_get_name(info),
(char*)alpm_pkg_getinfo(info, PM_PKG_VERSION)); alpm_pkg_get_version(info));
dump_pkg_changelog(changelog, (char*)alpm_pkg_getinfo(info, PM_PKG_NAME)); dump_pkg_changelog(changelog, alpm_pkg_get_name(info));
} }
if(config->op_q_info) { if(config->op_q_info) {
dump_pkg_full(info, 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); dump_pkg_files(info);
} }
} else if(config->op_q_orphans) { } 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); MSG(NL, "%s %s\n", pkgname, pkgver);
} }
} else { } else {
pkgname = alpm_pkg_getinfo(info, PM_PKG_NAME); pkgname = alpm_pkg_get_name(info);
pkgver = alpm_pkg_getinfo(info, PM_PKG_VERSION); pkgver = alpm_pkg_get_version(info);
MSG(NL, "%s %s\n", pkgname, pkgver); MSG(NL, "%s %s\n", pkgname, pkgver);
} }
} }

View file

@ -35,11 +35,11 @@
extern config_t *config; extern config_t *config;
extern PM_DB *db_local; extern pmdb_t *db_local;
int pacman_remove(list_t *targets) int pacman_remove(list_t *targets)
{ {
PM_LIST *data; pmlist_t *data;
list_t *i; list_t *i;
list_t *finaltargs = NULL; list_t *finaltargs = NULL;
int retval = 0; int retval = 0;
@ -52,17 +52,17 @@ int pacman_remove(list_t *targets)
* (the library can't remove groups for now) * (the library can't remove groups for now)
*/ */
for(i = targets; i; i = i->next) { for(i = targets; i; i = i->next) {
PM_GRP *grp; pmgrp_t *grp;
grp = alpm_db_readgrp(db_local, i->data); grp = alpm_db_readgrp(db_local, i->data);
if(grp) { if(grp) {
PM_LIST *lp, *pkgnames; pmlist_t *lp, *pkgnames;
int all; 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)); MSG(NL, _(":: group %s:\n"), alpm_grp_get_name(grp));
PM_LIST_display(" ", pkgnames); pmlist_display(" ", pkgnames);
all = yesno(_(" Remove whole content? [Y/n] ")); all = yesno(_(" Remove whole content? [Y/n] "));
for(lp = alpm_list_first(pkgnames); lp; lp = alpm_list_next(lp)) { 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)) { 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 /* Step 2: prepare the transaction based on its type, targets and flags
*/ */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
PM_LIST *lp; pmlist_t *lp;
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno)); ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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), MSG(NL, _(" %s: is required by %s\n"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
alpm_dep_getinfo(miss, PM_DEP_NAME)); alpm_dep_getinfo(miss, PM_DEP_NAME));
} }
@ -119,12 +119,12 @@ int pacman_remove(list_t *targets)
/* Warn user in case of dangerous operation /* Warn user in case of dangerous operation
*/ */
if(config->flags & PM_TRANS_FLAG_RECURSE || config->flags & PM_TRANS_FLAG_CASCADE) { if(config->flags & PM_TRANS_FLAG_RECURSE || config->flags & PM_TRANS_FLAG_CASCADE) {
PM_LIST *lp; pmlist_t *lp;
/* list transaction targets */ /* list transaction targets */
i = NULL; i = NULL;
for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) { for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) {
PM_PKG *pkg = alpm_list_getdata(lp); pmpkg_t *pkg = alpm_list_getdata(lp);
i = list_add(i, strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME))); i = list_add(i, strdup(alpm_pkg_get_name(pkg)));
} }
list_display(_("\nTargets:"), i); list_display(_("\nTargets:"), i);
FREELIST(i); FREELIST(i);

View file

@ -54,14 +54,11 @@ extern list_t *pmc_syncs;
static int sync_cleancache(int level) static int sync_cleancache(int level)
{ {
long lroot, lcachedir; const char *root, *cachedir;
char *root, *cachedir;
char dirpath[PATH_MAX]; char dirpath[PATH_MAX];
alpm_get_option(PM_OPT_ROOT, &lroot); root = alpm_option_get_root();
root = (void *)lroot; cachedir = alpm_option_get_cachedir();
alpm_get_option(PM_OPT_CACHEDIR, &lcachedir);
cachedir = (void *)lcachedir;
snprintf(dirpath, PATH_MAX, "%s%s", root, 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) static int sync_search(list_t *syncs, list_t *targets)
{ {
list_t *i; list_t *i;
PM_LIST *ret; pmlist_t *ret;
for(i = targets; i; i = i->next) { 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) { for(i = syncs; i; i = i->next) {
sync_t *sync = i->data; sync_t *sync = i->data;
if(targets) { if(targets) {
PM_LIST *lp; pmlist_t *lp;
ret = alpm_db_search(sync->db); ret = alpm_db_search(sync->db);
if(ret == NULL) { if(ret == NULL) {
continue; continue;
} }
for(lp = ret; lp; lp = alpm_list_next(lp)) { 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 ", printf("%s/%s %s %s%s%s\n ",
(char *)alpm_db_getinfo(sync->db, PM_DB_TREENAME), alpm_db_get_name(sync->db),
(char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), alpm_pkg_get_name(pkg),
(char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION), alpm_pkg_get_version(pkg),
(group ? " (" : ""), (group ? group : ""), (group ? ") " : "")); (group ? " (" : ""), (group ? group : ""), (group ? ") " : ""));
indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
printf("\n\n"); printf("\n\n");
} }
alpm_list_free_outer(ret); alpm_list_free_outer(ret);
} else { } else {
PM_LIST *lp; pmlist_t *lp;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(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)); MSG(NL, "%s/%s %s\n ", sync->treename, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
MSG(NL, "\n"); 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(i = targets; i; i = i->next) {
for(j = syncs; j; j = j->next) { for(j = syncs; j; j = j->next) {
sync_t *sync = j->data; 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) { if(grp) {
MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME)); MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp));
PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES)); pmlist_display(" ", alpm_grp_get_packages(grp));
} }
} }
} }
} else { } else {
for(j = syncs; j; j = j->next) { for(j = syncs; j; j = j->next) {
sync_t *sync = j->data; sync_t *sync = j->data;
PM_LIST *lp; pmlist_t *lp;
for(lp = alpm_db_getgrpcache(sync->db); lp; lp = alpm_list_next(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) { 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) { for(j = syncs; j && !found; j = j->next) {
sync_t *sync = j->data; 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)) { 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); dump_pkg_sync(pkg, sync->treename);
MSG(NL, "\n"); MSG(NL, "\n");
found = 1; found = 1;
@ -298,7 +296,7 @@ static int sync_info(list_t *syncs, list_t *targets)
} else { } else {
for(j = syncs; j; j = j->next) { for(j = syncs; j; j = j->next) {
sync_t *sync = j->data; sync_t *sync = j->data;
PM_LIST *lp; pmlist_t *lp;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) { for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
dump_pkg_sync(alpm_list_getdata(lp), sync->treename); 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) { for(i = ls; i; i = i->next) {
PM_LIST *lp; pmlist_t *lp;
sync_t *sync = i->data; sync_t *sync = i->data;
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(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", (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 confirm = 0;
int retval = 0; int retval = 0;
list_t *i = NULL; list_t *i = NULL;
PM_LIST *packages, *data, *lp; pmlist_t *packages, *data, *lp;
if(pmc_syncs == NULL || !list_count(pmc_syncs)) { if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
ERR(NL, _("no usable package repositories configured.\n")); 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); data = alpm_trans_getinfo(PM_TRANS_PACKAGES);
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
PM_SYNCPKG *sync = alpm_list_getdata(lp); pmsyncpkg_t *sync = alpm_list_getdata(lp);
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG); pmpkg_t *spkg = alpm_sync_get_package(sync);
if(!strcmp("pacman", alpm_pkg_getinfo(spkg, PM_PKG_NAME)) && alpm_list_count(data) > 1) { 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, _("\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, _(":: 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")); 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) { for(i = targets; i; i = i->next) {
char *targ = i->data; char *targ = i->data;
if(alpm_trans_addtarget(targ) == -1) { if(alpm_trans_addtarget(targ) == -1) {
PM_GRP *grp = NULL; pmgrp_t *grp = NULL;
list_t *j; list_t *j;
int found=0; int found=0;
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) { if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
@ -480,14 +478,14 @@ int pacman_sync(list_t *targets)
sync_t *sync = j->data; sync_t *sync = j->data;
grp = alpm_db_readgrp(sync->db, targ); grp = alpm_db_readgrp(sync->db, targ);
if(grp) { if(grp) {
PM_LIST *pmpkgs; pmlist_t *pmpkgs;
list_t *k, *pkgs; list_t *k, *pkgs;
found++; found++;
MSG(NL, _(":: group %s:\n"), targ); 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 */ /* remove dupe entries in case a package exists in multiple repos */
/* (the dupe function takes a PM_LIST* and returns a list_t*) */ /* (the dupe function takes a pmlist_t* and returns a list_t*) */
pkgs = PM_LIST_remove_dupes(pmpkgs); pkgs = pmlist_remove_dupes(pmpkgs);
list_display(" ", pkgs); list_display(" ", pkgs);
if(yesno(_(":: Install whole content? [Y/n] "))) { if(yesno(_(":: Install whole content? [Y/n] "))) {
for(k = pkgs; k; k = k->next) { for(k = pkgs; k; k = k->next) {
@ -506,14 +504,14 @@ int pacman_sync(list_t *targets)
} }
if(!found) { if(!found) {
/* targ not found in sync db, searching for providers... */ /* targ not found in sync db, searching for providers... */
PM_LIST *k = NULL; pmlist_t *k = NULL;
PM_PKG *pkg; pmpkg_t *pkg;
char *pname = NULL; const char *pname = NULL;
for(j = pmc_syncs; j && !k; j = j->next) { for(j = pmc_syncs; j && !k; j = j->next) {
sync_t *sync = j->data; sync_t *sync = j->data;
k = alpm_db_whatprovides(sync->db, targ); k = alpm_db_whatprovides(sync->db, targ);
pkg = (PM_PKG*)alpm_list_getdata(alpm_list_first(k)); pkg = (pmpkg_t*)alpm_list_getdata(alpm_list_first(k));
pname = (char*)alpm_pkg_getinfo(pkg, PM_PKG_NAME); pname = alpm_pkg_get_name(pkg);
} }
if(pname != NULL) { if(pname != NULL) {
/* targ is provided by pname */ /* targ is provided by pname */
@ -536,7 +534,7 @@ int pacman_sync(list_t *targets)
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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), 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"), (long)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? _("requires") : _("is required by"),
alpm_dep_getinfo(miss, PM_DEP_NAME)); alpm_dep_getinfo(miss, PM_DEP_NAME));
@ -550,7 +548,7 @@ int pacman_sync(list_t *targets)
break; break;
case PM_ERR_CONFLICTING_DEPS: case PM_ERR_CONFLICTING_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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"), MSG(NL, _(":: %s: conflicts with %s"),
alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); 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; double mb, umb;
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) { for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
PM_SYNCPKG *sync = alpm_list_getdata(lp); pmsyncpkg_t *sync = alpm_list_getdata(lp);
PM_PKG *pkg = alpm_sync_getinfo(sync, PM_SYNC_PKG); pmpkg_t *pkg = alpm_sync_get_package(sync);
char *pkgname, *pkgver; const char *pkgname, *pkgver;
if((long)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) { if(alpm_sync_get_type(sync) == PM_SYNC_TYPE_REPLACE) {
PM_LIST *j, *data; pmlist_t *j, *data;
data = alpm_sync_getinfo(sync, PM_SYNC_DATA); data = alpm_sync_get_data(sync);
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) { for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
PM_PKG *p = alpm_list_getdata(j); pmpkg_t *p = alpm_list_getdata(j);
char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME); const char *pkgname = alpm_pkg_get_name(p);
if(!list_is_strin(pkgname, list_remove)) { if(!list_is_strin(pkgname, list_remove)) {
list_remove = list_add(list_remove, strdup(pkgname)); list_remove = list_add(list_remove, strdup(pkgname));
} }
} }
} }
pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME); pkgname = alpm_pkg_get_name(pkg);
pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION); pkgver = alpm_pkg_get_version(pkg);
totalsize += (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE); totalsize += alpm_pkg_get_size(pkg);
totalusize += (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE); totalusize += alpm_pkg_get_usize(pkg);
asprintf(&str, "%s-%s", pkgname, pkgver); asprintf(&str, "%s-%s", pkgname, pkgver);
list_install = list_add(list_install, str); list_install = list_add(list_install, str);
@ -673,7 +671,7 @@ int pacman_sync(list_t *targets)
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_FILE_CONFLICTS: case PM_ERR_FILE_CONFLICTS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { 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)) { switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
case PM_CONFLICT_TYPE_TARGET: case PM_CONFLICT_TYPE_TARGET:
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),

View file

@ -24,7 +24,7 @@
/* Repositories */ /* Repositories */
typedef struct __sync_t { typedef struct __sync_t {
char *treename; char *treename;
PM_DB *db; pmdb_t *db;
} sync_t; } sync_t;
int pacman_sync(list_t *targets); int pacman_sync(list_t *targets);

View file

@ -84,7 +84,7 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
break; break;
case PM_TRANS_EVT_ADD_START: case PM_TRANS_EVT_ADD_START:
if(config->noprogressbar) { 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; break;
case PM_TRANS_EVT_ADD_DONE: 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")); MSG(CL, _("done.\n"));
} }
snprintf(str, LOG_STR_LEN, _("installed %s (%s)"), snprintf(str, LOG_STR_LEN, _("installed %s (%s)"),
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); alpm_pkg_get_version(data1));
alpm_logaction(str); alpm_logaction(str);
break; break;
case PM_TRANS_EVT_REMOVE_START: case PM_TRANS_EVT_REMOVE_START:
if(config->noprogressbar) { 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; break;
case PM_TRANS_EVT_REMOVE_DONE: 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")); MSG(CL, _("done.\n"));
} }
snprintf(str, LOG_STR_LEN, _("removed %s (%s)"), snprintf(str, LOG_STR_LEN, _("removed %s (%s)"),
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); alpm_pkg_get_version(data1));
alpm_logaction(str); alpm_logaction(str);
break; break;
case PM_TRANS_EVT_UPGRADE_START: case PM_TRANS_EVT_UPGRADE_START:
if(config->noprogressbar) { 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; break;
case PM_TRANS_EVT_UPGRADE_DONE: 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")); MSG(CL, _("done.\n"));
} }
snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"), snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"),
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), (char *)alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION), (char *)alpm_pkg_get_version(data2),
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); (char *)alpm_pkg_get_version(data1));
alpm_logaction(str); alpm_logaction(str);
break; break;
case PM_TRANS_EVT_INTEGRITY_START: 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 { } else {
snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "), 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), alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME)); alpm_pkg_get_name(data2));
*response = yesno(str); *response = yesno(str);
} }
break; break;
@ -192,7 +192,7 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} }
} else { } else {
snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "), 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); *response = yesno(str);
} }
break; break;
@ -205,9 +205,9 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} }
} else { } else {
snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "), 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 *)data3,
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME)); alpm_pkg_get_name(data2));
*response = yesno(str); *response = yesno(str);
} }
break; break;
@ -236,8 +236,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} else { } else {
if(!config->op_s_downloadonly) { if(!config->op_s_downloadonly) {
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "), snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); alpm_pkg_get_version(data1));
*response = yesno(str); *response = yesno(str);
} else { } else {
*response = 1; *response = 1;
@ -254,8 +254,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
} else { } else {
if(!config->op_s_downloadonly) { if(!config->op_s_downloadonly) {
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "), 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), alpm_pkg_get_name(data1),
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); alpm_pkg_get_version(data1));
*response = yesno(str); *response = yesno(str);
} else { } else {
*response = 1; *response = 1;
@ -349,7 +349,7 @@ void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howm
break; break;
} }
alpm_get_option(PM_OPT_CHOMP, &chomp); chomp = alpm_option_get_chomp();
/* hide the cursor, prevent flicker during fancy graphics /* hide the cursor, prevent flicker during fancy graphics
printf("\033[?25l\033[?1c["); printf("\033[?25l\033[?1c[");

View file

@ -49,6 +49,16 @@ extern int maxcols;
extern config_t *config; extern config_t *config;
extern int neednl; 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' */ /* does the same thing as 'mkdir -p' */
int makepath(char *path) int makepath(char *path)
{ {
@ -126,14 +136,14 @@ int rmrf(char *path)
/* output a string, but wrap words properly with a specified indentation /* 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; int cidx = indent;
while(*p) { while(*p) {
if(*p == ' ') { if(*p == ' ') {
char *next = NULL; const char *next = NULL;
int len; int len;
p++; p++;
if(p == NULL || *p == ' ') continue; if(p == NULL || *p == ' ') continue;

View file

@ -43,10 +43,10 @@
} while(0) } while(0)
#define _(str) gettext(str) #define _(str) gettext(str)
int getcols();
int makepath(char *path); int makepath(char *path);
int rmrf(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 *buildstring(list_t *strlist);
char *strtoupper(char *str); char *strtoupper(char *str);
char *strtrim(char *str); char *strtrim(char *str);