Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Sat, 31 Mar 2018 06:54:43
Message-Id: 1522479160.553d512900e5d83ec643475344f57118d8b4ed3f.grobian@gentoo
1 commit: 553d512900e5d83ec643475344f57118d8b4ed3f
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sat Mar 31 06:52:40 2018 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sat Mar 31 06:52:40 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=553d5129
7
8 read_portage_env_file: support reading directories, bug #558306
9
10 In particular /etc/portage/make.conf can be a directory. If it is,
11 process it recursively in sorted order.
12
13 Bug: https://bugs.gentoo.org/558306
14
15 main.c | 22 +++++++++++++++++++++-
16 1 file changed, 21 insertions(+), 1 deletion(-)
17
18 diff --git a/main.c b/main.c
19 index 8000540..85740b8 100644
20 --- a/main.c
21 +++ b/main.c
22 @@ -639,12 +639,15 @@ set_portage_env_var(env_vars *var, const char *value)
23 }
24 }
25
26 -/* Helper to read a portage env file (e.g. make.conf) */
27 +/* Helper to read a portage env file (e.g. make.conf), or recursively if
28 + * it points to a directory */
29 static void
30 read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
31 {
32 size_t i, buflen, line, configroot_len, file_len;
33 FILE *fp;
34 + struct dirent **dents;
35 + int dentslen;
36 char *buf, *s, *p;
37
38 if (getenv("DEBUG"))
39 @@ -659,6 +662,23 @@ read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
40 memcpy(buf + configroot_len, file, file_len);
41 buf[buflen - 1] = '\0';
42
43 + if ((dentslen = scandir(buf, &dents, NULL, alphasort)) > 0) {
44 + int di;
45 + struct dirent *d;
46 + char npath[_Q_PATH_MAX];
47 +
48 + /* recurse through all files */
49 + for (di = 0; di < dentslen; di++) {
50 + d = dents[di];
51 + if (d->d_name[0] == '.' || d->d_name[0] == '~')
52 + continue;
53 + snprintf(npath, sizeof(npath), "%s/%s", file, d->d_name);
54 + read_portage_env_file(configroot, npath, vars);
55 + }
56 + scandir_free(dents, dentslen);
57 + goto done;
58 + }
59 +
60 fp = fopen(buf, "r");
61 if (fp == NULL)
62 goto done;