commit:     553d512900e5d83ec643475344f57118d8b4ed3f
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 31 06:52:40 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Mar 31 06:52:40 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=553d5129

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

 main.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

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;

Reply via email to