Commit 09f743dc authored by Max Kellermann's avatar Max Kellermann

config/File: add directive "include_optional"

parent 035f986a
...@@ -418,6 +418,14 @@ systemctl start mpd.socket</programlisting> ...@@ -418,6 +418,14 @@ systemctl start mpd.socket</programlisting>
</para> </para>
<programlisting>include "other.conf"</programlisting> <programlisting>include "other.conf"</programlisting>
<para>
You can use <varname>include_optional</varname> instead if you
want the included file to be optional; the directive will be
ignored if the file does not exist:
</para>
<programlisting>include_optional "may_not_exist.conf"</programlisting>
</section> </section>
<section id="config_music_directory"> <section id="config_music_directory">
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#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/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,13 +180,20 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Path directory) ...@@ -179,13 +180,20 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Path directory)
// 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") // TODO: support wildcards (include "conf.d/*.conf")
// TODO: add "include_optional"
const auto path = AllocatedPath::Apply(directory, const auto path = AllocatedPath::Apply(directory,
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer))); AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
ReadConfigFile(config_data, path); ReadConfigFile(config_data, path);
continue; continue;
} }
if (StringIsEqual(name, "include_optional")) {
const auto path = AllocatedPath::Apply(directory,
AllocatedPath::FromUTF8Throw(ExpectValueAndEnd(tokenizer)));
if (PathExists(path))
ReadConfigFile(config_data, path);
continue;
}
/* get the definition of that option, and check the /* get the definition of that option, and check the
"repeatable" flag */ "repeatable" flag */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment