mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Ported trunk commits 2968 2969 2972 2979 2986 2992 2993: implemented a free disk space checking method, with a warning when running low. Set the default to 50MB. Updated the message to be more explicit (thanks Chris)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@3008 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
971431bfa1
commit
c87fbfe2cb
@ -35,6 +35,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef WINDOWS_SYS
|
||||||
|
#include "util/rswin.h"
|
||||||
|
#endif
|
||||||
|
#include "util/rsdiscspace.h"
|
||||||
|
|
||||||
#include "ft/ftcontroller.h"
|
#include "ft/ftcontroller.h"
|
||||||
|
|
||||||
#include "ft/ftfilecreator.h"
|
#include "ft/ftfilecreator.h"
|
||||||
@ -52,6 +57,7 @@
|
|||||||
|
|
||||||
#include "serialiser/rsconfigitems.h"
|
#include "serialiser/rsconfigitems.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
/******
|
/******
|
||||||
* #define CONTROL_DEBUG 1
|
* #define CONTROL_DEBUG 1
|
||||||
@ -1782,6 +1788,7 @@ const std::string download_dir_ss("DOWN_DIR");
|
|||||||
const std::string partial_dir_ss("PART_DIR");
|
const std::string partial_dir_ss("PART_DIR");
|
||||||
const std::string share_dwl_dir("SHARE_DWL_DIR");
|
const std::string share_dwl_dir("SHARE_DWL_DIR");
|
||||||
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
|
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
|
||||||
|
const std::string free_space_limit_ss("FREE_SPACE_LIMIT");
|
||||||
|
|
||||||
|
|
||||||
/* p3Config Interface */
|
/* p3Config Interface */
|
||||||
@ -1815,6 +1822,11 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
|
|||||||
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
|
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
|
||||||
configMap[default_chunk_strategy_ss] = (mDefaultChunkStrategy==FileChunksInfo::CHUNK_STRATEGY_STREAMING) ? "STREAMING" : "RANDOM";
|
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();
|
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
|
||||||
|
|
||||||
/* Convert to TLV */
|
/* Convert to TLV */
|
||||||
@ -2013,9 +2025,33 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
|||||||
std::cerr << "**** ERROR ***: Unknown value for default chunk strategy in keymap." << std::endl ;
|
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;
|
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()
|
FileChunksInfo::ChunkStrategy ftController::defaultChunkStrategy()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
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);
|
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||||
|
uint32_t freeDiskSpaceLimit() const ;
|
||||||
|
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||||
|
|
||||||
bool FileCancel(std::string hash);
|
bool FileCancel(std::string hash);
|
||||||
bool FileControl(std::string hash, uint32_t flags);
|
bool FileControl(std::string hash, uint32_t flags);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "ftfilecreator.h"
|
#include "ftfilecreator.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <util/rsdiscspace.h>
|
||||||
|
|
||||||
/*******
|
/*******
|
||||||
* #define FILE_DEBUG 1
|
* #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(). */
|
/* dodgey checking outside of mutex... much check again inside FileAttrs(). */
|
||||||
/* Check File is open */
|
/* Check File is open */
|
||||||
|
|
||||||
|
if(!RsDiscSpace::checkForDiscSpace(RS_PARTIALS_DIRECTORY))
|
||||||
|
return false ;
|
||||||
|
|
||||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
|
@ -272,6 +272,14 @@ bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStr
|
|||||||
{
|
{
|
||||||
return mFtController->setChunkStrategy(hash,s);
|
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)
|
void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
||||||
{
|
{
|
||||||
mFtController->setDefaultChunkStrategy(s) ;
|
mFtController->setDefaultChunkStrategy(s) ;
|
||||||
|
@ -127,6 +127,8 @@ virtual bool FileClearCompleted();
|
|||||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||||
|
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||||
|
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -289,6 +289,7 @@ HEADERS += dbase/cachestrapper.h \
|
|||||||
tcponudp/udplayer.h \
|
tcponudp/udplayer.h \
|
||||||
tcponudp/udpsorter.h \
|
tcponudp/udpsorter.h \
|
||||||
upnp/upnphandler.h \
|
upnp/upnphandler.h \
|
||||||
|
util/rsdiscspace.h \
|
||||||
util/rsdebug.h \
|
util/rsdebug.h \
|
||||||
util/rsdir.h \
|
util/rsdir.h \
|
||||||
util/rsnet.h \
|
util/rsnet.h \
|
||||||
@ -406,6 +407,7 @@ SOURCES += \
|
|||||||
tcponudp/udpsorter.cc \
|
tcponudp/udpsorter.cc \
|
||||||
tcponudp/tou_net.cc \
|
tcponudp/tou_net.cc \
|
||||||
tcponudp/udplayer.cc \
|
tcponudp/udplayer.cc \
|
||||||
|
util/rsdiscspace.cc \
|
||||||
util/rsdebug.cc \
|
util/rsdebug.cc \
|
||||||
util/rsdir.cc \
|
util/rsdir.cc \
|
||||||
util/rsnet.cc \
|
util/rsnet.cc \
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "pqi/pqistore.h"
|
#include "pqi/pqistore.h"
|
||||||
#include "pqi/pqinotify.h"
|
#include "pqi/pqinotify.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <util/rsdiscspace.h>
|
||||||
|
|
||||||
#include "serialiser/rsconfigitems.h"
|
#include "serialiser/rsconfigitems.h"
|
||||||
|
|
||||||
@ -86,6 +87,9 @@ void p3ConfigMgr::tick()
|
|||||||
|
|
||||||
void p3ConfigMgr::saveConfiguration()
|
void p3ConfigMgr::saveConfiguration()
|
||||||
{
|
{
|
||||||
|
if(!RsDiscSpace::checkForDiscSpace(RS_CONFIG_DIRECTORY))
|
||||||
|
return ;
|
||||||
|
|
||||||
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
|
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG
|
#ifdef CONFIG_DEBUG
|
||||||
|
@ -115,6 +115,8 @@ class RsFiles
|
|||||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
||||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 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 FileControl(std::string hash, uint32_t flags) = 0;
|
||||||
virtual bool FileClearCompleted() = 0;
|
virtual bool FileClearCompleted() = 0;
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ class NotifyBase
|
|||||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
||||||
virtual void notifyOwnAvatarChanged() {}
|
virtual void notifyOwnAvatarChanged() {}
|
||||||
virtual void notifyOwnStatusMessageChanged() {}
|
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 "" ;}
|
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_QUEUED = 0x0005 ;
|
||||||
const uint32_t FT_STATE_PAUSED = 0x0006 ;
|
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
|
class TransferInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
181
libretroshare/src/util/rsdiscspace.cc
Normal file
181
libretroshare/src/util/rsdiscspace.cc
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/util: rsdiscspace.cc
|
||||||
|
*
|
||||||
|
* Universal Networking Header for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2010 by Cyril Soler.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <rsiface/rsfiles.h>
|
||||||
|
#include <rsiface/rsiface.h>
|
||||||
|
#include <rsiface/rsinit.h>
|
||||||
|
#include "rsdiscspace.h"
|
||||||
|
#include <util/rsthreads.h>
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DELAY_BETWEEN_CHECKS 2
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #define DEBUG_RSDISCSPACE
|
||||||
|
*/
|
||||||
|
#define DEBUG_RSDISCSPACE
|
||||||
|
|
||||||
|
time_t RsDiscSpace::_last_check[3] = { 0,0,0 } ;
|
||||||
|
uint32_t RsDiscSpace::_size_limit_mb = 50 ;
|
||||||
|
uint32_t RsDiscSpace::_current_size[3] = { 10000,10000,10000 } ;
|
||||||
|
bool RsDiscSpace::_last_res[3] = { true,true,true };
|
||||||
|
RsMutex RsDiscSpace::_mtx ;
|
||||||
|
|
||||||
|
bool RsDiscSpace::crossSystemDiskStats(const char *file, uint64_t& free_blocks, uint64_t& block_size)
|
||||||
|
{
|
||||||
|
#if defined(WIN32) || defined(MINGW) || defined(__CYGWIN__)
|
||||||
|
|
||||||
|
DWORD dwFreeClusters;
|
||||||
|
DWORD dwBytesPerSector;
|
||||||
|
DWORD dwSectorPerCluster;
|
||||||
|
DWORD dwTotalClusters;
|
||||||
|
|
||||||
|
#ifdef WIN_CROSS_UBUNTU
|
||||||
|
wchar_t szDrive[4];
|
||||||
|
szDrive[0] = file[0] ;
|
||||||
|
szDrive[1] = file[1] ;
|
||||||
|
szDrive[2] = file[2] ;
|
||||||
|
#else
|
||||||
|
char szDrive[4] = "";
|
||||||
|
|
||||||
|
char *pszFullPath = _fullpath (NULL, file, 0);
|
||||||
|
if (pszFullPath == 0) {
|
||||||
|
std::cerr << "Size estimate failed for drive (_fullpath) " << szDrive << std::endl ;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_splitpath (pszFullPath, szDrive, NULL, NULL, NULL);
|
||||||
|
free (pszFullPath);
|
||||||
|
#endif
|
||||||
|
szDrive[3] = 0;
|
||||||
|
|
||||||
|
if (!GetDiskFreeSpace (szDrive, &dwSectorPerCluster, &dwBytesPerSector, &dwFreeClusters, &dwTotalClusters))
|
||||||
|
{
|
||||||
|
std::cerr << "Size estimate failed for drive " << szDrive << std::endl ;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
free_blocks = dwFreeClusters ;
|
||||||
|
block_size = dwSectorPerCluster * dwBytesPerSector ;
|
||||||
|
#else
|
||||||
|
struct statvfs64 buf;
|
||||||
|
|
||||||
|
if (0 != statvfs64 (file, &buf))
|
||||||
|
{
|
||||||
|
std::cerr << "Size estimate failed for file " << file << std::endl ;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
free_blocks = buf.f_bavail;
|
||||||
|
block_size = buf.f_frsize ;
|
||||||
|
#else
|
||||||
|
free_blocks = buf.f_bavail;
|
||||||
|
block_size = buf.f_bsize ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RsDiscSpace::checkForDiscSpace(RsDiscSpace::DiscLocation loc)
|
||||||
|
{
|
||||||
|
RsStackMutex m(_mtx) ; // Locked
|
||||||
|
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
|
if(_last_check[loc]+DELAY_BETWEEN_CHECKS < now)
|
||||||
|
{
|
||||||
|
uint64_t free_blocks,block_size ;
|
||||||
|
int rs = false;
|
||||||
|
|
||||||
|
#ifdef DEBUG_RSDISCSPACE
|
||||||
|
std::cerr << "Size determination:" << std::endl ;
|
||||||
|
#endif
|
||||||
|
switch(loc)
|
||||||
|
{
|
||||||
|
case RS_DOWNLOAD_DIRECTORY: rs = crossSystemDiskStats(rsFiles->getDownloadDirectory().c_str(),free_blocks,block_size) ;
|
||||||
|
#ifdef DEBUG_RSDISCSPACE
|
||||||
|
std::cerr << " path = " << rsFiles->getDownloadDirectory() << std::endl ;
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case RS_PARTIALS_DIRECTORY: rs = crossSystemDiskStats(rsFiles->getPartialsDirectory().c_str(),free_blocks,block_size) ;
|
||||||
|
#ifdef DEBUG_RSDISCSPACE
|
||||||
|
std::cerr << " path = " << rsFiles->getPartialsDirectory() << std::endl ;
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case RS_CONFIG_DIRECTORY: rs = crossSystemDiskStats(RsInit::RsConfigDirectory().c_str(),free_blocks,block_size) ;
|
||||||
|
#ifdef DEBUG_RSDISCSPACE
|
||||||
|
std::cerr << " path = " << RsInit::RsConfigDirectory() << std::endl ;
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rs)
|
||||||
|
{
|
||||||
|
std::cerr << "Determination of free disc space failed ! Be careful !" << std::endl ;
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
_last_check[loc] = now ;
|
||||||
|
|
||||||
|
// Now compute the size in megabytes
|
||||||
|
//
|
||||||
|
_current_size[loc] = uint32_t(block_size * free_blocks / (uint64_t)(1024*1024)) ; // on purpose integer division
|
||||||
|
|
||||||
|
#ifdef DEBUG_RSDISCSPACE
|
||||||
|
std::cerr << " blocks available = " << free_blocks << std::endl ;
|
||||||
|
std::cerr << " blocks size = " << block_size << std::endl ;
|
||||||
|
std::cerr << " free MBs = " << _current_size[loc] << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool res = _current_size[loc] > _size_limit_mb ;
|
||||||
|
|
||||||
|
if(_last_res[loc] && !res)
|
||||||
|
rsicontrol->getNotify().notifyDiskFull(loc,_size_limit_mb) ;
|
||||||
|
|
||||||
|
_last_res[loc] = res ;
|
||||||
|
|
||||||
|
return res ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsDiscSpace::setFreeSpaceLimit(uint32_t size_in_mb)
|
||||||
|
{
|
||||||
|
RsStackMutex m(_mtx) ; // Locked
|
||||||
|
|
||||||
|
_size_limit_mb = size_in_mb ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RsDiscSpace::freeSpaceLimit()
|
||||||
|
{
|
||||||
|
RsStackMutex m(_mtx) ; // Locked
|
||||||
|
|
||||||
|
return _size_limit_mb ;
|
||||||
|
}
|
||||||
|
|
59
libretroshare/src/util/rsdiscspace.h
Normal file
59
libretroshare/src/util/rsdiscspace.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/util: rsdiscspace.h
|
||||||
|
*
|
||||||
|
* Universal Networking Header for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2010 by Cyril Soler.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <util/rsthreads.h>
|
||||||
|
|
||||||
|
class RsDiscSpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef uint32_t DiscLocation ;
|
||||||
|
|
||||||
|
// Returns false is the disc space is lower than the given size limit, true otherwise.
|
||||||
|
// When the size limit is reached, this class calls notify to warn the user (possibly
|
||||||
|
// with a popup window).
|
||||||
|
//
|
||||||
|
static bool checkForDiscSpace(DiscLocation loc) ;
|
||||||
|
|
||||||
|
// Allow the user to specify his own size limit. Should not be too low, especially not 0 MB ;-)
|
||||||
|
// 10MB to 100MB are sensible values.
|
||||||
|
//
|
||||||
|
static void setFreeSpaceLimit(uint32_t mega_bytes) ;
|
||||||
|
static uint32_t freeSpaceLimit() ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool crossSystemDiskStats(const char *file, uint64_t& free_blocks, uint64_t& block_size) ;
|
||||||
|
|
||||||
|
static RsMutex _mtx ;
|
||||||
|
|
||||||
|
static time_t _last_check[3] ;
|
||||||
|
static uint32_t _size_limit_mb ;
|
||||||
|
static uint32_t _current_size[3] ;
|
||||||
|
static bool _last_res[3] ;
|
||||||
|
};
|
||||||
|
|
@ -183,11 +183,11 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
|||||||
ui.stackPages->add(messagesDialog = new MessagesDialog(ui.stackPages),
|
ui.stackPages->add(messagesDialog = new MessagesDialog(ui.stackPages),
|
||||||
messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
|
messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
|
||||||
|
|
||||||
#ifndef RS_RELEASE_VERSION
|
#ifndef RS_RELEASE_VERSION
|
||||||
ChannelFeed *channelFeed = NULL;
|
ChannelFeed *channelFeed = NULL;
|
||||||
ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages),
|
ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages),
|
||||||
createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
|
createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BLOGS
|
#ifdef BLOGS
|
||||||
BlogsDialog *blogsFeed = NULL;
|
BlogsDialog *blogsFeed = NULL;
|
||||||
@ -285,6 +285,28 @@ MainWindow::~MainWindow()
|
|||||||
#endif
|
#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 used by your ")+locString +tr(" directory is running low (Less than ")+QString::number(size_limit_mb)+tr("MB). \n\n RetroShare will now safely suspend config files saving and transfers. \n\n Please make some free space, then click Ok.")) ;
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a tray icon with a context menu and adds it to the system
|
/** Creates a tray icon with a context menu and adds it to the system
|
||||||
* notification area. */
|
* notification area. */
|
||||||
void MainWindow::createTrayIcon()
|
void MainWindow::createTrayIcon()
|
||||||
|
@ -105,6 +105,7 @@ public slots:
|
|||||||
void updateHashingInfo(const QString&) ;
|
void updateHashingInfo(const QString&) ;
|
||||||
void displayErrorMessage(int,int,const QString&) ;
|
void displayErrorMessage(int,int,const QString&) ;
|
||||||
void postModDirectories(bool update_local);
|
void postModDirectories(bool update_local);
|
||||||
|
void displayDiskSpaceWarning(int loc,int size_limit_mb) ;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
@ -56,6 +56,13 @@ std::string NotifyQt::askForPassword(const std::string& key_details,bool prev_is
|
|||||||
return res ;
|
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()
|
void NotifyQt::notifyOwnStatusMessageChanged()
|
||||||
{
|
{
|
||||||
#ifdef NOTIFY_DEBUG
|
#ifdef NOTIFY_DEBUG
|
||||||
|
@ -40,6 +40,8 @@ class NotifyQt: public QObject, public NotifyBase
|
|||||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
||||||
virtual void notifyOwnAvatarChanged() ;
|
virtual void notifyOwnAvatarChanged() ;
|
||||||
virtual void notifyOwnStatusMessageChanged() ;
|
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) ;
|
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 ownAvatarChanged() const ;
|
||||||
void ownStatusMessageChanged() const ;
|
void ownStatusMessageChanged() const ;
|
||||||
void errorOccurred(int,int,const QString&) const ;
|
void errorOccurred(int,int,const QString&) const ;
|
||||||
|
void diskFull(int,int) const ;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -45,8 +45,11 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
|
|||||||
else
|
else
|
||||||
ui._defaultStrategy_CB->setCurrentIndex(1) ;
|
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._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
|
||||||
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(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 */
|
/* Hide platform specific features */
|
||||||
#ifdef Q_WS_WIN
|
#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)
|
void TransferPage::updateQueueSize(int s)
|
||||||
{
|
{
|
||||||
rsFiles->setQueueSize(s) ;
|
rsFiles->setQueueSize(s) ;
|
||||||
|
@ -43,6 +43,7 @@ class TransferPage: public ConfigPage
|
|||||||
public slots:
|
public slots:
|
||||||
void updateQueueSize(int) ;
|
void updateQueueSize(int) ;
|
||||||
void updateDefaultStrategy(int) ;
|
void updateDefaultStrategy(int) ;
|
||||||
|
void updateDiskSizeLimit(int) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Transfer options</string>
|
<string>Transfer options</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -38,6 +38,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Safety disk space limit :</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -75,6 +82,28 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="_diskSpaceLimit_SB">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="suffix">
|
||||||
|
<string> MB</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>1000</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>50</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -92,7 +121,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=" 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="-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>
|
<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>
|
<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>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -143,6 +143,7 @@ int main(int argc, char *argv[])
|
|||||||
std::cerr << "connecting signals and slots" << std::endl ;
|
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(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(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(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->sharedfilesDialog ,SLOT(postModDirectories(bool) )) ;
|
||||||
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
|
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user