summaryrefslogtreecommitdiff
path: root/src/config/File.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-18 17:28:30 +0200
committerMax Kellermann <max@musicpd.org>2018-07-18 17:28:30 +0200
commitf30265a9ee3edd97ff922991544c6b169286391c (patch)
tree4448a355bcdc084341faad5c00bb4543feea92b2 /src/config/File.cxx
parentfcbcec6856a0e574b5ebc6d990c0afc0e25f132b (diff)
config/File: support wildcards in "include"
Diffstat (limited to 'src/config/File.cxx')
-rw-r--r--src/config/File.cxx29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/config/File.cxx b/src/config/File.cxx
index 5552f71b7..b552e6c2a 100644
--- a/src/config/File.cxx
+++ b/src/config/File.cxx
@@ -23,12 +23,14 @@
#include "Param.hxx"
#include "Block.hxx"
#include "Templates.hxx"
+#include "system/Error.hxx"
#include "util/Tokenizer.hxx"
#include "util/StringStrip.hxx"
#include "util/StringAPI.hxx"
#include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "fs/FileSystem.hxx"
+#include "fs/List.hxx"
#include "fs/Path.hxx"
#include "fs/io/FileReader.hxx"
#include "fs/io/BufferedReader.hxx"
@@ -179,18 +181,29 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Path directory)
if (StringIsEqual(name, "include")) {
// TODO: detect recursion
// TODO: Config{Block,Param} have only line number but no file name
- // TODO: support wildcards (include "conf.d/*.conf")
- const auto path = AllocatedPath::Apply(directory,
- AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
- ReadConfigFile(config_data, path);
+ const auto pattern = AllocatedPath::Apply(directory,
+ AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
+ for (const auto &path : ListWildcard(pattern))
+ ReadConfigFile(config_data, path);
continue;
}
if (StringIsEqual(name, "include_optional")) {
- const auto path = AllocatedPath::Apply(directory,
- AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
- if (PathExists(path))
- ReadConfigFile(config_data, path);
+ const auto pattern = AllocatedPath::Apply(directory,
+ AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
+
+ std::forward_list<AllocatedPath> l;
+ try {
+ l = ListWildcard(pattern);
+ } catch (const std::system_error &e) {
+ /* ignore "file not found */
+ if (!IsFileNotFound(e) && !IsPathNotFound(e))
+ throw;
+ }
+
+ for (const auto &path : l)
+ if (PathExists(path))
+ ReadConfigFile(config_data, path);
continue;
}