mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
improved file list saving by saving into a temporary file before renaming (Should be ported to trunk)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.4.x@1936 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4a39adc90a
commit
b5cd798a44
@ -556,7 +556,7 @@ void FileIndexMonitor::updateCycle()
|
||||
if (fiMods)
|
||||
{
|
||||
/* store to the cacheDirectory */
|
||||
fiMutex.lock(); { /* LOCKED DIRS */
|
||||
RsStackMutex mt(fiMutex) ;/* LOCKED DIRS */
|
||||
|
||||
std::string path = getCacheDir();
|
||||
std::ostringstream out;
|
||||
@ -575,34 +575,54 @@ void FileIndexMonitor::updateCycle()
|
||||
std::string calchash;
|
||||
uint64_t size;
|
||||
|
||||
fi.saveIndex(fname, calchash, size);
|
||||
std::string fnametmp = fname+".tmp" ;
|
||||
|
||||
if(fi.saveIndex(fnametmp, calchash, size))
|
||||
{
|
||||
std::cerr << "renaming " << fnametmp.c_str() << " to " << fname.c_str() << std::endl ;
|
||||
|
||||
if(!RsDirUtil::renameFile(fnametmp,fname))
|
||||
{
|
||||
std::ostringstream errlog;
|
||||
#ifdef WIN32
|
||||
errlog << "Error " << GetLastError() ;
|
||||
#else
|
||||
errlog << "Error " << errno ;
|
||||
#endif
|
||||
std::cerr << "fimonitor::updateCycle(): ERROR: File rename error: got error "+errlog.str() << std::endl ;
|
||||
return ;
|
||||
}
|
||||
|
||||
std::cerr << "Successfully wrote p3config file " << fname.c_str() << std::endl ;
|
||||
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::updateCycle() saved with hash:" << calchash;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "FileIndexMonitor::updateCycle() saved with hash:" << calchash;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* should clean up the previous cache.... */
|
||||
/* should clean up the previous cache.... */
|
||||
|
||||
/* flag as new info */
|
||||
CacheData data;
|
||||
data.pid = fi.root->id;
|
||||
data.cid.type = getCacheType();
|
||||
data.cid.subid = 0;
|
||||
data.path = path;
|
||||
data.name = tmpname;
|
||||
data.hash = calchash;
|
||||
data.size = size;
|
||||
data.recvd = time(NULL);
|
||||
/* flag as new info */
|
||||
CacheData data;
|
||||
data.pid = fi.root->id;
|
||||
data.cid.type = getCacheType();
|
||||
data.cid.subid = 0;
|
||||
data.path = path;
|
||||
data.name = tmpname;
|
||||
data.hash = calchash;
|
||||
data.size = size;
|
||||
data.recvd = time(NULL);
|
||||
|
||||
updateCache(data);
|
||||
updateCache(data);
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::updateCycle() called updateCache()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "FileIndexMonitor::updateCycle() called updateCache()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||
}
|
||||
else
|
||||
std::cerr << "fimonitor::updateCycle(): ERROR: Could not save file index file!! Check permissions and disk availability" << std::endl ;
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -913,6 +913,9 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
|
||||
/* finally, save to file */
|
||||
file << oss.str();
|
||||
|
||||
if(file.fail())
|
||||
return 0 ;
|
||||
|
||||
/* get the size out */
|
||||
size=file.tellp();
|
||||
file.close();
|
||||
|
Loading…
Reference in New Issue
Block a user