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)
// approximately atomic delete + rename operation
SGPath cacheName(localPath);
cacheName.append(DAV_CACHE_NAME);
- if (cacheName.exists()) {
- cacheName.remove();
- }
p.rename(cacheName);
}
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);
}
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));