]> git.mxchange.org Git - simgear.git/commitdiff
SGPath rename wrapper. Let's see what Win32 makes of it.
authorJames Turner <zakalawe@mac.com>
Fri, 21 Oct 2011 08:36:33 +0000 (09:36 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 21 Oct 2011 08:36:33 +0000 (09:36 +0100)
simgear/misc/sg_path.cxx
simgear/misc/sg_path.hxx

index 53504a2013adc84a6b2a977092d46ad88c38ead2..bff1a61c17481c5a7ebc407d023a832ba79e91b7 100644 (file)
@@ -471,3 +471,16 @@ bool SGPath::operator!=(const SGPath& other) const
     return (path != other.path);
 }
 
+bool SGPath::rename(const SGPath& newName)
+{
+    if (::rename(c_str(), newName.c_str()) != 0) {
+        SG_LOG(SG_IO, SG_WARN, "renamed failed: from " << str() << " to " << newName.str()
+            << " reason: " << strerror(errno));
+        return false;
+    }
+    
+    path = newName.path;
+    _cached = false;
+    return true;
+}
+
index 27b375d9d0ff8fe1e59aac52f8c840bc33f1f99b..e71c5f54d9a55e7312e9b7ef8ac20102edddd380 100644 (file)
@@ -213,6 +213,13 @@ public:
      * modification time of the file
      */
     time_t modTime() const;
+    
+    /**
+     * rename the file / directory we point at, to a new name
+     * this may fail if the new location is on a different volume / share,
+     * or if the destination already exists, or is not writeable
+     */
+    bool rename(const SGPath& newName);
 private:
 
     void fix();