mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
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:
parent
4d99495361
commit
0634e461fb
18 changed files with 137 additions and 5 deletions
|
@ -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 ********/
|
||||
|
|
|
@ -146,6 +146,8 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
uint32_t freeDiskSpaceLimit() const ;
|
||||
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
bool FileCancel(std::string hash);
|
||||
bool FileControl(std::string hash, uint32_t flags);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ftfilecreator.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <util/rsdiscspace.h>
|
||||
|
||||
/*******
|
||||
* #define FILE_DEBUG 1
|
||||
|
@ -93,6 +94,9 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||
/* dodgey checking outside of mutex... much check again inside FileAttrs(). */
|
||||
/* Check File is open */
|
||||
|
||||
if(!RsDiscSpace::checkForDiscSpace(RS_PARTIALS_DIRECTORY))
|
||||
return false ;
|
||||
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (fd == NULL)
|
||||
|
|
|
@ -272,6 +272,14 @@ bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStr
|
|||
{
|
||||
return mFtController->setChunkStrategy(hash,s);
|
||||
}
|
||||
uint32_t ftServer::freeDiskSpaceLimit()const
|
||||
{
|
||||
return mFtController->freeDiskSpaceLimit() ;
|
||||
}
|
||||
void ftServer::setFreeDiskSpaceLimit(uint32_t s)
|
||||
{
|
||||
mFtController->setFreeDiskSpaceLimit(s) ;
|
||||
}
|
||||
void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
||||
{
|
||||
mFtController->setDefaultChunkStrategy(s) ;
|
||||
|
|
|
@ -127,6 +127,8 @@ virtual bool FileClearCompleted();
|
|||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
|
||||
/***
|
||||
|
|
|
@ -297,6 +297,7 @@ HEADERS += dbase/cachestrapper.h \
|
|||
tcponudp/udpsorter.h \
|
||||
upnp/upnphandler.h \
|
||||
util/folderiterator.h \
|
||||
util/rsdiscspace.h \
|
||||
util/rsdebug.h \
|
||||
util/rsdir.h \
|
||||
util/rsnet.h \
|
||||
|
@ -414,6 +415,7 @@ SOURCES += \
|
|||
tcponudp/tou_net.cc \
|
||||
tcponudp/udplayer.cc \
|
||||
util/folderiterator.cc \
|
||||
util/rsdiscspace.cc \
|
||||
util/rsdebug.cc \
|
||||
util/rsdir.cc \
|
||||
util/rsnet.cc \
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "pqi/pqistore.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
#include <errno.h>
|
||||
#include <util/rsdiscspace.h>
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
|
@ -86,6 +87,9 @@ void p3ConfigMgr::tick()
|
|||
|
||||
void p3ConfigMgr::saveConfiguration()
|
||||
{
|
||||
if(!RsDiscSpace::checkForDiscSpace(RS_CONFIG_DIRECTORY))
|
||||
return ;
|
||||
|
||||
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
|
|
@ -115,6 +115,8 @@ class RsFiles
|
|||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
|
||||
virtual uint32_t freeDiskSpaceLimit() const =0;
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0;
|
||||
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
|
||||
virtual bool FileClearCompleted() = 0;
|
||||
|
||||
|
|
|
@ -207,6 +207,7 @@ class NotifyBase
|
|||
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
||||
virtual void notifyOwnAvatarChanged() {}
|
||||
virtual void notifyOwnStatusMessageChanged() {}
|
||||
virtual void notifyDiskFull(uint32_t /* location */,uint32_t /* size limit in MB */) {}
|
||||
|
||||
virtual std::string askForPassword(const std::string& key_details,bool prev_is_bad) { return "" ;}
|
||||
};
|
||||
|
|
|
@ -47,6 +47,12 @@ const uint32_t FT_STATE_COMPLETE = 0x0004 ;
|
|||
const uint32_t FT_STATE_QUEUED = 0x0005 ;
|
||||
const uint32_t FT_STATE_PAUSED = 0x0006 ;
|
||||
|
||||
// These constants are used by RsDiscSpace
|
||||
//
|
||||
const uint32_t RS_PARTIALS_DIRECTORY = 0x0000 ;
|
||||
const uint32_t RS_DOWNLOAD_DIRECTORY = 0x0001 ;
|
||||
const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ;
|
||||
|
||||
class TransferInfo
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue