Allow $repo expansion in 'Server' config lines
Small change (addition of a 'strreplace' function) which replaces any $repo tokens found in a server line with the name of the repo or section being processed. While this is more simplistic than suggestions on flyspray, it works and I think it is cleaner. Merits can be discussed further. Ref: FS#6389 Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
parent
1381b58ceb
commit
ebad199614
3 changed files with 72 additions and 22 deletions
|
@ -224,7 +224,7 @@ int alpm_db_setserver(pmdb_t *db, const char *url)
|
|||
}
|
||||
db->servers = alpm_list_add(db->servers, server);
|
||||
_alpm_log(PM_LOG_DEBUG, _("adding new server to database '%s': protocol '%s', server '%s', path '%s'"),
|
||||
db->treename, server->s_url->scheme, server->s_url->host, server->s_url->doc);
|
||||
db->treename, server->s_url->scheme, server->s_url->host, server->s_url->doc);
|
||||
} else {
|
||||
FREELIST(db->servers);
|
||||
_alpm_log(PM_LOG_DEBUG, _("serverlist flushed for '%s'"), db->treename);
|
||||
|
@ -467,8 +467,8 @@ int alpm_pkg_checksha1sum(pmpkg_t *pkg)
|
|||
ASSERT(pkg->data != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
|
||||
|
||||
snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
|
||||
handle->root, handle->cachedir,
|
||||
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
handle->root, handle->cachedir,
|
||||
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
|
||||
sha1sum = _alpm_SHAFile(path);
|
||||
if(sha1sum == NULL) {
|
||||
|
@ -511,8 +511,8 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
|
|||
ASSERT(pkg->data != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
|
||||
|
||||
snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
|
||||
handle->root, handle->cachedir,
|
||||
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
handle->root, handle->cachedir,
|
||||
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
|
||||
md5sum = _alpm_MDFile(path);
|
||||
if(md5sum == NULL) {
|
||||
|
@ -545,7 +545,7 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
|
|||
*/
|
||||
int SYMEXPORT alpm_pkg_vercmp(const char *ver1, const char *ver2)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
return(_alpm_versioncmp(ver1, ver2));
|
||||
}
|
||||
|
@ -636,8 +636,8 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, alpm_list_t* needles)
|
|||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||
*/
|
||||
int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
|
||||
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
|
||||
alpm_trans_cb_progress progress)
|
||||
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
|
||||
alpm_trans_cb_progress progress)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
|
@ -1059,11 +1059,15 @@ int SYMEXPORT alpm_parse_config(char *file, alpm_cb_db_register callback, const
|
|||
}
|
||||
} else {
|
||||
if(strcmp(origkey, "Server") == 0 || strcmp(key, "SERVER") == 0) {
|
||||
/* add to the list */
|
||||
if(alpm_db_setserver(db, ptr) != 0) {
|
||||
/* let's attempt a replacement for the current repo */
|
||||
char *server = _alpm_strreplace(ptr, "$repo", section);
|
||||
|
||||
if(alpm_db_setserver(db, server) != 0) {
|
||||
/* pm_errno is set by alpm_db_setserver */
|
||||
return(-1);
|
||||
}
|
||||
|
||||
free(server);
|
||||
} else {
|
||||
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ int _alpm_copyfile(const char *src, const char *dest)
|
|||
}
|
||||
|
||||
/* Convert a string to uppercase
|
||||
*/
|
||||
*/
|
||||
char *_alpm_strtoupper(char *str)
|
||||
{
|
||||
char *ptr = str;
|
||||
|
@ -174,7 +174,7 @@ char *_alpm_strtoupper(char *str)
|
|||
}
|
||||
|
||||
/* Trim whitespace and newlines from a string
|
||||
*/
|
||||
*/
|
||||
char *_alpm_strtrim(char *str)
|
||||
{
|
||||
char *pch = str;
|
||||
|
@ -205,8 +205,53 @@ char *_alpm_strtrim(char *str)
|
|||
return(str);
|
||||
}
|
||||
|
||||
/* Helper function for _alpm_strreplace */
|
||||
static void _strnadd(char **str, const char *append, unsigned int count)
|
||||
{
|
||||
if(*str) {
|
||||
*str = realloc(*str, strlen(*str) + count + 1);
|
||||
} else {
|
||||
*str = calloc(sizeof(char), count + 1);
|
||||
}
|
||||
|
||||
strncat(*str, append, count);
|
||||
}
|
||||
|
||||
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
|
||||
* a new string (must be free'd) */
|
||||
char *_alpm_strreplace(const char *str, const char *needle, const char *replace)
|
||||
{
|
||||
const char *p, *q;
|
||||
p = q = str;
|
||||
|
||||
char *newstr = NULL;
|
||||
unsigned int needlesz = strlen(needle),
|
||||
replacesz = strlen(replace);
|
||||
|
||||
while (1) {
|
||||
q = strstr(p, needle);
|
||||
if(!q) { /* not found */
|
||||
if(*p) {
|
||||
/* add the rest of 'p' */
|
||||
_strnadd(&newstr, p, strlen(p));
|
||||
}
|
||||
break;
|
||||
} else { /* found match */
|
||||
if(q > p){
|
||||
/* add chars between this occurance and last occurance, if any */
|
||||
_strnadd(&newstr, p, q - p);
|
||||
}
|
||||
_strnadd(&newstr, replace, replacesz);
|
||||
p = q + needlesz;
|
||||
}
|
||||
}
|
||||
|
||||
return newstr;
|
||||
}
|
||||
|
||||
|
||||
/* Create a lock file
|
||||
*/
|
||||
*/
|
||||
int _alpm_lckmk(const char *file)
|
||||
{
|
||||
int fd, count = 0;
|
||||
|
@ -234,7 +279,7 @@ int _alpm_lckmk(const char *file)
|
|||
}
|
||||
|
||||
/* Remove a lock file
|
||||
*/
|
||||
*/
|
||||
int _alpm_lckrm(const char *file)
|
||||
{
|
||||
if(unlink(file) == -1 && errno != ENOENT) {
|
||||
|
@ -244,7 +289,7 @@ int _alpm_lckrm(const char *file)
|
|||
}
|
||||
|
||||
/* Compression functions
|
||||
*/
|
||||
*/
|
||||
|
||||
int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
||||
{
|
||||
|
@ -252,8 +297,8 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
|||
struct archive_entry *entry;
|
||||
char expath[PATH_MAX];
|
||||
const int archive_flags = ARCHIVE_EXTRACT_OWNER |
|
||||
ARCHIVE_EXTRACT_PERM |
|
||||
ARCHIVE_EXTRACT_TIME;
|
||||
ARCHIVE_EXTRACT_PERM |
|
||||
ARCHIVE_EXTRACT_TIME;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
|
@ -278,7 +323,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
|||
archive_entry_set_pathname(entry, expath);
|
||||
if(archive_read_extract(_archive, entry, archive_flags) != ARCHIVE_OK) {
|
||||
_alpm_log(PM_LOG_ERROR, _("could not extract %s: %s\n"), archive_entry_pathname(entry), archive_error_string(_archive));
|
||||
return(1);
|
||||
return(1);
|
||||
}
|
||||
|
||||
if(fn) {
|
||||
|
@ -349,8 +394,8 @@ int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str)
|
|||
|
||||
/* Use ISO-8601 date format */
|
||||
fprintf(f, "[%04d-%02d-%02d %02d:%02d] %s\n",
|
||||
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, str);
|
||||
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, str);
|
||||
|
||||
fflush(f);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ int _alpm_makepath(const char *path);
|
|||
int _alpm_copyfile(const char *src, const char *dest);
|
||||
char *_alpm_strtoupper(char *str);
|
||||
char *_alpm_strtrim(char *str);
|
||||
char *_alpm_strreplace(const char *str, const char *needle, const char *replace);
|
||||
int _alpm_lckmk(const char *file);
|
||||
int _alpm_lckrm(const char *file);
|
||||
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
|
||||
|
|
Loading…
Add table
Reference in a new issue