summaryrefslogtreecommitdiff
path: root/src/lib/config.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-09-17 23:07:19 +0200
committerCarl Hetherington <cth@carlh.net>2023-09-17 23:07:19 +0200
commit35ba1f7a97d3173bd3846cb48de1542fff1d8b5a (patch)
tree45a3639c5c2cecd0e1091330ceadd9b5282ccffa /src/lib/config.cc
parent5fd9501bc2e879708b36ee17b3cb2bcd546feadc (diff)
Always use a default template.
Diffstat (limited to 'src/lib/config.cc')
-rw-r--r--src/lib/config.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 44aa51dc5..042dc9994 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -1404,6 +1404,11 @@ Config::templates () const
for (auto const& i: boost::filesystem::directory_iterator(read_path("templates"))) {
n.push_back (i.path().filename().string());
}
+
+ /* Make sure that the default exists, and is the first thing on the list */
+ n.erase(std::remove(n.begin(), n.end(), default_template_name()), n.end());
+ n.insert(n.begin(), default_template_name());
+
return n;
}
@@ -1411,14 +1416,19 @@ Config::templates () const
bool
Config::existing_template (string name) const
{
- return boost::filesystem::exists (template_read_path(name));
+ return name == default_template_name() || template_read_path(name);
}
-boost::filesystem::path
+optional<boost::filesystem::path>
Config::template_read_path (string name) const
{
- return read_path("templates") / tidy_for_filename (name);
+ auto const path = read_path("templates") / tidy_for_filename(name);
+ if (!boost::filesystem::exists(path)) {
+ return {};
+ }
+
+ return path;
}
@@ -1432,7 +1442,9 @@ Config::template_write_path (string name) const
void
Config::rename_template (string old_name, string new_name) const
{
- boost::filesystem::rename (template_read_path(old_name), template_write_path(new_name));
+ if (auto read_path = template_read_path(old_name)) {
+ boost::filesystem::rename(*read_path, template_write_path(new_name));
+ }
}
void