diff --git a/libretroshare/src/dbase/cachestrapper.cc b/libretroshare/src/dbase/cachestrapper.cc index 307aa103a..6c95009d8 100644 --- a/libretroshare/src/dbase/cachestrapper.cc +++ b/libretroshare/src/dbase/cachestrapper.cc @@ -699,7 +699,18 @@ bool CacheStrapper::findCache(std::string hash, CacheData &data) const return false; } +bool CacheStrapper::CacheExist(CacheData& data){ + std::string filename = data.path + "/" + data.name; + FILE* file = NULL; + file = fopen(filename.c_str(), "r"); + + if(file == NULL) + return false; + + fclose(file); + return true; +} /***************************************************************************/ /****************************** CONFIGURATION HANDLING *********************/ @@ -746,7 +757,8 @@ std::list CacheStrapper::saveList(bool &cleanup) for(tit = ownTmp.begin(); tit != ownTmp.end(); tit++) { - ownCaches.push_back(tit->second); + if(CacheExist(tit->second)) + ownCaches.push_back(tit->second); } } diff --git a/libretroshare/src/dbase/cachestrapper.h b/libretroshare/src/dbase/cachestrapper.h index 9c0c45f3e..8b7223ed0 100644 --- a/libretroshare/src/dbase/cachestrapper.h +++ b/libretroshare/src/dbase/cachestrapper.h @@ -303,6 +303,12 @@ bool findCache(std::string hash, CacheData &data) const; void listCaches(std::ostream &out); void listPeerStatus(std::ostream &out); +/** + * Checks if the cache physically exist at path given + * @param data + * @return whether it exists or not + */ +bool CacheExist(CacheData& data); /* Config */ protected: diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index ff97eaa10..b7fcefe48 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -734,6 +734,8 @@ void p3GroupDistrib::locked_publishPendingMsgs() CacheData newCache; time_t now = time(NULL); + bool ok = true; // hass msg/cache file been written successfully + newCache.pid = mOwnId; newCache.cid.type = CacheSource::getCacheType(); newCache.cid.subid = locked_determineCacheSubId(); @@ -770,7 +772,10 @@ void p3GroupDistrib::locked_publishPendingMsgs() resave = true; } - store->SendItem(*it); /* deletes it */ + if(!store->SendItem(*it)) /* deletes it */ + { + ok &= false; + } } /* Extract File Information from pqistore */ @@ -788,6 +793,7 @@ void p3GroupDistrib::locked_publishPendingMsgs() if(!RsDirUtil::renameFile(filenametmp,filename)) { std::ostringstream errlog; + ok &= false; #ifdef WIN32 errlog << "Error " << GetLastError() ; #else @@ -800,9 +806,12 @@ void p3GroupDistrib::locked_publishPendingMsgs() mLastPublishTime = now; /* push file to CacheSource */ - refreshCache(newCache); - if (resave) + if(ok) + refreshCache(newCache); + + + if (ok && resave) { #ifdef DISTRIB_DEBUG std::cerr << "p3GroupDistrib::locked_publishPendingMsgs() Indicate Save Data Changed";