Add function sys::rename to pbd/filesystem.h/cc. Renames a file, uses g_rename.
authorTim Mayberry <mojofunk@gmail.com>
Sun, 9 Sep 2007 10:04:54 +0000 (10:04 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Sun, 9 Sep 2007 10:04:54 +0000 (10:04 +0000)
git-svn-id: svn://localhost/ardour2/trunk@2431 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/pbd/filesystem.cc
libs/pbd/pbd/filesystem.h

index 7943e40b7430cef9ae20b28d87ae102b5f66b5d7..f527c9a473b35dee01d5a028e04fe1e99a3bdb1b 100644 (file)
@@ -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)
 {
index 7ccc451eaccc1554d686386ebfbbde002789256b..2d21a3fafceca338e4af650074cf049e20330ab1 100644 (file)
@@ -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.