diff options
author | Aaron Griffin <aaron@archlinux.org> | 2006-11-15 07:50:37 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2006-11-15 07:50:37 +0000 |
commit | 00ce9ea7394e6e21010d3758e5d949e2b449f64d (patch) | |
tree | 1e91d8c80cf2e535978b6fa51031765460234c9d /lib/libalpm | |
parent | 74e780f25df5642e19e6b8cc42ff1432fb7fe1b9 (diff) |
* Initial changes to gensync - makepkg changes were not checked in from another
machine - still pending
* Addition of _alpm_pkg_makefilename to simplify the with/without -ARCH prefix
scheme we're going with for the interim
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.c | 39 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 1 | ||||
-rw-r--r-- | lib/libalpm/package.c | 29 | ||||
-rw-r--r-- | lib/libalpm/package.h | 1 | ||||
-rw-r--r-- | lib/libalpm/server.c | 1 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 28 | ||||
-rw-r--r-- | lib/libalpm/util.c | 40 | ||||
-rw-r--r-- | lib/libalpm/util.h | 1 |
8 files changed, 83 insertions, 57 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 77f3632e..b642501b 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <errno.h> #include <fcntl.h> +#include <ctype.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> @@ -705,6 +706,44 @@ int alpm_pkg_vercmp(const char *ver1, const char *ver2) return(_alpm_versioncmp(ver1, ver2)); } +/* internal */ +char *_supported_archs[] = { + "i586", + "i686", + "ppc", + "x86_64", +}; + +char *alpm_pkg_name_hasarch(char *pkgname) +{ + /* TODO remove this when we transfer everything over to -ARCH + * + * this parsing sucks... it's done to support + * two package formats for the time being: + * package-name-foo-1.0.0-1-i686 + * and + * package-name-bar-1.2.3-1 + */ + int i = 0; + char *arch, *cmp, *p; + + if((p = strrchr(pkgname, '-'))) { + for(i=0; i < sizeof(_supported_archs)/sizeof(char*); ++i) { + cmp = p+1; + arch = _supported_archs[i]; + + /* whee, case insensitive compare */ + + while(*arch && *cmp && tolower(*arch++) == tolower(*cmp++)) ; + if(*arch || *cmp) continue; + + return p; + } + } + return NULL; +} + + /** @} */ /** @defgroup alpm_groups Group Functions diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 155d09ad..394001ce 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -205,6 +205,7 @@ int alpm_pkg_checksha1sum(PM_PKG *pkg); char *alpm_fetch_pkgurl(char *url); int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section); int alpm_pkg_vercmp(const char *ver1, const char *ver2); +char *alpm_pkg_name_hasarch(char *pkgname); /* * Groups diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 85d76151..1302ebe5 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -435,6 +435,30 @@ 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]; @@ -456,12 +480,9 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch) *p = '\0'; } - if((p = _alpm_pkgname_has_arch(tmp))) { - *p = '\0'; - } if(witharch) { /* trim architecture */ - if((p = _alpm_pkgname_has_arch(tmp))) { + if((p = alpm_pkg_name_hasarch(tmp))) { *p = 0; } } diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 6dd092c8..d96f8d41 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -98,6 +98,7 @@ 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); #endif /* _ALPM_PACKAGE_H */ diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c index aeaad6ae..4c0b5e79 100644 --- a/lib/libalpm/server.c +++ b/lib/libalpm/server.c @@ -180,6 +180,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath, } else { dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p")); } + if(downloadLastErrCode != 0 || dlf == NULL) { _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s://%s: %s"), fn, server->s_url->scheme, server->s_url->host, downloadLastErrString); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 52de2660..9fd1884f 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -785,23 +785,23 @@ 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; char path[PATH_MAX]; + fname = _alpm_pkg_makefilename(spkg); if(trans->flags & PM_TRANS_FLAG_PRINTURIS) { - snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, spkg->name, spkg->version); - EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), path); + EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), fname); } else { struct stat buf; - snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, spkg->name, spkg->version); + snprintf(path, PATH_MAX, "%s/%s", ldir, fname); if(stat(path, &buf)) { /* file is not in the cache dir, so add it to the list */ - snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, spkg->name, spkg->version); - files = _alpm_list_add(files, strdup(path)); + files = _alpm_list_add(files, strdup(fname)); } else { - _alpm_log(PM_LOG_DEBUG, _("%s-%s%s is already in the cache\n"), - spkg->name, spkg->version, PM_EXT_PKG); + _alpm_log(PM_LOG_DEBUG, _("%s is already in the cache\n"), fname); } } + FREE(fname); } } @@ -843,12 +843,11 @@ 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[PATH_MAX]; + char str[PATH_MAX], *pkgname; char *md5sum1, *md5sum2, *sha1sum1, *sha1sum2; char *ptr=NULL; - snprintf(pkgname, PATH_MAX, "%s-%s" PM_EXT_PKG, - spkg->name, spkg->version); + pkgname = _alpm_pkg_makefilename(spkg); md5sum1 = spkg->md5sum; sha1sum1 = spkg->sha1sum; @@ -885,7 +884,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) } if(doremove) { char str[PATH_MAX]; - snprintf(str, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG, handle->root, handle->cachedir, spkg->name, spkg->version); + snprintf(str, PATH_MAX, "%s%s/%s", handle->root, handle->cachedir, pkgname); unlink(str); snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname); } else { @@ -894,6 +893,7 @@ 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); } @@ -965,8 +965,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 *fname = NULL; char str[PATH_MAX]; - snprintf(str, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG, handle->root, handle->cachedir, spkg->name, spkg->version); + + fname = _alpm_pkg_makefilename(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/util.c b/lib/libalpm/util.c index 38b0bced..ddaecebb 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -641,44 +641,4 @@ void _alpm_time2string(time_t t, char *buffer) } } -/* internal */ -char *_supported_archs[] = { - "i586", - "i686", - "ppc", - "x86_64", -}; - -char *_alpm_pkgname_has_arch(char *pkgname) -{ - /* TODO remove this when we transfer everything over to -ARCH - * - * this parsing sucks... it's done to support - * two package formats for the time being: - * package-name-foo-1.0.0-1-i686 - * and - * package-name-bar-1.2.3-1 - */ - int i = 0; - char *arch, *cmp, *p; - - if((p = strrchr(pkgname, '-'))) { - for(i=0; i < sizeof(_supported_archs)/sizeof(char*); ++i) { - cmp = p+1; - arch = _supported_archs[i]; - - /* whee, case insensitive compare */ - - while(*arch && *cmp && tolower(*arch++) == tolower(*cmp++)) ; - if(*arch || *cmp) continue; - - return p; - } - } - return NULL; -} - - - - /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 37a19e89..37b944cb 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -72,7 +72,6 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data); #endif int _alpm_reg_match(char *string, char *pattern); void _alpm_time2string(time_t t, char *buffer); -char *_alpm_pkgname_has_arch(char *pkgname); #ifdef __sun__ char* strsep(char** str, const char* delims); char* mkdtemp(char *template); |