Revert "fix use of session-creation via template, when just template name is given"
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 18 Jul 2019 19:38:43 +0000 (13:38 -0600)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 18 Jul 2019 19:38:43 +0000 (13:38 -0600)
This reverts commit ce7add1481f54eb12b32e5f46af4ea36140eb932.

libs/ardour/session_state.cc

index f51b85b797c2b3092eb7d4c138b29ba3664700e2..e02fefc3b6ec34b2368cc629dafe5fb95b661343 100644 (file)
@@ -580,7 +580,7 @@ Session::ensure_subdirs ()
  *  Caller must not hold process lock.
  */
 int
-Session::create (const string& st, BusProfile* bus_profile)
+Session::create (const string& session_template, BusProfile* bus_profile)
 {
        if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) {
                error << string_compose(_("Session: cannot create session folder \"%1\" (%2)"), _path, strerror (errno)) << endmsg;
@@ -593,78 +593,71 @@ Session::create (const string& st, BusProfile* bus_profile)
 
        _writable = exists_and_writable (_path);
 
-       string session_template (st);
-
        if (!session_template.empty()) {
+               string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template));
 
-               if (session_template.find (G_DIR_SEPARATOR) == string::npos) {
-                       /* not a path */
-                       session_template = Glib::build_filename (user_template_directory(), session_template);
-               }
+               FILE* in = g_fopen (in_path.c_str(), "rb");
 
-               cerr << "Using session template " << session_template << endl;
+               if (in) {
+                       /* no need to call legalize_for_path() since the string
+                        * in session_template is already a legal path name
+                        */
+                       string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix);
 
-               string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template));
+                       FILE* out = g_fopen (out_path.c_str(), "wb");
 
-               FILE* in = g_fopen (in_path.c_str(), "rb");
+                       if (out) {
+                               char buf[1024];
+                               stringstream new_session;
 
-               if (!in) {
-                       error << string_compose (_("Could not open session template %1 for reading"), in_path)
-                               << endmsg;
-                       return -1;
-               }
+                               while (!feof (in)) {
+                                       size_t charsRead = fread (buf, sizeof(char), 1024, in);
 
-               /* no need to call legalize_for_path() since the string
-                * in session_template is already a legal path name
-                */
-               string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix);
+                                       if (ferror (in)) {
+                                               error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg;
+                                               fclose (in);
+                                               fclose (out);
+                                               return -1;
+                                       }
+                                       if (charsRead == 0) {
+                                               break;
+                                       }
+                                       new_session.write (buf, charsRead);
+                               }
+                               fclose (in);
 
-               FILE* out = g_fopen (out_path.c_str(), "wb");
+                               string file_contents = new_session.str();
+                               size_t writeSize = file_contents.length();
+                               if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) {
+                                       error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg;
+                                       fclose (out);
+                                       return -1;
+                               }
+                               fclose (out);
 
-               if (!out) {
-                       error << string_compose (_("Could not open %1 for writing session template"), out_path)
-                             << endmsg;
-                       fclose(in);
-                       return -1;
-               }
+                               _is_new = false;
 
-               char buf[1024];
-               stringstream new_session;
+                               if (!ARDOUR::Profile->get_trx()) {
+                                       /* Copy plugin state files from template to new session */
+                                       std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
+                                       copy_recurse (template_plugins, plugins_dir ());
+                               }
 
-               while (!feof (in)) {
-                       size_t charsRead = fread (buf, sizeof(char), 1024, in);
+                               return 0;
 
-                       if (ferror (in)) {
-                               error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg;
-                               fclose (in);
-                               fclose (out);
+                       } else {
+                               error << string_compose (_("Could not open %1 for writing session template"), out_path)
+                                       << endmsg;
+                               fclose(in);
                                return -1;
                        }
-                       if (charsRead == 0) {
-                               break;
-                       }
-                       new_session.write (buf, charsRead);
-               }
-               fclose (in);
 
-               string file_contents = new_session.str();
-               size_t writeSize = file_contents.length();
-               if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) {
-                       error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg;
-                       fclose (out);
+               } else {
+                       error << string_compose (_("Could not open session template %1 for reading"), in_path)
+                               << endmsg;
                        return -1;
                }
-               fclose (out);
 
-               _is_new = false;
-
-               if (!ARDOUR::Profile->get_trx()) {
-                       /* Copy plugin state files from template to new session */
-                       std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
-                       copy_recurse (template_plugins, plugins_dir ());
-               }
-
-               return 0;
        }
 
        if (Profile->get_trx()) {