config/File: support wildcards in "include"
This commit is contained in:
parent
fcbcec6856
commit
f30265a9ee
@ -426,6 +426,14 @@ systemctl start mpd.socket</programlisting>
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<programlisting>include_optional "may_not_exist.conf"</programlisting>
|
<programlisting>include_optional "may_not_exist.conf"</programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Both directives can have a shell pattern (with wildcards
|
||||||
|
'<filename>*</filename>' and '<filename>?</filename>') in the
|
||||||
|
last path segment, e.g.:
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting>include "conf.d/*.conf"</programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="config_music_directory">
|
<section id="config_music_directory">
|
||||||
|
@ -23,12 +23,14 @@
|
|||||||
#include "Param.hxx"
|
#include "Param.hxx"
|
||||||
#include "Block.hxx"
|
#include "Block.hxx"
|
||||||
#include "Templates.hxx"
|
#include "Templates.hxx"
|
||||||
|
#include "system/Error.hxx"
|
||||||
#include "util/Tokenizer.hxx"
|
#include "util/Tokenizer.hxx"
|
||||||
#include "util/StringStrip.hxx"
|
#include "util/StringStrip.hxx"
|
||||||
#include "util/StringAPI.hxx"
|
#include "util/StringAPI.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "fs/FileSystem.hxx"
|
#include "fs/FileSystem.hxx"
|
||||||
|
#include "fs/List.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/io/FileReader.hxx"
|
#include "fs/io/FileReader.hxx"
|
||||||
#include "fs/io/BufferedReader.hxx"
|
#include "fs/io/BufferedReader.hxx"
|
||||||
@ -179,18 +181,29 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Path directory)
|
|||||||
if (StringIsEqual(name, "include")) {
|
if (StringIsEqual(name, "include")) {
|
||||||
// TODO: detect recursion
|
// TODO: detect recursion
|
||||||
// TODO: Config{Block,Param} have only line number but no file name
|
// TODO: Config{Block,Param} have only line number but no file name
|
||||||
// TODO: support wildcards (include "conf.d/*.conf")
|
const auto pattern = AllocatedPath::Apply(directory,
|
||||||
const auto path = AllocatedPath::Apply(directory,
|
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
|
||||||
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
|
for (const auto &path : ListWildcard(pattern))
|
||||||
ReadConfigFile(config_data, path);
|
ReadConfigFile(config_data, path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringIsEqual(name, "include_optional")) {
|
if (StringIsEqual(name, "include_optional")) {
|
||||||
const auto path = AllocatedPath::Apply(directory,
|
const auto pattern = AllocatedPath::Apply(directory,
|
||||||
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
|
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
|
||||||
if (PathExists(path))
|
|
||||||
ReadConfigFile(config_data, path);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user