diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc index 7943e40b74..f527c9a473 100644 --- a/libs/pbd/filesystem.cc +++ b/libs/pbd/filesystem.cc @@ -136,6 +136,19 @@ remove(const path & p) return true; } +void +rename (const path & from_path, const path & to_path) +{ + // g_rename is a macro that evaluates to ::rename on + // POSIX systems, without the global namespace qualifier + // it would evaluate to a recursive call(if it compiled) + if ( ::g_rename( from_path.to_string().c_str(), + to_path.to_string().c_str() ) == -1 ) + { + throw filesystem_error(g_strerror(errno), errno); + } +} + void copy_file(const path & from_path, const path & to_path) { diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h index 7ccc451eac..2d21a3fafc 100644 --- a/libs/pbd/pbd/filesystem.h +++ b/libs/pbd/pbd/filesystem.h @@ -162,6 +162,11 @@ bool create_directories(const path & p); */ bool remove(const path & p); +/** + * Renames from_path to to_path as if by the glib function g_rename. + */ +void rename (const path& from_path, const path& to_path); + /** * Attempt to copy the contents of the file from_path to a new file * at path to_path.