diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-05-07 12:06:49 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-05-07 12:06:49 -0400 |
commit | e902029b26a6e36befaeb9366a19d3796fa53a95 (patch) | |
tree | 64d71e726eb3cd471d29ad8782ccff87dd930db1 | |
parent | 31acba8305e6e624c7cd13d7153b21814265e08d (diff) |
fix Session::rename()
-rw-r--r-- | libs/ardour/ardour/session.h | 2 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 111 |
2 files changed, 53 insertions, 60 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index c44adec501..b6bbee9d58 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -430,7 +430,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop void remove_state (std::string snapshot_name); void rename_state (std::string old_name, std::string new_name); void remove_pending_capture_state (); - int rename (const std::string&, bool after_copy = false); + int rename (const std::string&); bool get_nsm_state () const { return _under_nsm_control; } void set_nsm_state (bool state) { _under_nsm_control = state; } bool save_default_options (); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 780c5802f0..84518592a9 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3631,7 +3631,7 @@ Session::solo_cut_control() const } int -Session::rename (const std::string& new_name, bool after_copy) +Session::rename (const std::string& new_name) { string legal_name = legalize_for_path (new_name); string new_path; @@ -3666,37 +3666,34 @@ Session::rename (const std::string& new_name, bool after_copy) * already exist ... */ - if (!after_copy) { - - for (vector<space_and_path>::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { - - oldstr = (*i).path; - - /* this is a stupid hack because Glib::path_get_dirname() is - * lexical-only, and so passing it /a/b/c/ gives a different - * result than passing it /a/b/c ... - */ - - if (oldstr[oldstr.length()-1] == G_DIR_SEPARATOR) { - oldstr = oldstr.substr (0, oldstr.length() - 1); - } - - string base = Glib::path_get_dirname (oldstr); - - newstr = Glib::build_filename (base, legal_name); - - cerr << "Looking for " << newstr << endl; - - if (Glib::file_test (newstr, Glib::FILE_TEST_EXISTS)) { - cerr << " exists\n"; - return -1; - } + for (vector<space_and_path>::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { + + oldstr = (*i).path; + + /* this is a stupid hack because Glib::path_get_dirname() is + * lexical-only, and so passing it /a/b/c/ gives a different + * result than passing it /a/b/c ... + */ + + if (oldstr[oldstr.length()-1] == G_DIR_SEPARATOR) { + oldstr = oldstr.substr (0, oldstr.length() - 1); + } + + string base = Glib::path_get_dirname (oldstr); + + newstr = Glib::build_filename (base, legal_name); + + cerr << "Looking for " << newstr << endl; + + if (Glib::file_test (newstr, Glib::FILE_TEST_EXISTS)) { + cerr << " exists\n"; + return -1; } } /* Session dirs */ - first = false; + first = true; for (vector<space_and_path>::iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { @@ -3713,20 +3710,16 @@ Session::rename (const std::string& new_name, bool after_copy) oldstr = oldstr.substr (0, oldstr.length() - 1); } - if (first) { - newstr = _path; - } else { - string base = Glib::path_get_dirname (oldstr); - newstr = Glib::build_filename (base, legal_name); - } + string base = Glib::path_get_dirname (oldstr); + newstr = Glib::build_filename (base, legal_name); - if (!after_copy) { - cerr << "Rename " << oldstr << " => " << newstr << endl; - if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { - cerr << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endl; - error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; - return 1; - } + cerr << "for " << oldstr << " new dir = " << newstr << endl; + + cerr << "Rename " << oldstr << " => " << newstr << endl; + if (::g_rename (oldstr.c_str(), newstr.c_str()) != 0) { + cerr << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endl; + error << string_compose (_("renaming %s as %2 failed (%3)"), oldstr, newstr, g_strerror (errno)) << endmsg; + return 1; } /* Reset path in "session dirs" */ @@ -3747,7 +3740,9 @@ Session::rename (const std::string& new_name, bool after_copy) string old_interchange_dir; string new_interchange_dir; - /* use newstr here because we renamed the path that used to be oldstr to newstr above */ + /* use newstr here because we renamed the path + * (folder/directory) that used to be oldstr to newstr above + */ v.push_back (newstr); v.push_back (interchange_dir_name); @@ -3779,8 +3774,8 @@ Session::rename (const std::string& new_name, bool after_copy) /* state file */ - oldstr = Glib::build_filename (new_path, _current_snapshot_name) + statefile_suffix; - newstr= Glib::build_filename (new_path, legal_name) + statefile_suffix; + oldstr = Glib::build_filename (new_path, _current_snapshot_name + statefile_suffix); + newstr= Glib::build_filename (new_path, legal_name + statefile_suffix); cerr << "Rename " << oldstr << " => " << newstr << endl; @@ -3806,27 +3801,25 @@ Session::rename (const std::string& new_name, bool after_copy) } } - if (!after_copy) { - /* remove old name from recent sessions */ - remove_recent_sessions (_path); - _path = new_path; - - /* update file source paths */ - - for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) { - boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (i->second); - if (fs) { - string p = fs->path (); - boost::replace_all (p, old_sources_root, _session_dir->sources_root()); - fs->set_path (p); - SourceFactory::setup_peakfile(i->second, true); - } + /* remove old name from recent sessions */ + remove_recent_sessions (_path); + _path = new_path; + + /* update file source paths */ + + for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) { + boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (i->second); + if (fs) { + string p = fs->path (); + boost::replace_all (p, old_sources_root, _session_dir->sources_root()); + fs->set_path (p); + SourceFactory::setup_peakfile(i->second, true); } } _current_snapshot_name = new_name; _name = new_name; - + set_dirty (); /* save state again to get everything just right */ |