From b99c6c6e1d5a2f8f653f64e1ee3788f77a11a120 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Sat, 19 May 2007 11:31:27 +0000 Subject: When loading sessions, create any missing session directories rather than throwing an exception. Change the meaning of the return value of SessionDirectory::create and add documentation to explain usage. Add PBD::sys::filesystem_error to indicate a filesystem error and throw it where necessary. Change the semantics of PBD::sys::create_directory/ies functions to match boost::filesystem git-svn-id: svn://localhost/ardour2/trunk@1884 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session_directory.h | 11 +++++++-- libs/ardour/session.cc | 43 +++++++++++++++++++++++++++------- libs/ardour/session_directory.cc | 24 ++++++++++++------- 3 files changed, 58 insertions(+), 20 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/session_directory.h b/libs/ardour/ardour/session_directory.h index 131812c130..d23c135e0b 100644 --- a/libs/ardour/ardour/session_directory.h +++ b/libs/ardour/ardour/session_directory.h @@ -80,8 +80,15 @@ public: bool is_valid () const; /** - * @return true If a new session directory and all the - * subdirectories were created, otherwise false. + * Create the session directory and all the subdirectories. + * + * @throw PBD::sys::filesystem_error if the directories were + * not able to be created. + * + * @return true If a new session directory was created, otherwise + * (if it already existed) false. + * + * @post is_valid () */ bool create (); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 1fa5d47ac0..3f1760c88a 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -133,23 +133,48 @@ Session::Session (AudioEngine &eng, SessionDirectory sdir(fullpath); - if (mix_template && - sdir.create() && - create_session_file_from_template (*mix_template)) { + if(mix_template) { + // try and create a new session directory + try + { + if(!sdir.create()) { + // an existing session. + // throw a_more_meaningful_exception() + destroy (); + throw failed_constructor (); + } + } + catch(sys::filesystem_error& ex) + { + destroy (); + throw failed_constructor (); + } + + if(!create_session_file_from_template (*mix_template)) { + destroy (); + throw failed_constructor (); + } cerr << "Creating session " << fullpath <<" using template" << *mix_template << endl; - - } else if (sdir.is_valid ()) { + } else { + // must be an existing session + try + { + // ensure the necessary session subdirectories exist + // in case the directory structure has changed etc. + sdir.create(); + } + catch(sys::filesystem_error& ex) + { + destroy (); + throw failed_constructor (); + } cerr << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (1)" << endl; - - } else { - destroy (); - throw failed_constructor (); } if (second_stage_init (false)) { diff --git a/libs/ardour/session_directory.cc b/libs/ardour/session_directory.cc index e871b84244..91b2587eb7 100644 --- a/libs/ardour/session_directory.cc +++ b/libs/ardour/session_directory.cc @@ -43,23 +43,29 @@ SessionDirectory::SessionDirectory (const string& session_path) bool SessionDirectory::create () { - if (is_directory (m_root_path)) - { - PBD::error << string_compose(_("Cannot create Session directory at path %1 as it already exists"), m_root_path.to_string()) << endmsg; - return false; - } + bool is_new = false; vector sub_dirs = sub_directories (); for (vector::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) { - if (!create_directories(*i)) + try { - PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), g_strerror (errno)) << endmsg; - return false; + if(create_directories(*i)) { + PBD::info << string_compose(_("Created Session directory at path %1"), (*i).to_string()) << endmsg; + is_new = true; + } + } + catch (PBD::sys::filesystem_error& ex) + { + // log the error + PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), ex.what()) << endmsg; + + // and rethrow + throw ex; } } - return true; + return is_new; } bool -- cgit v1.2.3