aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2018-03-31 08:52:40 +0200
committerFabian Groffen <grobian@gentoo.org>2018-03-31 08:52:40 +0200
commit553d512900e5d83ec643475344f57118d8b4ed3f (patch)
tree83ac6bd096bf8c4347fad3bd14f16b44d5f98355
parentinitialize_portage_env: move debug var printing after repos.conf (diff)
downloadportage-utils-553d512900e5d83ec643475344f57118d8b4ed3f.tar.gz
portage-utils-553d512900e5d83ec643475344f57118d8b4ed3f.tar.bz2
portage-utils-553d512900e5d83ec643475344f57118d8b4ed3f.zip
read_portage_env_file: support reading directories, bug #558306
In particular /etc/portage/make.conf can be a directory. If it is, process it recursively in sorted order. Bug: https://bugs.gentoo.org/558306
-rw-r--r--main.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/main.c b/main.c
index 8000540..85740b8 100644
--- a/main.c
+++ b/main.c
@@ -639,12 +639,15 @@ set_portage_env_var(env_vars *var, const char *value)
}
}
-/* Helper to read a portage env file (e.g. make.conf) */
+/* Helper to read a portage env file (e.g. make.conf), or recursively if
+ * it points to a directory */
static void
read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
{
size_t i, buflen, line, configroot_len, file_len;
FILE *fp;
+ struct dirent **dents;
+ int dentslen;
char *buf, *s, *p;
if (getenv("DEBUG"))
@@ -659,6 +662,23 @@ read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
memcpy(buf + configroot_len, file, file_len);
buf[buflen - 1] = '\0';
+ if ((dentslen = scandir(buf, &dents, NULL, alphasort)) > 0) {
+ int di;
+ struct dirent *d;
+ char npath[_Q_PATH_MAX];
+
+ /* recurse through all files */
+ for (di = 0; di < dentslen; di++) {
+ d = dents[di];
+ if (d->d_name[0] == '.' || d->d_name[0] == '~')
+ continue;
+ snprintf(npath, sizeof(npath), "%s/%s", file, d->d_name);
+ read_portage_env_file(configroot, npath, vars);
+ }
+ scandir_free(dents, dentslen);
+ goto done;
+ }
+
fp = fopen(buf, "r");
if (fp == NULL)
goto done;