summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2015-05-08 11:41:00 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2015-06-29 14:18:10 -0400
commitfba9bff5b0df73567017ec03dd59a009e1eb5463 (patch)
treeed20b477cdcc1568c85bef3c688b07f3fcb8f3cf /libs
parent5bf6542a2c0d351c2536984cad47233f22904a31 (diff)
improved error handling and checking for Session::save_template()
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/session_state.cc44
1 files changed, 26 insertions, 18 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index f11ba77a2a..30b4eaeb62 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -1985,26 +1985,28 @@ Session::XMLSourceFactory (const XMLNode& node)
int
Session::save_template (string template_name)
{
- XMLTree tree;
-
- if (_state_of_the_state & CannotSave) {
+ if ((_state_of_the_state & CannotSave) || template_name.empty ()) {
return -1;
}
- std::string user_template_dir(user_template_directory());
+ bool absolute_path = Glib::path_is_absolute (template_name);
- if (g_mkdir_with_parents (user_template_dir.c_str(), 0755) != 0) {
- error << string_compose(_("Could not create templates directory \"%1\" (%2)"),
- user_template_dir, g_strerror (errno)) << endmsg;
- return -1;
- }
+ /* directory to put the template in */
+ std::string template_dir_path;
- tree.set_root (&get_template());
+ if (!absolute_path) {
+ std::string user_template_dir(user_template_directory());
- std::string template_dir_path(user_template_dir);
-
- /* directory to put the template in */
- template_dir_path = Glib::build_filename (template_dir_path, template_name);
+ if (g_mkdir_with_parents (user_template_dir.c_str(), 0755) != 0) {
+ error << string_compose(_("Could not create templates directory \"%1\" (%2)"),
+ user_template_dir, g_strerror (errno)) << endmsg;
+ return -1;
+ }
+
+ template_dir_path = Glib::build_filename (user_template_dir, template_name);
+ } else {
+ template_dir_path = template_name;
+ }
if (Glib::file_test (template_dir_path, Glib::FILE_TEST_EXISTS)) {
warning << string_compose(_("Template \"%1\" already exists - new version not created"),
@@ -2019,9 +2021,16 @@ Session::save_template (string template_name)
}
/* file to write */
- std::string template_file_path(template_dir_path);
- template_file_path = Glib::build_filename (template_file_path, template_name + template_suffix);
+ std::string template_file_path;
+ if (absolute_path) {
+ template_file_path = Glib::build_filename (template_dir_path, Glib::path_get_basename (template_dir_path) + template_suffix);
+ } else {
+ template_file_path = Glib::build_filename (template_dir_path, template_name + template_suffix);
+ }
+
+ XMLTree tree;
+ tree.set_root (&get_template());
if (!tree.write (template_file_path)) {
error << _("template not saved") << endmsg;
return -1;
@@ -2029,8 +2038,7 @@ Session::save_template (string template_name)
/* copy plugin state directory */
- std::string template_plugin_state_path(template_dir_path);
- template_plugin_state_path = Glib::build_filename (template_plugin_state_path, X_("plugins"));
+ std::string template_plugin_state_path (Glib::build_filename (template_dir_path, X_("plugins")));
if (g_mkdir_with_parents (template_plugin_state_path.c_str(), 0755) != 0) {
error << string_compose(_("Could not create directory for Session template plugin state\"%1\" (%2)"),