summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-06-18 05:25:07 +0200
committerDan McGee <dan@archlinux.org>2007-09-28 07:16:43 +0200
commitf7bbfe4052ca1060d2d1021dacd77923d8ab6786 (patch)
treec1013c79b1148874ff30effe4c84c99eb69b5a86 /lib/libalpm
parent0758012b6617fd25f3af84853611b9adaf65f674 (diff)
downloadpacman-f7bbfe4052ca1060d2d1021dacd77923d8ab6786.tar.gz
pacman-f7bbfe4052ca1060d2d1021dacd77923d8ab6786.tar.xz
Remove package name dependency from libalpm
Previously, package names must match a specified scheme or they will cause pacman add operations to fail. This is not a very intelligent or necessary way to act, so remove the dependency on the name of the package to be installed and read all relevant information from the metadata instead. This does have one causality to be addressed later- pacman cache cleaning functionality, which has never been phenomenal, just lost most capability. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/add.c45
-rw-r--r--lib/libalpm/alpm.h9
-rw-r--r--lib/libalpm/be_files.c43
-rw-r--r--lib/libalpm/package.c101
-rw-r--r--lib/libalpm/package.h1
-rw-r--r--lib/libalpm/server.c13
6 files changed, 55 insertions, 157 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 86e80778..442b3180 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -53,11 +53,9 @@
int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
{
- pmpkg_t *info = NULL;
- pmpkg_t *dummy;
- char pkgname[PKG_NAME_LEN], pkgver[PKG_VERSION_LEN];
+ pmpkg_t *pkg = NULL;
+ const char *pkgname, *pkgver;
alpm_list_t *i;
- struct stat buf;
ALPM_LOG_FUNC;
@@ -67,24 +65,11 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
_alpm_log(PM_LOG_DEBUG, "loading target '%s'\n", name);
- /* TODO FS#5120 we need a better way to check if a package is a valid package,
- * and read the metadata instead of relying on the filename for package name
- * and version */
- if(stat(name, &buf)) {
- pm_errno = PM_ERR_NOT_A_FILE;
- goto error;
- }
-
- if(_alpm_pkg_splitname(name, pkgname, pkgver, 1) == -1) {
- pm_errno = PM_ERR_PKG_INVALID_NAME;
- goto error;
- }
-
- /* no additional hyphens in version strings */
- if(strchr(pkgver, '-') != strrchr(pkgver, '-')) {
- pm_errno = PM_ERR_PKG_INVALID_NAME;
+ if(alpm_pkg_load(name, &pkg) != 0) {
goto error;
}
+ pkgname = alpm_pkg_get_name(pkg);
+ pkgver = alpm_pkg_get_version(pkg);
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
/* only install this package if it is not already installed */
@@ -95,7 +80,7 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
} else {
if(trans->flags & PM_TRANS_FLAG_FRESHEN) {
/* only upgrade/install this package if it is already installed and at a lesser version */
- dummy = _alpm_db_get_pkgfromcache(db, pkgname);
+ pmpkg_t *dummy = _alpm_db_get_pkgfromcache(db, pkgname);
if(dummy == NULL || _alpm_versioncmp(dummy->version, pkgver) >= 0) {
pm_errno = PM_ERR_PKG_CANT_FRESH;
goto error;
@@ -126,29 +111,17 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
}
}
- _alpm_log(PM_LOG_DEBUG, "reading '%s' metadata\n", pkgname);
- info = _alpm_pkg_load(name);
- if(info == NULL) {
- /* pm_errno is already set by pkg_load() */
- goto error;
- }
- /* check to verify we're not getting fooled by a corrupted package */
- if(strcmp(pkgname, info->name) != 0 || strcmp(pkgver, info->version) != 0) {
- pm_errno = PM_ERR_PKG_INVALID;
- goto error;
- }
-
if(trans->flags & PM_TRANS_FLAG_ALLDEPS) {
- info->reason = PM_PKG_REASON_DEPEND;
+ pkg->reason = PM_PKG_REASON_DEPEND;
}
/* add the package to the transaction */
- trans->packages = alpm_list_add(trans->packages, info);
+ trans->packages = alpm_list_add(trans->packages, pkg);
return(0);
error:
- _alpm_pkg_free(info);
+ _alpm_pkg_free(pkg);
return(-1);
}
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 852b5c15..53bbaaa0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -180,20 +180,11 @@ typedef enum _pmpkgreason_t {
PM_PKG_REASON_DEPEND = 1 /* installed as a dependency for another package */
} pmpkgreason_t;
-/* package name formats */
-/*
-typedef enum _pmpkghasarch_t {
- PM_PKG_WITHOUT_ARCH = 0, / pkgname-pkgver-pkgrel, used under PM_DBPATH /
- PM_PKG_WITH_ARCH = 1 / pkgname-pkgver-pkgrel-arch, used under PM_CACHEDIR /
-} pmpkghasarch_t;
-*/
-
int alpm_pkg_load(const char *filename, pmpkg_t **pkg);
int alpm_pkg_free(pmpkg_t *pkg);
int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
char *alpm_fetch_pkgurl(const char *url);
int alpm_pkg_vercmp(const char *ver1, const char *ver2);
-char *alpm_pkg_name_hasarch(const char *pkgname);
alpm_list_t *alpm_pkg_compute_requiredby(pmpkg_t *pkg);
const char *alpm_pkg_get_filename(pmpkg_t *pkg);
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index af222136..1566fe2d 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -104,6 +104,43 @@ void _alpm_db_rewind(pmdb_t *db)
rewinddir(db->handle);
}
+static int _alpm_db_splitname(const char *target, char *name, char *version)
+{
+ /* the format of a db entry is as follows:
+ * package-version-rel/
+ * package name can contain hyphens, so parse from the back- go back
+ * two hyphens and we have split the version from the name.
+ */
+ char *tmp, *p, *q;
+
+ if(target == NULL) {
+ return(-1);
+ }
+ tmp = strdup(target);
+ p = tmp + strlen(tmp);
+
+ /* do the magic parsing- find the beginning of the version string
+ * by doing two iterations of same loop to lop off two hyphens */
+ for(q = --p; *q && *q != '-'; q--);
+ for(p = --q; *p && *p != '-'; p--);
+ if(*p != '-' || p == tmp) {
+ return(-1);
+ }
+
+ /* copy into fields and return */
+ if(version) {
+ strncpy(version, p+1, PKG_VERSION_LEN);
+ }
+ /* insert a terminator at the end of the name (on hyphen)- then copy it */
+ *p = '\0';
+ if(name) {
+ strncpy(name, tmp, PKG_NAME_LEN);
+ }
+
+ free(tmp);
+ return(0);
+}
+
pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
{
struct dirent *ent = NULL;
@@ -177,8 +214,10 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
_alpm_log(PM_LOG_DEBUG, "db scan could not find package: %s\n", target);
return(NULL);
}
- if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version, 0) == -1) {
- _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), ent->d_name);
+ /* split the db entry name */
+ if(_alpm_db_splitname(ent->d_name, pkg->name, pkg->version) != 0) {
+ _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
+ ent->d_name);
alpm_pkg_free(pkg);
pkg = NULL;
continue;
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 4a6e62b9..30d77a74 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -65,7 +65,8 @@ int SYMEXPORT alpm_pkg_load(const char *filename, pmpkg_t **pkg)
_alpm_log(PM_LOG_FUNCTION, "enter alpm_pkg_load\n");
/* Sanity checks */
- ASSERT(filename != NULL && strlen(filename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(filename != NULL && strlen(filename) != 0,
+ RET_ERR(PM_ERR_WRONG_ARGS, -1));
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
*pkg = _alpm_pkg_load(filename);
@@ -151,51 +152,6 @@ int SYMEXPORT alpm_pkg_vercmp(const char *ver1, const char *ver2)
return(_alpm_versioncmp(ver1, ver2));
}
-/* internal */
-static char *_supported_archs[] = {
- "i586",
- "i686",
- "ppc",
- "x86_64",
-};
-
-/**
- * @brief Determine if a package name has -ARCH tacked on.
- * @param pkgname name of the package to parse
- * @return pointer to start of -ARCH text if it exists, else NULL
- */
-char SYMEXPORT *alpm_pkg_name_hasarch(const 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
- */
- size_t i = 0;
- char *arch, *cmp, *p;
-
- ALPM_LOG_FUNC;
-
- 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);
-}
-
const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
@@ -1113,59 +1069,6 @@ pmpkg_t *_alpm_pkg_find(const char *needle, alpm_list_t *haystack)
return(NULL);
}
-int _alpm_pkg_splitname(const char *target, char *name, char *version, int witharch)
-{
- char tmp[PKG_FULLNAME_LEN+7];
- const char *t;
- char *p, *q;
-
- ALPM_LOG_FUNC;
-
- if(target == NULL) {
- return(-1);
- }
-
- /* trim path name (if any) */
- if((t = strrchr(target, '/')) == NULL) {
- t = target;
- } else {
- t++;
- }
- strncpy(tmp, t, PKG_FULLNAME_LEN+7);
- /* trim file extension (if any) */
- if((p = strstr(tmp, PKGEXT))) {
- *p = '\0';
- }
-
- if(witharch) {
- /* trim architecture */
- if((p = alpm_pkg_name_hasarch(tmp))) {
- *p = '\0';
- }
- }
-
- p = tmp + strlen(tmp);
-
- for(q = --p; *q && *q != '-'; q--);
- if(*q != '-' || q == tmp) {
- return(-1);
- }
- for(p = --q; *p && *p != '-'; p--);
- if(*p != '-' || p == tmp) {
- return(-1);
- }
- if(version) {
- strncpy(version, p+1, PKG_VERSION_LEN);
- }
- *p = '\0';
-
- if(name) {
- strncpy(name, tmp, PKG_NAME_LEN);
- }
-
- return(0);
-}
-
/* fill in requiredby field of package,
* used when we want to install or add a package */
void _alpm_pkg_update_requiredby(pmpkg_t *pkg)
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 460a38c8..30dd3961 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -96,7 +96,6 @@ int _alpm_pkg_cmp(const void *p1, const void *p2);
int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg);
pmpkg_t *_alpm_pkg_load(const char *pkgfile);
pmpkg_t *_alpm_pkg_find(const char *needle, alpm_list_t *haystack);
-int _alpm_pkg_splitname(const char *target, char *name, char *version, int witharch);
int _alpm_pkg_istoonew(pmpkg_t *pkg);
void _alpm_pkg_update_requiredby(pmpkg_t *pkg);
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index 5fdc41a6..8d9c6f87 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -187,22 +187,15 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
char output[PATH_MAX];
char *fn = (char *)lp->data;
char pkgname[PKG_NAME_LEN];
- char *p;
fileurl = url_for_file(server, fn);
if(!fileurl) {
return(-1);
}
- /* Try to get JUST the name of the package from the filename */
- memset(pkgname, 0, PKG_NAME_LEN);
- if((p = strstr(fn, PKGEXT))) {
- _alpm_pkg_splitname(fn, pkgname, NULL, 1);
- }
- if(!strlen(pkgname)) {
- /* just use the raw filename if we can't find crap */
- strncpy(pkgname, fn, PKG_NAME_LEN);
- }
+ /* use the raw filename for download progress */
+ /* TODO maybe strip the normal pkg.tar.gz extension? */
+ strncpy(pkgname, fn, PKG_NAME_LEN);
_alpm_log(PM_LOG_DEBUG, "using '%s' for download progress\n", pkgname);
snprintf(realfile, PATH_MAX, "%s%s", localpath, fn);