1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-01-09 13:07:58 -05:00

- merged pkg_new and pkg_dummy functions

- renamed _alpm_log_action to _alpm_logaction
This commit is contained in:
Aurelien Foret 2006-01-09 20:16:00 +00:00
parent 45a7e57f6c
commit fd6ce1f4cb
10 changed files with 29 additions and 48 deletions

View File

@ -71,7 +71,7 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
*/ */
if(strchr(name, '|')) { if(strchr(name, '|')) {
char *str, *ptr, *p; char *str, *ptr, *p;
dummy = pkg_new(); dummy = pkg_new(NULL, NULL);
if(dummy == NULL) { if(dummy == NULL) {
pm_errno = PM_ERR_MEMORY; pm_errno = PM_ERR_MEMORY;
goto error; goto error;
@ -339,10 +339,8 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
_alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version); _alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version);
/* we'll need to save some record for backup checks later */ /* we'll need to save some record for backup checks later */
oldpkg = pkg_new(); oldpkg = pkg_new(local->name, local->version);
if(oldpkg) { if(oldpkg) {
strncpy(oldpkg->name, local->name, PKG_NAME_LEN);
strncpy(oldpkg->version, local->version, PKG_VERSION_LEN);
if(!(local->infolevel & INFRQ_FILES)) { if(!(local->infolevel & INFRQ_FILES)) {
char name[PKG_FULLNAME_LEN]; char name[PKG_FULLNAME_LEN];
snprintf(name, PKG_FULLNAME_LEN, "%s-%s", local->name, local->version); snprintf(name, PKG_FULLNAME_LEN, "%s-%s", local->name, local->version);

View File

@ -565,9 +565,12 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1)); ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
/* ORE
* perform sanity checks on type and flags:
* for instance, we can't set UPGRADE and FRESHEN at the same time */
handle->trans = trans_new(); handle->trans = trans_new();
if(handle->trans == NULL) { if(handle->trans == NULL) {
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
@ -708,7 +711,7 @@ int alpm_logaction(char *fmt, ...)
It allows to share the log file between several frontends and to actually It allows to share the log file between several frontends and to actually
know who does what */ know who does what */
return(_alpm_log_action(handle->usesyslog, handle->logfd, str)); return(_alpm_logaction(handle->usesyslog, handle->logfd, str));
} }
/** @} */ /** @} */

View File

@ -238,7 +238,7 @@ pmpkg_t *db_scan(pmdb_t *db, char *target, unsigned int inforeq)
} }
} }
pkg = pkg_new(); pkg = pkg_new(NULL, NULL);
if(pkg == NULL) { if(pkg == NULL) {
return(NULL); return(NULL);
} }

View File

@ -562,7 +562,7 @@ PMList* removedeps(pmdb_t *db, PMList *targs)
} }
if(!needed) { if(!needed) {
char *name; char *name;
pmpkg_t *pkg = pkg_dummy(dep->name, dep->version); pmpkg_t *pkg = pkg_new(dep->name, dep->version);
if(pkg == NULL) { if(pkg == NULL) {
_alpm_log(PM_LOG_ERROR, "could not allocate memory for a package structure"); _alpm_log(PM_LOG_ERROR, "could not allocate memory for a package structure");
continue; continue;
@ -696,7 +696,7 @@ int resolvedeps(pmdb_t *local, PMList *dbs_sync, pmpkg_t *syncpkg, PMList *list,
} }
} }
if(found) { if(found) {
pmpkg_t *dummypkg = pkg_dummy(miss->target, NULL); pmpkg_t *dummypkg = pkg_new(miss->target, NULL);
QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep); QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep);
FREEPKG(dummypkg); FREEPKG(dummypkg);
} }

View File

@ -35,14 +35,22 @@
#include "package.h" #include "package.h"
#include "alpm.h" #include "alpm.h"
pmpkg_t *pkg_new() pmpkg_t *pkg_new(const char *name, const char *version)
{ {
pmpkg_t* pkg = NULL; pmpkg_t* pkg = NULL;
MALLOC(pkg, sizeof(pmpkg_t)); MALLOC(pkg, sizeof(pmpkg_t));
pkg->name[0] = '\0'; if(name && name[0] != 0) {
pkg->version[0] = '\0'; STRNCPY(pkg->name, name, PKG_NAME_LEN);
} else {
pkg->name[0] = '\0';
}
if(version && version[0] != 0) {
STRNCPY(pkg->version, version, PKG_VERSION_LEN);
} else {
pkg->version[0] = '\0';
}
pkg->desc[0] = '\0'; pkg->desc[0] = '\0';
pkg->url[0] = '\0'; pkg->url[0] = '\0';
pkg->license = NULL; pkg->license = NULL;
@ -133,27 +141,6 @@ void pkg_free(pmpkg_t *pkg)
return; return;
} }
/* Create a dummy package struct that only contains the package
* name and version. This is useful when we're only passing
* name/version data, but it needs to be wrapped in a pmpkg_t
*/
pmpkg_t* pkg_dummy(const char *name, const char *version)
{
pmpkg_t *pkg = pkg_new();
if(pkg == NULL) {
return(NULL);
}
if(name) {
STRNCPY(pkg->name, name, PKG_NAME_LEN);
}
if(version) {
STRNCPY(pkg->version, version, PKG_VERSION_LEN);
}
return(pkg);
}
/* Parses the package description file for the current package /* Parses the package description file for the current package
* *
* Returns: 0 on success, 1 on error * Returns: 0 on success, 1 on error
@ -262,7 +249,7 @@ pmpkg_t *pkg_load(char *pkgfile)
RET_ERR(PM_ERR_NOT_A_FILE, NULL); RET_ERR(PM_ERR_NOT_A_FILE, NULL);
} }
info = pkg_new(); info = pkg_new(NULL, NULL);
if(info == NULL) { if(info == NULL) {
tar_close(tar); tar_close(tar);
RET_ERR(PM_ERR_MEMORY, NULL); RET_ERR(PM_ERR_MEMORY, NULL);

View File

@ -86,10 +86,9 @@ do { \
} \ } \
} while(0) } while(0)
pmpkg_t* pkg_new(void); pmpkg_t* pkg_new(const char *name, const char *version);
pmpkg_t *pkg_dup(pmpkg_t *pkg); pmpkg_t *pkg_dup(pmpkg_t *pkg);
void pkg_free(pmpkg_t *pkg); void pkg_free(pmpkg_t *pkg);
pmpkg_t* pkg_dummy(const char *name, const char *version);
pmpkg_t *pkg_load(char *pkgfile); pmpkg_t *pkg_load(char *pkgfile);
int pkg_isin(pmpkg_t *needle, PMList *haystack); int pkg_isin(pmpkg_t *needle, PMList *haystack);
int pkg_splitname(char *target, char *name, char *version); int pkg_splitname(char *target, char *name, char *version);

View File

@ -161,7 +161,7 @@ int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
* the package to replace. * the package to replace.
*/ */
pmsyncpkg_t *sync; pmsyncpkg_t *sync;
pmpkg_t *dummy = pkg_dummy(lpkg->name, NULL); pmpkg_t *dummy = pkg_new(lpkg->name, NULL);
if(dummy == NULL) { if(dummy == NULL) {
pm_errno = PM_ERR_MEMORY; pm_errno = PM_ERR_MEMORY;
goto error; goto error;
@ -227,7 +227,7 @@ int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
_alpm_log(PM_LOG_FLOW1, "%s-%s: ignoring package upgrade (%s)", _alpm_log(PM_LOG_FLOW1, "%s-%s: ignoring package upgrade (%s)",
local->name, local->version, spkg->version); local->name, local->version, spkg->version);
} else { } else {
pmpkg_t *dummy = pkg_dummy(local->name, local->version); pmpkg_t *dummy = pkg_new(local->name, local->version);
sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy); sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
if(sync == NULL) { if(sync == NULL) {
FREEPKG(dummy); FREEPKG(dummy);
@ -311,12 +311,10 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n
if(!find_pkginsync(spkg->name, trans->packages)) { if(!find_pkginsync(spkg->name, trans->packages)) {
pmpkg_t *dummy = NULL; pmpkg_t *dummy = NULL;
if(local) { if(local) {
dummy = pkg_new(); dummy = pkg_new(local->name, local->version);
if(dummy == NULL) { if(dummy == NULL) {
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
STRNCPY(dummy->name, local->name, PKG_NAME_LEN);
STRNCPY(dummy->version, local->version, PKG_VERSION_LEN);
} }
sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy); sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
if(sync == NULL) { if(sync == NULL) {
@ -512,7 +510,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
for(l = trans->packages; l; l = l->next) { for(l = trans->packages; l; l = l->next) {
pmsyncpkg_t *s = l->data; pmsyncpkg_t *s = l->data;
if(!strcmp(s->pkg->name, miss->target)) { if(!strcmp(s->pkg->name, miss->target)) {
pmpkg_t *q = pkg_new(); pmpkg_t *q = pkg_new(NULL, NULL);
STRNCPY(q->name, miss->depend.name, PKG_NAME_LEN); STRNCPY(q->name, miss->depend.name, PKG_NAME_LEN);
if(s->type == PM_SYNC_TYPE_REPLACE) { if(s->type == PM_SYNC_TYPE_REPLACE) {
/* append to the replaces list */ /* append to the replaces list */

View File

@ -82,10 +82,6 @@ int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_t
/* Sanity checks */ /* Sanity checks */
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
/* ORE
perform sanity checks on type and flags:
for instance, we can't set UPGRADE and FRESHEN at the same time */
trans->type = type; trans->type = type;
trans->flags = flags; trans->flags = flags;
trans->cb_event = event; trans->cb_event = event;

View File

@ -308,7 +308,7 @@ int _alpm_rmrf(char *path)
return(0); return(0);
} }
int _alpm_log_action(unsigned char usesyslog, FILE *f, char *fmt, ...) int _alpm_logaction(unsigned char usesyslog, FILE *f, char *fmt, ...)
{ {
char msg[1024]; char msg[1024];
va_list args; va_list args;

View File

@ -53,7 +53,7 @@ int _alpm_lckmk(char *file);
int _alpm_lckrm(char *file); int _alpm_lckrm(char *file);
int _alpm_unpack(char *archive, const char *prefix, const char *fn); int _alpm_unpack(char *archive, const char *prefix, const char *fn);
int _alpm_rmrf(char *path); int _alpm_rmrf(char *path);
int _alpm_log_action(unsigned char usesyslog, FILE *f, char *fmt, ...); int _alpm_logaction(unsigned char usesyslog, FILE *f, char *fmt, ...);
int _alpm_ldconfig(char *root); int _alpm_ldconfig(char *root);
int _alpm_runscriptlet(char *util, char *installfn, char *script, char *ver, char *oldver); int _alpm_runscriptlet(char *util, char *installfn, char *script, char *ver, char *oldver);