implemented a safety check for low disc space, and safe drop of disk access if too low

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2968 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-05-21 20:49:48 +00:00
parent 4d99495361
commit 0634e461fb
18 changed files with 137 additions and 5 deletions

View file

@ -38,6 +38,7 @@
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#endif
#include "util/rsdiscspace.h"
#include "ft/ftcontroller.h"
@ -56,6 +57,7 @@
#include "serialiser/rsconfigitems.h"
#include <stdio.h>
#include <sstream>
/******
* #define CONTROL_DEBUG 1
@ -1812,6 +1814,7 @@ const std::string download_dir_ss("DOWN_DIR");
const std::string partial_dir_ss("PART_DIR");
const std::string share_dwl_dir("SHARE_DWL_DIR");
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
const std::string free_space_limit_ss("FREE_SPACE_LIMIT");
/* p3Config Interface */
@ -1845,6 +1848,11 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
configMap[default_chunk_strategy_ss] = (mDefaultChunkStrategy==FileChunksInfo::CHUNK_STRATEGY_STREAMING) ? "STREAMING" : "RANDOM";
std::ostringstream s ;
s << RsDiscSpace::freeSpaceLimit();
configMap[free_space_limit_ss] = s.str() ;
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
/* Convert to TLV */
@ -2043,9 +2051,33 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
std::cerr << "**** ERROR ***: Unknown value for default chunk strategy in keymap." << std::endl ;
}
if (configMap.end() != (mit = configMap.find(free_space_limit_ss)))
{
std::istringstream in(mit->second) ;
uint32_t size ;
in >> size ;
std::cerr << "have read a size limit of " << size <<" MB" << std::endl ;
RsDiscSpace::setFreeSpaceLimit(size) ;
}
return true;
}
void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb)
{
RsDiscSpace::setFreeSpaceLimit(size_in_mb) ;
IndicateConfigChanged() ;
}
uint32_t ftController::freeDiskSpaceLimit() const
{
return RsDiscSpace::freeSpaceLimit() ;
}
FileChunksInfo::ChunkStrategy ftController::defaultChunkStrategy()
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/