diff --git a/libretroshare/src/pqi/p3cfgmgr.cc b/libretroshare/src/pqi/p3cfgmgr.cc index f854c8f4e..33593550c 100644 --- a/libretroshare/src/pqi/p3cfgmgr.cc +++ b/libretroshare/src/pqi/p3cfgmgr.cc @@ -29,6 +29,8 @@ #include "pqi/pqibin.h" #include "pqi/pqiarchive.h" #include "pqi/pqistreamer.h" +#include "pqi/pqinotify.h" +#include #include "serialiser/rsconfigitems.h" @@ -505,8 +507,26 @@ bool p3Config::saveConfiguration() std::cerr << "renaming " << fnametmp.c_str() << " to " << fname.c_str() << std::endl ; - if(0 != rename(fnametmp.c_str(),fname.c_str())) +#ifdef WIN32 + std::wstring from,to ; + for(std::string::const_iterator it = fnametmp.begin(); it!=fnametmp.end();++it) from += *it; + for(std::string::const_iterator it = fname .begin(); it!=fname .end();++it) to += *it; + + int err = !MoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING) ; +#else + int err = rename(fnametmp.c_str(),fname.c_str()); +#endif + if(0 != err) + { + std::ostringstream errlog; +#ifdef WIN32 + errlog << err << ", " << errno ; +#else + errlog << err << :", " << GetLastError() ; +#endif + getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + fname + ": got error "+errlog.str()); return false ; + } std::cerr << "Successfully wrote p3config file " << fname.c_str() << std::endl ; /* else okay */ diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 2ad6888e0..9ae6a1a34 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -459,7 +459,15 @@ bool p3ChatService::saveConfiguration() setHash(out->gethash()); delete pa_out; +#ifdef WIN32 + std::wstring from,to ; + for(std::string::const_iterator it = msgfiletmp.begin(); it!=msgfiletmp.end();++it) from += *it; + for(std::string::const_iterator it = msgfile .begin(); it!=msgfile .end();++it) to += *it; + + if(!MoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING)) +#else if(0 != rename(msgfiletmp.c_str(),msgfile.c_str())) +#endif return false ; return true; diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 81c575e3d..0b70a2a85 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -788,7 +788,15 @@ void p3GroupDistrib::locked_publishPendingMsgs() mPendingPublish.clear(); delete streamer; +#ifdef WIN32 + std::wstring from,to ; + for(std::string::const_iterator it = filenametmp.begin(); it!=filenametmp.end();++it) from += *it; + for(std::string::const_iterator it = filename .begin(); it!=filename .end();++it) to += *it; + + if(!MoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING)) +#else if(0 != rename(filenametmp.c_str(),filename.c_str())) +#endif std::cerr << "Could not rename file " << filenametmp << " into " << filename << std::endl ; else std::cerr << "Successfull wrote file " << filename << std::endl ; @@ -925,7 +933,15 @@ void p3GroupDistrib::publishDistribGroups() /* cleanup */ delete streamer; +#ifdef WIN32 + std::wstring from,to ; + for(std::string::const_iterator it = filenametmp.begin(); it!=filenametmp.end();++it) from += *it; + for(std::string::const_iterator it = filename .begin(); it!=filename .end();++it) to += *it; + + if(!MoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING)) +#else if(0 != rename(filenametmp.c_str(),filename.c_str())) +#endif std::cerr << "Could not rename file " << filenametmp << " into " << filename << std::endl ; else std::cerr << "Successfull wrote file " << filename << std::endl ; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 0dc60d5bd..baee43b05 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -289,7 +289,15 @@ bool p3MsgService::saveConfiguration() if(!written) return false ; +#ifdef WIN32 + std::wstring from,to ; + for(std::string::const_iterator it = msgfiletmp.begin(); it!=msgfiletmp.end();++it) from += *it; + for(std::string::const_iterator it = msgfile .begin(); it!=msgfile .end();++it) to += *it; + + if(!MoveFileEx(from.c_str(), to.c_str(), MOVEFILE_REPLACE_EXISTING)) +#else if(0 != rename(msgfiletmp.c_str(),msgfile.c_str())) +#endif return false ; return true;