summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSampo Savolainen <v2@iki.fi>2006-08-01 22:00:40 +0000
committerSampo Savolainen <v2@iki.fi>2006-08-01 22:00:40 +0000
commit0851f88d9d17f9e23c4c87e61c179f0b05a87b44 (patch)
tree8a63225d659bb019434f392d903c5d87028223d7
parentc220ec3928869581e71977856b4b1e8ec94114de (diff)
Fixed a nasty sound file overwrite issue due to how stub rec files were
renamed when the track they were associated with was renamed. Also added a safeguard to check whether the renaming destination location exists already. git-svn-id: svn://localhost/ardour2/trunk@741 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--libs/ardour/audiofilesource.cc6
-rw-r--r--libs/ardour/session.cc59
2 files changed, 51 insertions, 14 deletions
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index d3d870865f..ee35f3068a 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -609,6 +609,12 @@ AudioFileSource::set_name (string newname, bool destructive)
return -1;
}
+ // Test whether newpath exists, if yes notify the user but continue.
+ if (access(newpath.c_str(),F_OK) == 0) {
+ error << _("Programming error! Ardour tried to rename a file over another file! It's safe to continue working, but please report this to the developers.") << endmsg;
+ return -1;
+ }
+
if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
error << string_compose (_("cannot rename audio file for %1 to %2"), _name, newpath) << endmsg;
return -1;
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 63797c4edd..806ec3b17f 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -2767,12 +2767,13 @@ Session::change_audio_path_by_name (string path, string oldname, string newname,
the task here is to replace NAME with the new name.
*/
- /* find last slash */
-
string dir;
string suffix;
string::size_type slash;
string::size_type dash;
+ string::size_type postfix;
+
+ /* find last slash */
if ((slash = path.find_last_of ('/')) == string::npos) {
return "";
@@ -2786,11 +2787,41 @@ Session::change_audio_path_by_name (string path, string oldname, string newname,
return "";
}
- suffix = path.substr (dash);
+ suffix = path.substr (dash+1);
+
+ // Suffix is now everything after the dash. Now we need to eliminate
+ // the nnnnn part, which is done by either finding a '%' or a '.'
+
+ postfix = suffix.find_last_of ("%");
+ if (postfix == string::npos) {
+ postfix = suffix.find_last_of ('.');
+ }
+
+ if (postfix != string::npos) {
+ suffix = suffix.substr (postfix);
+ } else {
+ error << "Logic error in Session::change_audio_path_by_name(), please report to the developers" << endl;
+ return "";
+ }
+
+ const uint32_t limit = 10000;
+ char buf[PATH_MAX+1];
+
+ for (uint32_t cnt = 1; cnt <= limit; ++cnt) {
+
+ snprintf (buf, sizeof(buf), "%s%s-%u%s", dir.c_str(), newname.c_str(), cnt, suffix.c_str());
+
+ if (access (buf, F_OK) != 0) {
+ path = buf;
+ break;
+ }
+ path = "";
+ }
+
+ if (path == "") {
+ error << "FATAL ERROR! Could not find a " << endl;
+ }
- path = dir;
- path += new_legalized;
- path += suffix;
}
return path;
@@ -2813,20 +2844,20 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool
*/
for (cnt = (destructive ? ++destructive_index : 1); cnt <= limit; ++cnt) {
-
+
vector<space_and_path>::iterator i;
uint32_t existing = 0;
-
+
for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
-
+
spath = (*i).path;
-
+
if (destructive) {
spath += tape_dir_name;
} else {
spath += sound_dir_name;
}
-
+
if (destructive) {
if (nchan < 2) {
snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav", spath.c_str(), cnt, legalized.c_str());
@@ -2842,10 +2873,10 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool
snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav", spath.c_str(), cnt, legalized.c_str());
}
} else {
-
+
spath += '/';
spath += legalized;
-
+
if (nchan < 2) {
snprintf (buf, sizeof(buf), "%s-%u.wav", spath.c_str(), cnt);
} else if (nchan == 2) {
@@ -2865,7 +2896,7 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool
existing++;
}
}
-
+
if (existing == 0) {
break;
}