mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-05 23:55:35 -04:00
added code to avoid corruption of bdboot.txt: first write to tmp file then move the file. Refers on Windows utf16ToUtf8 from libretroshare. This forward reference can be improved.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5434 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
21e97a47df
commit
c3db4dacf7
4 changed files with 68 additions and 1 deletions
49
libbitdht/src/util/bdfile.cc
Normal file
49
libbitdht/src/util/bdfile.cc
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "bdfile.h"
|
||||
|
||||
namespace librs {
|
||||
namespace util {
|
||||
bool ConvertUtf8ToUtf16(const std::string& source, std::wstring& dest) ;
|
||||
}
|
||||
}
|
||||
|
||||
bool bdFile::renameFile(const std::string& from, const std::string& to)
|
||||
{
|
||||
int loops = 0;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring f;
|
||||
librs::util::ConvertUtf8ToUtf16(from, f);
|
||||
std::wstring t;
|
||||
librs::util::ConvertUtf8ToUtf16(to, t);
|
||||
|
||||
while (!MoveFileEx(f.c_str(), t.c_str(), MOVEFILE_REPLACE_EXISTING))
|
||||
#else
|
||||
std::string f(from),t(to) ;
|
||||
|
||||
while (rename(from.c_str(), to.c_str()) < 0)
|
||||
#endif
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (GetLastError() != ERROR_ACCESS_DENIED)
|
||||
#else
|
||||
if (errno != EACCES)
|
||||
#endif
|
||||
/* set errno? */
|
||||
return false ;
|
||||
#ifdef WIN32
|
||||
Sleep(100000); /* us */
|
||||
#else
|
||||
usleep(100000); /* us */
|
||||
#endif
|
||||
|
||||
if (loops >= 30)
|
||||
return false ;
|
||||
|
||||
loops++;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue