1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

Move and rename splitname

The splitname function is a general utility function and so is better
suited to util.h.  Rename it to _alpm_splitname to indicate it is an
internal libalpm function as was the case prior to splitting local and
sync db handling.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2010-10-11 14:05:07 +10:00
parent 448f78c067
commit e464339e3b
6 changed files with 49 additions and 50 deletions

View File

@ -393,7 +393,7 @@ int _alpm_local_db_populate(pmdb_t *db)
return(-1); return(-1);
} }
/* split the db entry name */ /* split the db entry name */
if(splitname(name, pkg) != 0) { if(_alpm_splitname(name, pkg) != 0) {
_alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
name); name);
_alpm_pkg_free(pkg); _alpm_pkg_free(pkg);

View File

@ -172,7 +172,7 @@ int _alpm_sync_db_populate(pmdb_t *db)
name = archive_entry_pathname(entry); name = archive_entry_pathname(entry);
if(splitname(name, pkg) != 0) { if(_alpm_splitname(name, pkg) != 0) {
_alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
name); name);
_alpm_pkg_free(pkg); _alpm_pkg_free(pkg);

View File

@ -750,50 +750,4 @@ pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
return(NULL); return(NULL);
} }
int splitname(const char *target, pmpkg_t *pkg)
{
/* 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 || pkg == NULL) {
return(-1);
}
STRDUP(tmp, target, RET_ERR(PM_ERR_MEMORY, -1));
p = tmp + strlen(tmp);
/* remove any trailing '/' */
while (*(p - 1) == '/') {
--p;
*p = '\0';
}
/* 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(pkg->version) {
FREE(pkg->version);
}
STRDUP(pkg->version, p+1, RET_ERR(PM_ERR_MEMORY, -1));
/* insert a terminator at the end of the name (on hyphen)- then copy it */
*p = '\0';
if(pkg->name) {
FREE(pkg->name);
}
STRDUP(pkg->name, tmp, RET_ERR(PM_ERR_MEMORY, -1));
free(tmp);
return(0);
}
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View File

@ -100,8 +100,6 @@ void _alpm_db_free_grpcache(pmdb_t *db);
alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db); alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db);
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target); pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target);
int splitname(const char *target, pmpkg_t *pkg);
#endif /* _ALPM_DB_H */ #endif /* _ALPM_DB_H */
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View File

@ -800,4 +800,49 @@ char *_alpm_archive_fgets(char *line, size_t size, struct archive *a)
return(line); return(line);
} }
int _alpm_splitname(const char *target, pmpkg_t *pkg)
{
/* 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 || pkg == NULL) {
return(-1);
}
STRDUP(tmp, target, RET_ERR(PM_ERR_MEMORY, -1));
p = tmp + strlen(tmp);
/* remove any trailing '/' */
while (*(p - 1) == '/') {
--p;
*p = '\0';
}
/* 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(pkg->version) {
FREE(pkg->version);
}
STRDUP(pkg->version, p+1, RET_ERR(PM_ERR_MEMORY, -1));
/* insert a terminator at the end of the name (on hyphen)- then copy it */
*p = '\0';
if(pkg->name) {
FREE(pkg->name);
}
STRDUP(pkg->name, tmp, RET_ERR(PM_ERR_MEMORY, -1));
free(tmp);
return(0);
}
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View File

@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#include "alpm_list.h" #include "alpm_list.h"
#include "package.h" /* pmpkg_t */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -76,6 +77,7 @@ const char *_alpm_filecache_setup(void);
int _alpm_lstat(const char *path, struct stat *buf); int _alpm_lstat(const char *path, struct stat *buf);
int _alpm_test_md5sum(const char *filepath, const char *md5sum); int _alpm_test_md5sum(const char *filepath, const char *md5sum);
char *_alpm_archive_fgets(char *line, size_t size, struct archive *a); char *_alpm_archive_fgets(char *line, size_t size, struct archive *a);
int _alpm_splitname(const char *target, pmpkg_t *pkg);
#ifndef HAVE_STRSEP #ifndef HAVE_STRSEP
char *strsep(char **, const char *); char *strsep(char **, const char *);