diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-01 09:46:18 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-01 09:46:18 -0400 |
commit | 23e7cf10191270d70357ccf0ed9294f020c7b7ab (patch) | |
tree | ddc1fc4d1914fe3de3de79c194c5dd859915bd2a /libs/ardour/file_source.cc | |
parent | 4244ea65460b865f946551aace9b74191b26be4b (diff) | |
parent | b660bc8ae92d19aedf0165815432b77a0c6170c4 (diff) |
merge with master.
Manually resolved conflicts in import.cc and session.cc
Diffstat (limited to 'libs/ardour/file_source.cc')
-rw-r--r-- | libs/ardour/file_source.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc index ae63bd55b1..8c41f981b9 100644 --- a/libs/ardour/file_source.cc +++ b/libs/ardour/file_source.cc @@ -214,7 +214,7 @@ FileSource::move_to_trash (const string& trash_dir_name) if (move_dependents_to_trash() != 0) { /* try to back out */ - rename (newpath.c_str(), _path.c_str()); + ::rename (newpath.c_str(), _path.c_str()); return -1; } @@ -572,3 +572,28 @@ FileSource::is_stub () const return true; } +int +FileSource::rename (const string& newpath) +{ + Glib::Threads::Mutex::Lock lm (_lock); + string oldpath = _path; + + // Test whether newpath exists, if yes notify the user but continue. + if (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS)) { + error << string_compose (_("Programming error! %1 tried to rename a file over another file! It's safe to continue working, but please report this to the developers."), PROGRAM_NAME) << endmsg; + return -1; + } + + if (Glib::file_test (oldpath.c_str(), Glib::FILE_TEST_EXISTS)) { + /* rename only needed if file exists on disk */ + if (::rename (oldpath.c_str(), newpath.c_str()) != 0) { + error << string_compose (_("cannot rename file %1 to %2 (%3)"), oldpath, newpath, strerror(errno)) << endmsg; + return -1; + } + } + + _name = Glib::path_get_basename (newpath); + _path = newpath; + + return 0; +} |