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
This commit is contained in:
Sampo Savolainen 2006-08-01 22:00:40 +00:00
parent c220ec3928
commit 0851f88d9d
2 changed files with 51 additions and 14 deletions

View file

@ -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;

View file

@ -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;
}