From f26f3b606d2d10c3b1ff1613731e640abe118a26 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 26 Oct 2013 21:03:00 +0100 Subject: [PATCH] Fix handling of SGPath::rename Windows handling of ::rename differs from POSIX when the new name exists. Check for this case on Windows and remove the file manually. (This allows a work-around in SVNDirectory to be removed) --- simgear/io/SVNDirectory.cxx | 3 --- simgear/misc/sg_path.cxx | 11 ++++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/simgear/io/SVNDirectory.cxx b/simgear/io/SVNDirectory.cxx index 923993ac..6983ef87 100644 --- a/simgear/io/SVNDirectory.cxx +++ b/simgear/io/SVNDirectory.cxx @@ -177,9 +177,6 @@ void SVNDirectory::writeCache() // approximately atomic delete + rename operation SGPath cacheName(localPath); cacheName.append(DAV_CACHE_NAME); - if (cacheName.exists()) { - cacheName.remove(); - } p.rename(cacheName); } diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 4e11de3c..cc71a9af 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -461,7 +461,8 @@ bool SGPath::remove() int err = ::unlink(c_str()); if (err) { SG_LOG(SG_IO, SG_WARN, "file remove failed: (" << str() << ") " << strerror(errno)); - } + } + _cached = false; // stat again if required return (err == 0); } @@ -483,6 +484,14 @@ bool SGPath::operator!=(const SGPath& other) const bool SGPath::rename(const SGPath& newName) { +#ifdef SG_WINDOWS + if (newName.exists()) { + SGPath r(newName); + if (!r.remove()) { + return false; + } + } +#endif if (::rename(c_str(), newName.c_str()) != 0) { SG_LOG(SG_IO, SG_WARN, "renamed failed: from " << str() << " to " << newName.str() << " reason: " << strerror(errno)); -- 2.39.5