mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 21:34:10 -05: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
@ -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:
|
||||
|
@ -191,10 +191,10 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
||||
ui.stackPages->add(messagesDialog = new MessagesDialog(ui.stackPages),
|
||||
messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
|
||||
|
||||
#ifndef RS_RELEASE_VERSION
|
||||
#ifndef RS_RELEASE_VERSION
|
||||
ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages),
|
||||
createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BLOGS
|
||||
ui.stackPages->add(blogsFeed = new BlogsDialog(ui.stackPages),
|
||||
@ -292,6 +292,28 @@ MainWindow::~MainWindow()
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::displayDiskSpaceWarning(int loc,int size_limit_mb)
|
||||
{
|
||||
QString locString ;
|
||||
switch(loc)
|
||||
{
|
||||
case RS_PARTIALS_DIRECTORY: locString = "Partials" ;
|
||||
break ;
|
||||
|
||||
case RS_CONFIG_DIRECTORY: locString = "Config" ;
|
||||
break ;
|
||||
|
||||
case RS_DOWNLOAD_DIRECTORY: locString = "Download" ;
|
||||
break ;
|
||||
|
||||
default:
|
||||
std::cerr << "Error: " << __PRETTY_FUNCTION__ << " was called with an unknown parameter loc=" << loc << std::endl ;
|
||||
return ;
|
||||
}
|
||||
QMessageBox::critical(NULL,tr("Low disk space warning"),
|
||||
tr("The disk space in your ")+locString +tr(" directory is running low (current limit is ")+QString::number(size_limit_mb)+tr("MB). \n\n RetroShare will now safely suspend any disk access to this directory. \n\n Please make some free space and click Ok.")) ;
|
||||
}
|
||||
|
||||
/** Creates a tray icon with a context menu and adds it to the system
|
||||
* notification area. */
|
||||
void MainWindow::createTrayIcon()
|
||||
|
@ -138,6 +138,7 @@ public slots:
|
||||
void updateHashingInfo(const QString&) ;
|
||||
void displayErrorMessage(int,int,const QString&) ;
|
||||
void postModDirectories(bool update_local);
|
||||
void displayDiskSpaceWarning(int loc,int size_limit_mb) ;
|
||||
|
||||
protected:
|
||||
/** Default Constructor */
|
||||
|
@ -51,6 +51,13 @@ std::string NotifyQt::askForPassword(const std::string& key_details,bool prev_is
|
||||
return res ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
|
||||
{
|
||||
std::cerr << "Notifyqt:: notified that disk is full" << std::endl ;
|
||||
|
||||
emit diskFull(loc,size_in_mb) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyOwnStatusMessageChanged()
|
||||
{
|
||||
#ifdef NOTIFY_DEBUG
|
||||
|
@ -40,6 +40,8 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
||||
virtual void notifyOwnAvatarChanged() ;
|
||||
virtual void notifyOwnStatusMessageChanged() ;
|
||||
virtual void notifyDiskFull(uint32_t loc,uint32_t size_in_mb) ;
|
||||
|
||||
|
||||
virtual std::string askForPassword(const std::string& key_details,bool prev_is_bad) ;
|
||||
|
||||
@ -63,6 +65,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void ownAvatarChanged() const ;
|
||||
void ownStatusMessageChanged() const ;
|
||||
void errorOccurred(int,int,const QString&) const ;
|
||||
void diskFull(int,int) const ;
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -45,8 +45,11 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
|
||||
else
|
||||
ui._defaultStrategy_CB->setCurrentIndex(1) ;
|
||||
|
||||
ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ;
|
||||
|
||||
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
|
||||
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ;
|
||||
QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ;
|
||||
|
||||
/* Hide platform specific features */
|
||||
#ifdef Q_WS_WIN
|
||||
@ -68,6 +71,11 @@ void TransferPage::updateDefaultStrategy(int i)
|
||||
}
|
||||
}
|
||||
|
||||
void TransferPage::updateDiskSizeLimit(int s)
|
||||
{
|
||||
rsFiles->setFreeDiskSpaceLimit(s) ;
|
||||
}
|
||||
|
||||
void TransferPage::updateQueueSize(int s)
|
||||
{
|
||||
rsFiles->setQueueSize(s) ;
|
||||
|
@ -43,6 +43,7 @@ class TransferPage: public ConfigPage
|
||||
public slots:
|
||||
void updateQueueSize(int) ;
|
||||
void updateDefaultStrategy(int) ;
|
||||
void updateDiskSizeLimit(int) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -19,11 +19,11 @@
|
||||
<property name="title">
|
||||
<string>Transfer options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -38,6 +38,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Safety disk space limit :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@ -75,6 +82,25 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="_diskSpaceLimit_SB">
|
||||
<property name="suffix">
|
||||
<string> MB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@ -92,7 +118,7 @@ p, li { white-space: pre-wrap; }
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-weight:600;">RetroShare</span><span style=" font-size:8pt;"> is capable of transfering data and search requests between peers that are not necessarily friends. This traffic however only transits through a connected list of friends and is anonymous.</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">You can separately setup share flags for each shared directory in the shared files dialog to be:</span></p>
|
||||
<ul style="-qt-list-indent: 1;"><li style=" font-size:8pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Browsable by friends</span>: files are seen by your friends.</li>
|
||||
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-size:8pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Browsable by friends</span>: files are seen by your friends.</li>
|
||||
<li style=" font-size:8pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Anonymously shared</span>: files are anonymously reachable through distant F2F tunnels.</li></ul></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
|
@ -136,6 +136,7 @@ int main(int argc, char *argv[])
|
||||
std::cerr << "connecting signals and slots" << std::endl ;
|
||||
QObject::connect(notify,SIGNAL(gotTurtleSearchResult(qulonglong,FileDetail)),w->searchDialog ,SLOT(updateFiles(qulonglong,FileDetail))) ;
|
||||
QObject::connect(notify,SIGNAL(hashingInfoChanged(const QString&)),w ,SLOT(updateHashingInfo(const QString&))) ;
|
||||
QObject::connect(notify,SIGNAL(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ;
|
||||
QObject::connect(notify,SIGNAL(filesPreModChanged(bool)) ,w->sharedfilesDialog ,SLOT(preModDirectories(bool) )) ;
|
||||
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w->sharedfilesDialog ,SLOT(postModDirectories(bool) )) ;
|
||||
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user