Add function PBD::sys::remove as a wrapper to g_unlink
authorTim Mayberry <mojofunk@gmail.com>
Tue, 4 Sep 2007 04:48:04 +0000 (04:48 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 4 Sep 2007 04:48:04 +0000 (04:48 +0000)
API is intended to be indentical(apart from the string type) to boost::filesystem::remove

git-svn-id: svn://localhost/ardour2/trunk@2372 d708f5d6-7413-0410-9779-e7cbd77b26cf

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

index 229b22fcb54ed6e61f1bb6835d9d48f8ee3974fb..aefe6d525cf22635853a0d398f97a8ded17cd803 100644 (file)
@@ -94,6 +94,20 @@ create_directories(const path & p)
        return true;
 }
 
+bool
+remove(const path & p)
+{
+       if(!exists(p)) return false;
+
+       int error = g_unlink (p.to_string().c_str());
+
+       if(error == -1)
+       {
+               throw filesystem_error(g_strerror(errno), errno);
+       }
+       return true;
+}
+
 string
 basename (const path & p)
 {
index 8d4bf8dea974aec4101f4140db27b7d0b872adb7..7eca8a7ed35eed309ef67ed2a8a03e8286dd6706 100644 (file)
@@ -94,6 +94,18 @@ bool create_directory(const path & p);
  */
 bool create_directories(const path & p);
 
+/**
+ * Attempt to delete the file at path p as if by the glib function
+ * g_unlink.
+ *
+ * @return true if file existed prior to removing it, false if file
+ * at p did not exist.
+ *
+ * @throw filesystem_error if removing the file failed for any other
+ * reason other than the file did not exist.
+ */
+bool remove(const path & p);
+
 string basename (const path& p);
 
 } // namespace sys