summaryrefslogtreecommitdiff
path: root/lib/rpmrc.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-04-29 09:59:56 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-04-29 10:37:54 +0300
commit10b2d1300b25e47a525666fb2fc4564fa4cfe13e (patch)
tree8e4606f2c3fedf1fb79822890da049da549b1db2 /lib/rpmrc.c
parenteff99d08ac16fd37d53bb1baf808aadaa1e99743 (diff)
downloadlibrpm-tizen-10b2d1300b25e47a525666fb2fc4564fa4cfe13e.tar.gz
librpm-tizen-10b2d1300b25e47a525666fb2fc4564fa4cfe13e.tar.bz2
librpm-tizen-10b2d1300b25e47a525666fb2fc4564fa4cfe13e.zip
Use rpmGlob() for expanding rcfiles globs
- avoids static filename buffer and simplifies things quite a bit
Diffstat (limited to 'lib/rpmrc.c')
-rw-r--r--lib/rpmrc.c73
1 files changed, 23 insertions, 50 deletions
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
index 9dd9d69e2..237427cc8 100644
--- a/lib/rpmrc.c
+++ b/lib/rpmrc.c
@@ -1628,8 +1628,8 @@ void rpmFreeRpmrc(void)
*/
static rpmRC rpmReadRC(const char * rcfiles)
{
- char *myrcfiles, *r, *re;
- int rc;
+ ARGV_t p, globs = NULL, files = NULL;
+ rpmRC rc = RPMRC_FAIL;
if (!defaultsInitialized) {
setDefaults();
@@ -1639,67 +1639,40 @@ static rpmRC rpmReadRC(const char * rcfiles)
if (rcfiles == NULL)
rcfiles = defrcfiles;
- /* Read each file in rcfiles. */
- rc = RPMRC_OK;
- for (r = myrcfiles = xstrdup(rcfiles); r && *r != '\0'; r = re) {
- char fn[4096];
- FD_t fd;
-
- /* Get pointer to rest of files */
- for (re = r; (re = strchr(re, ':')) != NULL; re++) {
- if (!(re[1] == '/' && re[2] == '/'))
- break;
- }
- if (re && *re == ':')
- *re++ = '\0';
- else
- re = r + strlen(r);
-
- /* Expand ~/ to $HOME/ */
- fn[0] = '\0';
- if (r[0] == '~' && r[1] == '/') {
- const char * home = getenv("HOME");
- if (home == NULL) {
- /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */
- if (rcfiles == defrcfiles && myrcfiles != r)
- continue;
- rpmlog(RPMLOG_ERR, _("Cannot expand %s\n"), r);
- rc = RPMRC_FAIL;
- break;
- }
- if (strlen(home) > (sizeof(fn) - strlen(r))) {
- rpmlog(RPMLOG_ERR, _("Cannot read %s, HOME is too large.\n"),
- r);
- rc = RPMRC_FAIL;
- break;
- }
- strcpy(fn, home);
- r++;
+ /* Expand any globs in rcfiles. Missing files are ok here. */
+ argvSplit(&globs, rcfiles, ":");
+ for (p = globs; *p; p++) {
+ ARGV_t av = NULL;
+ if (rpmGlob(*p, NULL, &av) == 0) {
+ argvAppend(&files, av);
+ argvFree(av);
}
- strncat(fn, r, sizeof(fn) - (strlen(fn) + 1));
- fn[sizeof(fn)-1] = '\0';
+ }
+ argvFree(globs);
+ /* Read each file in rcfiles. */
+ for (p = files; *p; p++) {
+ FD_t fd;
+
/* Read another rcfile */
- fd = Fopen(fn, "r.fpio");
+ fd = Fopen(*p, "r.fpio");
if (fd == NULL || Ferror(fd)) {
/* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */
- if (rcfiles == defrcfiles && myrcfiles != r)
+ if (rcfiles == defrcfiles && *p != files)
continue;
rpmlog(RPMLOG_ERR, _("Unable to open %s for reading: %s.\n"),
- fn, Fstrerror(fd));
- rc = RPMRC_FAIL;
+ *p, Fstrerror(fd));
+ goto exit;
break;
} else {
- rc = doReadRC(fd, fn);
+ rc = doReadRC(fd, *p);
}
- if (rc) break;
}
- myrcfiles = _free(myrcfiles);
- if (rc)
- return rc;
-
+ rc = RPMRC_OK;
rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */
+exit:
+ argvFree(files);
return rc;
}