index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dan McGee <dan@archlinux.org> | 2007-06-17 23:25:07 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-09-28 00:16:43 -0500 |
commit | f7bbfe4052ca1060d2d1021dacd77923d8ab6786 (patch) | |
tree | c1013c79b1148874ff30effe4c84c99eb69b5a86 /lib/libalpm/be_files.c | |
parent | 0758012b6617fd25f3af84853611b9adaf65f674 (diff) |
-rw-r--r-- | lib/libalpm/be_files.c | 43 |
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; |