diff options
author | Aaron Griffin <aaron@archlinux.org> | 2006-11-22 09:03:41 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2006-11-22 09:03:41 +0000 |
commit | 986409f9bd7b84e63352b9ec1f825b0c917627a6 (patch) | |
tree | f74350bb415326724e86408985ea0d43fe93c7b0 /lib | |
parent | 54691771831c97c7366bf8ee7c54da3952c22120 (diff) | |
download | pacman-986409f9bd7b84e63352b9ec1f825b0c917627a6.tar.xz |
* Completed getinfo api changes (pmmissing_t, pmtrans_t, etc)
* Modified some dependancy checking
* Changed "performing local database upgrade" message to be more clear
* Change 'usize' to 'isize' in database files
* Scriptlet output is now sent to pacman's log file
* Limited some debugging output to be more clear
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.c | 73 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 43 | ||||
-rw-r--r-- | lib/libalpm/be_files.c | 27 | ||||
-rw-r--r-- | lib/libalpm/conflict.c | 37 | ||||
-rw-r--r-- | lib/libalpm/deps.c | 141 | ||||
-rw-r--r-- | lib/libalpm/deps.h | 1 | ||||
-rw-r--r-- | lib/libalpm/package.c | 56 | ||||
-rw-r--r-- | lib/libalpm/package.h | 5 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 19 | ||||
-rw-r--r-- | lib/libalpm/trans.c | 35 | ||||
-rw-r--r-- | lib/libalpm/util.c | 15 | ||||
-rw-r--r-- | lib/libalpm/util.h | 4 | ||||
-rw-r--r-- | lib/libalpm/versioncmp.c | 43 | ||||
-rw-r--r-- | lib/libalpm/versioncmp.h | 4 |
14 files changed, 256 insertions, 247 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 49cfd0cd..1bda976c 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -613,34 +613,6 @@ pmlist_t *alpm_db_search(pmdb_t *db) * @{ */ -/** Get informations about the transaction. - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_trans_getinfo(unsigned char parm) -{ - pmtrans_t *trans; - void *data; - - /* Sanity checks */ - ASSERT(handle != NULL, return(NULL)); - ASSERT(handle->trans != NULL, return(NULL)); - - trans = handle->trans; - - switch(parm) { - case PM_TRANS_TYPE: data = (void *)(long)trans->type; break; - case PM_TRANS_FLAGS: data = (void *)(long)trans->flags; break; - case PM_TRANS_TARGETS: data = trans->targets; break; - case PM_TRANS_PACKAGES: data = trans->packages; break; - default: - data = NULL; - break; - } - - return(data); -} - /** Initialize the transaction. * @param type type of the transaction * @param flags flags of the transaction (like nodeps, etc) @@ -790,32 +762,6 @@ int alpm_trans_release() * @brief Functions to get informations about a libalpm dependency * @{ */ - -/** Get informations about a dependency. - * @param miss dependency pointer - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm) -{ - void *data; - - /* Sanity checks */ - ASSERT(miss != NULL, return(NULL)); - - switch(parm) { - case PM_DEP_TARGET: data = (void *)(long)miss->target; break; - case PM_DEP_TYPE: data = (void *)(long)miss->type; break; - case PM_DEP_MOD: data = (void *)(long)miss->depend.mod; break; - case PM_DEP_NAME: data = miss->depend.name; break; - case PM_DEP_VERSION: data = miss->depend.version; break; - default: - data = NULL; - break; - } - - return(data); -} /** @} */ /** \addtogroup alpm_conflict File Conflicts Functions @@ -828,25 +774,6 @@ void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm) * @param parm name of the info to get * @return a void* on success (the value), NULL on error */ -void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm) -{ - void *data; - - /* Sanity checks */ - ASSERT(conflict != NULL, return(NULL)); - - switch(parm) { - case PM_CONFLICT_TARGET: data = conflict->target; break; - case PM_CONFLICT_TYPE: data = (void *)(long)conflict->type; break; - case PM_CONFLICT_FILE: data = conflict->file; break; - case PM_CONFLICT_CTARGET: data = conflict->ctarget; break; - default: - data = NULL; - break; - } - - return(data); -} /** @} */ /** \addtogroup alpm_log Logging Functions diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 3b5126b1..2f35ad6f 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -200,6 +200,7 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this int alpm_pkg_vercmp(const char *ver1, const char *ver2); char *alpm_pkg_name_hasarch(char *pkgname); +const char *alpm_pkg_get_filename(pmpkg_t *pkg); 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); @@ -212,7 +213,7 @@ 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 long alpm_pkg_get_isize(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); @@ -331,15 +332,10 @@ typedef void (*alpm_trans_cb_conv)(unsigned char, void *, void *, void *, int *) /* Transaction Progress callback */ typedef void (*alpm_trans_cb_progress)(unsigned char, char *, int, int, int); -/* Info parameters */ -enum { - PM_TRANS_TYPE = 1, - PM_TRANS_FLAGS, - PM_TRANS_TARGETS, - PM_TRANS_PACKAGES -}; - -void *alpm_trans_getinfo(unsigned char parm); +unsigned char alpm_trans_get_type(); +unsigned int alpm_trans_get_flags(); +pmlist_t * alpm_trans_get_targets(); +pmlist_t * alpm_trans_get_packages(); int alpm_trans_init(unsigned char type, unsigned int flags, alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv, alpm_trans_cb_progress cb_progress); int alpm_trans_sysupgrade(void); int alpm_trans_addtarget(char *target); @@ -362,16 +358,12 @@ enum { PM_DEP_TYPE_REQUIRED, PM_DEP_TYPE_CONFLICT }; -/* Info parameters */ -enum { - PM_DEP_TARGET = 1, - PM_DEP_TYPE, - PM_DEP_MOD, - PM_DEP_NAME, - PM_DEP_VERSION -}; -void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm); +const char *alpm_dep_get_target(pmdepmissing_t *miss); +unsigned char alpm_dep_get_type(pmdepmissing_t *miss); +unsigned char alpm_dep_get_mod(pmdepmissing_t *miss); +const char *alpm_dep_get_name(pmdepmissing_t *miss); +const char *alpm_dep_get_version(pmdepmissing_t *miss); /* * File conflicts @@ -381,15 +373,11 @@ enum { PM_CONFLICT_TYPE_TARGET = 1, PM_CONFLICT_TYPE_FILE }; -/* Info parameters */ -enum { - PM_CONFLICT_TARGET = 1, - PM_CONFLICT_TYPE, - PM_CONFLICT_FILE, - PM_CONFLICT_CTARGET -}; -void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm); +const char *alpm_conflict_get_target(pmconflict_t *conflict); +unsigned char alpm_conflict_get_type(pmconflict_t *conflict); +const char *alpm_conflict_get_file(pmconflict_t *conflict); +const char *alpm_conflict_get_ctarget(pmconflict_t *conflict); /* * Helpers @@ -398,6 +386,7 @@ void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm); /* pmlist_t */ pmlist_t *alpm_list_first(pmlist_t *list); pmlist_t *alpm_list_next(pmlist_t *entry); +#define alpm_list_data(type, list) (type)alpm_list_getdata((list)) void *alpm_list_getdata(const pmlist_t *entry); int alpm_list_free(pmlist_t *entry); int alpm_list_free_outer(pmlist_t *entry); diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 33dd78b5..ccd0b246 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -198,6 +198,10 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) return(-1); } + if(info->infolevel & inforeq) { + /* already loaded this info, do nothing */ + return(0); + } _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 */ @@ -223,7 +227,16 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) break; } _alpm_strtrim(line); - if(!strcmp(line, "%DESC%")) { + if(!strcmp(line, "%FILENAME%")) { + /* filename is _new_ - it provides the real name of the package, on the + * server, to allow for us to not tie the name of the actual file to the + * data of the package + */ + if(fgets(info->filename, sizeof(info->filename), fp) == NULL) { + goto error; + } + _alpm_strtrim(info->filename); + } else if(!strcmp(line, "%DESC%")) { while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) { info->desc_localized = _alpm_list_add(info->desc_localized, strdup(line)); } @@ -305,15 +318,15 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) } _alpm_strtrim(tmp); info->size = atol(tmp); - } else if(!strcmp(line, "%USIZE%")) { - /* USIZE (uncompressed size) tag only appears in sync repositories, + } else if(!strcmp(line, "%ISIZE%")) { + /* ISIZE (installed size) tag only appears in sync repositories, * not the local one. */ char tmp[32]; if(fgets(tmp, sizeof(tmp), fp) == NULL) { goto error; } _alpm_strtrim(tmp); - info->usize = atol(tmp); + info->isize = atol(tmp); } else if(!strcmp(line, "%SHA1SUM%")) { /* SHA1SUM tag only appears in sync repositories, * not the local one. */ @@ -525,9 +538,9 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) fprintf(fp, "%%CSIZE%%\n" "%ld\n\n", info->size); } - if(info->usize) { - fprintf(fp, "%%USIZE%%\n" - "%ld\n\n", info->usize); + if(info->isize) { + fprintf(fp, "%%ISIZE%%\n" + "%ld\n\n", info->isize); } if(info->sha1sum) { fprintf(fp, "%%SHA1SUM%%\n" diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 57323c30..c9649e40 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -29,12 +29,14 @@ #include "config.h" #include <stdlib.h> +#include <stdio.h> #include <unistd.h> #include <string.h> #include <limits.h> #include <sys/stat.h> #include <libintl.h> /* pacman */ +#include "handle.h" #include "list.h" #include "trans.h" #include "util.h" @@ -353,4 +355,39 @@ pmlist_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root, pmli return(conflicts); } +const char *alpm_conflict_get_target(pmconflict_t *conflict) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(conflict != NULL, return(NULL)); + + return conflict->target; +} + +unsigned char alpm_conflict_get_type(pmconflict_t *conflict) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(conflict != NULL, return(-1)); + + return conflict->type; +} + +const char *alpm_conflict_get_file(pmconflict_t *conflict) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(conflict != NULL, return(NULL)); + + return conflict->file; +} + +const char *alpm_conflict_get_ctarget(pmconflict_t *conflict) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(conflict != NULL, return(NULL)); + + return conflict->ctarget; +} /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index cdbec038..9cab8489 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -187,7 +187,6 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist { pmdepend_t depend; pmlist_t *i, *j, *k; - int cmp; int found = 0; pmlist_t *baddeps = NULL; pmdepmissing_t *miss = NULL; @@ -204,15 +203,16 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist pmpkg_t *tp = i->data; pmpkg_t *oldpkg; if(tp == NULL) { + _alpm_log(PM_LOG_DEBUG, _("null package found in package list")); continue; } if((oldpkg = _alpm_db_get_pkgfromcache(db, tp->name)) == NULL) { + _alpm_log(PM_LOG_DEBUG, _("cannot find package installed '%s'"), tp->name); continue; } _alpm_db_read(db, INFRQ_DEPENDS, oldpkg); for(j = oldpkg->requiredby; j; j = j->next) { - char *ver; pmpkg_t *p; found = 0; if((p = _alpm_db_get_pkgfromcache(db, j->data)) == NULL) { @@ -241,26 +241,7 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist /* we found an installed package that provides depend.name */ FREELISTPTR(provides); } - found = 0; - if(depend.mod == PM_DEP_MOD_ANY) { - found = 1; - } else { - /* note that we use the version from the NEW package in the check */ - ver = strdup(tp->version); - if(!index(depend.version,'-')) { - char *ptr; - for(ptr = ver; *ptr != '-'; ptr++); - *ptr = '\0'; - } - cmp = _alpm_versioncmp(ver, depend.version); - switch(depend.mod) { - case PM_DEP_MOD_EQ: found = (cmp == 0); break; - case PM_DEP_MOD_GE: found = (cmp >= 0); break; - case PM_DEP_MOD_LE: found = (cmp <= 0); break; - } - FREE(ver); - } - if(!found) { + if(!_alpm_depcmp(tp, &depend)) { _alpm_log(PM_LOG_DEBUG, _("checkdeps: found %s as required by %s"), depend.name, p->name); miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_REQUIRED, depend.mod, depend.name, depend.version); if(!_alpm_depmiss_isin(miss, baddeps)) { @@ -277,6 +258,7 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist for(i = packages; i; i = i->next) { pmpkg_t *tp = i->data; if(tp == NULL) { + _alpm_log(PM_LOG_DEBUG, _("null package found in package list")); continue; } @@ -294,29 +276,7 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist /* check database for literal packages */ for(k = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); k && !found; k = k->next) { pmpkg_t *p = (pmpkg_t *)k->data; - if(!strcmp(p->name, depend.name)) { - if(depend.mod == PM_DEP_MOD_ANY) { - /* accept any version */ - found = 1; - } else { - char *ver = strdup(p->version); - /* check for a release in depend.version. if it's - * missing remove it from p->version as well. - */ - if(!index(depend.version,'-')) { - char *ptr; - for(ptr = ver; *ptr != '-'; ptr++); - *ptr = '\0'; - } - cmp = _alpm_versioncmp(ver, depend.version); - switch(depend.mod) { - case PM_DEP_MOD_EQ: found = (cmp == 0); break; - case PM_DEP_MOD_GE: found = (cmp >= 0); break; - case PM_DEP_MOD_LE: found = (cmp <= 0); break; - } - FREE(ver); - } - } + found = _alpm_depcmp(p, &depend); } /* check database for provides matches */ if(!found) { @@ -340,57 +300,14 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist continue; } - if(depend.mod == PM_DEP_MOD_ANY) { - /* accept any version */ - found = 1; - } else { - char *ver = strdup(p->version); - /* check for a release in depend.version. if it's - * missing remove it from p->version as well. - */ - if(!index(depend.version,'-')) { - char *ptr; - for(ptr = ver; *ptr != '-'; ptr++); - *ptr = '\0'; - } - cmp = _alpm_versioncmp(ver, depend.version); - switch(depend.mod) { - case PM_DEP_MOD_EQ: found = (cmp == 0); break; - case PM_DEP_MOD_GE: found = (cmp >= 0); break; - case PM_DEP_MOD_LE: found = (cmp <= 0); break; - } - FREE(ver); - } + found = _alpm_depcmp(p, &depend); } FREELISTPTR(k); } /* check other targets */ for(k = packages; k && !found; k = k->next) { pmpkg_t *p = (pmpkg_t *)k->data; - /* see if the package names match OR if p provides depend.name */ - if(!strcmp(p->name, depend.name) || _alpm_list_is_strin(depend.name, p->provides)) { - if(depend.mod == PM_DEP_MOD_ANY) { - /* accept any version */ - found = 1; - } else { - char *ver = strdup(p->version); - /* check for a release in depend.version. if it's - * missing remove it from p->version as well. - */ - if(!index(depend.version,'-')) { - char *ptr; - for(ptr = ver; *ptr != '-'; ptr++); - *ptr = '\0'; - } - cmp = _alpm_versioncmp(ver, depend.version); - switch(depend.mod) { - case PM_DEP_MOD_EQ: found = (cmp == 0); break; - case PM_DEP_MOD_GE: found = (cmp >= 0); break; - case PM_DEP_MOD_LE: found = (cmp <= 0); break; - } - FREE(ver); - } - } + found = _alpm_depcmp(p, &depend); } /* else if still not found... */ if(!found) { @@ -701,4 +618,48 @@ error: return(-1); } +const char *alpm_dep_get_target(pmdepmissing_t *miss) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(miss != NULL, return(NULL)); + + return miss->target; +} + +unsigned char alpm_dep_get_type(pmdepmissing_t *miss) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(miss != NULL, return(-1)); + + return miss->type; +} + +unsigned char alpm_dep_get_mod(pmdepmissing_t *miss) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(miss != NULL, return(-1)); + + return miss->depend.mod; +} + +const char *alpm_dep_get_name(pmdepmissing_t *miss) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(miss != NULL, return(NULL)); + + return miss->depend.name; +} + +const char *alpm_dep_get_version(pmdepmissing_t *miss) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(miss != NULL, return(NULL)); + + return miss->depend.version; +} /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index d3269673..72425f56 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -25,6 +25,7 @@ #include "db.h" #include "sync.h" +#include "package.h" #include "alpm.h" /* Dependency */ diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 31867551..52e939d1 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -58,6 +58,7 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version) } else { pkg->version[0] = '\0'; } + pkg->filename[0] = '\0'; pkg->desc[0] = '\0'; pkg->url[0] = '\0'; pkg->license = NULL; @@ -70,7 +71,7 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version) pkg->sha1sum[0] = '\0'; pkg->arch[0] = '\0'; pkg->size = 0; - pkg->usize = 0; + pkg->isize = 0; pkg->scriptlet = 0; pkg->force = 0; pkg->reason = PM_PKG_REASON_EXPLICIT; @@ -101,6 +102,7 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) RET_ERR(PM_ERR_MEMORY, NULL); } + STRNCPY(newpkg->filename, pkg->filename, PKG_FILENAME_LEN); STRNCPY(newpkg->name, pkg->name, PKG_NAME_LEN); STRNCPY(newpkg->version, pkg->version, PKG_VERSION_LEN); STRNCPY(newpkg->desc, pkg->desc, PKG_DESC_LEN); @@ -113,7 +115,7 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) STRNCPY(newpkg->sha1sum, pkg->sha1sum, PKG_SHA1SUM_LEN); STRNCPY(newpkg->arch, pkg->arch, PKG_ARCH_LEN); newpkg->size = pkg->size; - newpkg->usize = pkg->usize; + newpkg->isize = pkg->isize; newpkg->force = pkg->force; newpkg->scriptlet = pkg->scriptlet; newpkg->reason = pkg->reason; @@ -244,10 +246,10 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output) char tmp[32]; STRNCPY(tmp, ptr, sizeof(tmp)); info->size = atol(ptr); - } else if(!strcmp(key, "USIZE")) { + } else if(!strcmp(key, "ISIZE")) { char tmp[32]; STRNCPY(tmp, ptr, sizeof(tmp)); - info->usize = atol(ptr); + info->isize = atol(ptr); } else if(!strcmp(key, "DEPEND")) { info->depends = _alpm_list_add(info->depends, strdup(ptr)); } else if(!strcmp(key, "REMOVE")) { @@ -437,30 +439,6 @@ pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack) return(NULL); } -char *_alpm_pkg_makefilename(pmpkg_t *pkg) -{ - char *fname = NULL; - int len = 0, arch_valid = 0; - - len = strlen(pkg->name) + strlen(pkg->version) + strlen(PM_EXT_PKG) + 3; - if(pkg->arch && strlen(pkg->arch) > 0) { - arch_valid = 1; - len += strlen(pkg->arch) + 1; - } - - if((fname = (char *)calloc(len, sizeof(char))) == NULL) { - RET_ERR(PM_ERR_MEMORY, NULL); - } - - if(arch_valid) { - snprintf(fname, len-1, "%s-%s-%s" PM_EXT_PKG, pkg->name, pkg->version, pkg->arch); - } else { - snprintf(fname, len-1, "%s-%s" PM_EXT_PKG, pkg->name, pkg->version); - } - - return fname; -} - int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch) { char tmp[PKG_FULLNAME_LEN+7]; @@ -511,6 +489,24 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch) return(0); } +const char *alpm_pkg_get_filename(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(!strlen(pkg->filename)) { + /* construct the file name, it's not in the desc file */ + if(pkg->arch && strlen(pkg->arch) > 0) { + snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s-%s" PM_EXT_PKG, pkg->name, pkg->version, pkg->arch); + } else { + snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s" PM_EXT_PKG, pkg->name, pkg->version); + } + } + + return pkg->filename; +} + const char *alpm_pkg_get_name(pmpkg_t *pkg) { /* Sanity checks */ @@ -649,7 +645,7 @@ unsigned long alpm_pkg_get_size(pmpkg_t *pkg) return pkg->size; } -unsigned long alpm_pkg_get_usize(pmpkg_t *pkg) +unsigned long alpm_pkg_get_isize(pmpkg_t *pkg) { /* Sanity checks */ ASSERT(handle != NULL, return(-1)); @@ -658,7 +654,7 @@ unsigned long alpm_pkg_get_usize(pmpkg_t *pkg) if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { _alpm_db_read(pkg->data, INFRQ_DESC, pkg); } - return pkg->usize; + return pkg->isize; } unsigned char alpm_pkg_get_reason(pmpkg_t *pkg) diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 1b834cb8..0b11ae49 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -37,6 +37,7 @@ enum { }; /* Packages */ +#define PKG_FILENAME_LEN 512 #define PKG_NAME_LEN 256 #define PKG_VERSION_LEN 64 #define PKG_FULLNAME_LEN (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1 @@ -50,6 +51,7 @@ enum { #define PKG_ARCH_LEN 32 struct __pmpkg_t { + char filename[PKG_FILENAME_LEN]; char name[PKG_NAME_LEN]; char version[PKG_VERSION_LEN]; char desc[PKG_DESC_LEN]; @@ -62,7 +64,7 @@ struct __pmpkg_t { char sha1sum[PKG_SHA1SUM_LEN]; char arch[PKG_ARCH_LEN]; unsigned long size; - unsigned long usize; + unsigned long isize; unsigned char scriptlet; unsigned char force; time_t date; @@ -93,7 +95,6 @@ void _alpm_pkg_free(void *data); int _alpm_pkg_cmp(const void *p1, const void *p2); pmpkg_t *_alpm_pkg_load(char *pkgfile); pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack); -char *_alpm_pkg_makefilename(pmpkg_t *pkg); int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index acc48362..7c251790 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -785,12 +785,12 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) pmdb_t *dbs = spkg->data; if(current == dbs) { - char *fname = NULL; + const char *fname = NULL; char path[PATH_MAX]; - fname = _alpm_pkg_makefilename(spkg); + fname = alpm_pkg_get_filename(spkg); if(trans->flags & PM_TRANS_FLAG_PRINTURIS) { - EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current), fname); + EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current), (char *)fname); } else { struct stat buf; snprintf(path, PATH_MAX, "%s/%s", ldir, fname); @@ -801,7 +801,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) _alpm_log(PM_LOG_DEBUG, _("%s is already in the cache\n"), fname); } } - FREE(fname); } } @@ -840,11 +839,12 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) for(i = trans->packages; i; i = i->next) { pmsyncpkg_t *sync = i->data; pmpkg_t *spkg = sync->pkg; - char str[PATH_MAX], *pkgname; + char str[PATH_MAX]; + const char *pkgname; char *md5sum1, *md5sum2, *sha1sum1, *sha1sum2; char *ptr=NULL; - pkgname = _alpm_pkg_makefilename(spkg); + pkgname = alpm_pkg_get_filename(spkg); md5sum1 = spkg->md5sum; sha1sum1 = spkg->sha1sum; @@ -877,7 +877,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) if(trans->flags & PM_TRANS_FLAG_ALLDEPS) { doremove=1; } else { - QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, pkgname, NULL, NULL, &doremove); + QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, (char *)pkgname, NULL, NULL, &doremove); } if(doremove) { char str[PATH_MAX]; @@ -890,7 +890,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) *data = _alpm_list_add(*data, ptr); retval = 1; } - FREE(pkgname); FREE(md5sum2); FREE(sha1sum2); } @@ -963,10 +962,10 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) pmsyncpkg_t *sync = i->data; pmpkg_t *spkg = sync->pkg; - char *fname = NULL; + const char *fname = NULL; char str[PATH_MAX]; - fname = _alpm_pkg_makefilename(spkg); + fname = alpm_pkg_get_filename(spkg); snprintf(str, PATH_MAX, "%s%s/%s", handle->root, handle->cachedir, fname); if(_alpm_trans_addtarget(tr, str) == -1) { goto error; diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 55d3cf7c..8def650f 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -226,4 +226,39 @@ int _alpm_trans_commit(pmtrans_t *trans, pmlist_t **data) return(0); } +unsigned char alpm_trans_get_type() +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(handle->trans != NULL, return(-1)); + + return handle->trans->type; +} + +unsigned int alpm_trans_get_flags() +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(handle->trans != NULL, return(-1)); + + return handle->trans->flags; +} + +pmlist_t * alpm_trans_get_targets() +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(handle->trans != NULL, return(NULL)); + + return handle->trans->targets; +} + +pmlist_t * alpm_trans_get_packages() +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(handle->trans != NULL, return(NULL)); + + return handle->trans->packages; +} /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index cca43117..1610c43f 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -511,13 +511,16 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha if(fgets(line, 1024, pp) == NULL) break; /* "START <event desc>" */ - if((strlen(line) > strlen(STARTSTR)) && !strncmp(line, STARTSTR, strlen(STARTSTR))) { - EVENT(trans, PM_TRANS_EVT_SCRIPTLET_START, _alpm_strtrim(line + strlen(STARTSTR)), NULL); + if((strlen(line) > strlen(SCRIPTLET_START)) && !strncmp(line, SCRIPTLET_START, strlen(SCRIPTLET_START))) { + EVENT(trans, PM_TRANS_EVT_SCRIPTLET_START, _alpm_strtrim(line + strlen(SCRIPTLET_START)), NULL); /* "DONE <ret code>" */ - } else if((strlen(line) > strlen(DONESTR)) && !strncmp(line, DONESTR, strlen(DONESTR))) { - EVENT(trans, PM_TRANS_EVT_SCRIPTLET_DONE, (void*)atol(_alpm_strtrim(line + strlen(DONESTR))), NULL); + } else if((strlen(line) > strlen(SCRIPTLET_DONE)) && !strncmp(line, SCRIPTLET_DONE, strlen(SCRIPTLET_DONE))) { + EVENT(trans, PM_TRANS_EVT_SCRIPTLET_DONE, (void*)atol(_alpm_strtrim(line + strlen(SCRIPTLET_DONE))), NULL); } else { - EVENT(trans, PM_TRANS_EVT_SCRIPTLET_INFO, _alpm_strtrim(line), NULL); + _alpm_strtrim(line); + /* log our script output */ + alpm_logaction(line); + EVENT(trans, PM_TRANS_EVT_SCRIPTLET_INFO, line, NULL); } } pclose(pp); @@ -577,7 +580,7 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data) pmsyncpkg_t *sync = i->data; if(sync->type != PM_SYNC_TYPE_REPLACE) { pmpkg_t *pkg = sync->pkg; - pkgsize += pkg->usize; + pkgsize += pkg->isize; } } else diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 37b944cb..978de9e7 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -51,8 +51,8 @@ #define _(s) s #endif -#define STARTSTR "START " -#define DONESTR "DONE " +#define SCRIPTLET_START "START " +#define SCRIPTLET_DONE "DONE " int _alpm_makepath(char *path); int _alpm_copyfile(char *src, char *dest); diff --git a/lib/libalpm/versioncmp.c b/lib/libalpm/versioncmp.c index 652b7efb..2e406d9e 100644 --- a/lib/libalpm/versioncmp.c +++ b/lib/libalpm/versioncmp.c @@ -26,7 +26,12 @@ #include <stdio.h> #include <ctype.h> #include <string.h> +#include <libintl.h> /* pacman */ +#include "alpm.h" +#include "log.h" +#include "util.h" +#include "list.h" #include "versioncmp.h" #ifndef HAVE_STRVERSCMP @@ -238,4 +243,42 @@ int _alpm_versioncmp(const char *a, const char *b) return(*one ? 1 : -1); } +int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep) +{ + int equal = 0; + + if(strcmp(pkg->name, dep->name) == 0 || _alpm_list_is_strin(dep->name, pkg->provides)) { + if(dep->mod == PM_DEP_MOD_ANY) { + equal = 1; + } else { + int cmp = _alpm_versioncmp(pkg->version, dep->version); + switch(dep->mod) { + case PM_DEP_MOD_EQ: equal = (cmp == 0); break; + case PM_DEP_MOD_GE: equal = (cmp >= 0); break; + case PM_DEP_MOD_LE: equal = (cmp <= 0); break; + } + } + + char *mod = "depends on"; + switch(dep->mod) { + case PM_DEP_MOD_EQ: mod = "=="; break; + case PM_DEP_MOD_GE: mod = ">="; break; + case PM_DEP_MOD_LE: mod = "<="; break; + } + + if(strlen(dep->version) > 0) { + _alpm_log(PM_LOG_DEBUG, _("depcmp: %s-%s %s %s-%s => %s"), + pkg->name, pkg->version, mod, dep->name, dep->version, + (equal ? "match" : "no match")); + } else { + _alpm_log(PM_LOG_DEBUG, _("depcmp: %s-%s %s %s => %s"), + pkg->name, pkg->version, mod, dep->name, + (equal ? "match" : "no match")); + } + } + + return equal; +} + + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/versioncmp.h b/lib/libalpm/versioncmp.h index ada2921a..3a64888a 100644 --- a/lib/libalpm/versioncmp.h +++ b/lib/libalpm/versioncmp.h @@ -23,7 +23,11 @@ #ifndef _PM_RPMVERCMP_H #define _PM_RPMVERCMP_H +#include "deps.h" +#include "package.h" + int _alpm_versioncmp(const char *a, const char *b); +int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep); #endif |