diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index 9f708bd1f..b82072bcb 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -40,9 +40,10 @@ LocalDirectoryUpdater::LocalDirectoryUpdater(HashStorage *hc,LocalDirectoryStora , mLastSweepTime(0), mLastTSUpdateTime(0) , mDelayBetweenDirectoryUpdates(DELAY_BETWEEN_DIRECTORY_UPDATES) , mIsEnabled(false), mFollowSymLinks(FOLLOW_SYMLINKS_DEFAULT) + , mIgnoreDuplicates(true) /* Can be left to false, but setting it to true will force to re-hash any file that has been left unhashed in the last session.*/ , mNeedsFullRecheck(true) - , mIsChecking(false), mForceUpdate(false), mIgnoreFlags (0) + , mIsChecking(false), mForceUpdate(false), mIgnoreFlags (0), mMaxShareDepth(0) { } @@ -344,4 +345,25 @@ bool LocalDirectoryUpdater::getIgnoreLists(std::list& ignored_prefi return true; } +int LocalDirectoryUpdater::maxShareDepth() const +{ + return mMaxShareDepth ; +} +void LocalDirectoryUpdater::setMaxShareDepth(int d) +{ + if(d != mMaxShareDepth) + mNeedsFullRecheck = true ; + + mMaxShareDepth = d ; +} + +bool LocalDirectoryUpdater::ignoreDuplicates() const +{ + return mIgnoreDuplicates; +} + +void LocalDirectoryUpdater::setIgnoreDuplicates(bool b) +{ + mIgnoreDuplicates = b ; +} diff --git a/libretroshare/src/file_sharing/directory_updater.h b/libretroshare/src/file_sharing/directory_updater.h index 5930985e3..211194a48 100644 --- a/libretroshare/src/file_sharing/directory_updater.h +++ b/libretroshare/src/file_sharing/directory_updater.h @@ -58,6 +58,12 @@ public: void setIgnoreLists(const std::list& ignored_prefixes,const std::list& ignored_suffixes,uint32_t ignore_flags) ; bool getIgnoreLists(std::list& ignored_prefixes,std::list& ignored_suffixes,uint32_t& ignore_flags) const ; + void setMaxShareDepth(int i) ; + int maxShareDepth() const; + + void setIgnoreDuplicates(bool b) ; + bool ignoreDuplicates() const; + protected: virtual void data_tick() ; @@ -81,11 +87,14 @@ private: uint32_t mDelayBetweenDirectoryUpdates; bool mIsEnabled ; bool mFollowSymLinks; + bool mIgnoreDuplicates; bool mNeedsFullRecheck ; bool mIsChecking ; bool mForceUpdate ; uint32_t mIgnoreFlags ; + uint32_t mMaxShareDepth ; + std::list mIgnoredPrefixes ; std::list mIgnoredSuffixes ; }; diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 718118c66..9e2dd6241 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -38,10 +38,12 @@ static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // ke static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them. +static const std::string IGNORE_DUPLICATES = "IGNORE_DUPLICATES"; // do not index files that are referenced multiple times because of links static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags +static const std::string MAX_SHARE_DEPTH = "MAX_SHARE_DEPTH"; // maximum depth of shared directories static const std::string FILE_SHARING_DIR_NAME = "file_sharing" ; // hard-coded directory name to store friend file lists, hash cache, etc. static const std::string HASH_CACHE_FILE_NAME = "hash_cache.bin" ; // hard-coded directory name to store encrypted hash cache. diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 9fac76483..5748a3b58 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -332,6 +332,17 @@ cleanup = true; kv.key = WATCH_FILE_DURATION_SS; kv.value = s ; + rskv->tlvkvs.pairs.push_back(kv); + } + { + std::string s ; + rs_sprintf(s, "%d", maxShareDepth()) ; + + RsTlvKeyValue kv; + + kv.key = MAX_SHARE_DEPTH; + kv.value = s ; + rskv->tlvkvs.pairs.push_back(kv); } { @@ -342,6 +353,14 @@ cleanup = true; rskv->tlvkvs.pairs.push_back(kv); } + { + RsTlvKeyValue kv; + + kv.key = IGNORE_DUPLICATES; + kv.value = ignoreDuplicates()?"YES":"NO" ; + + rskv->tlvkvs.pairs.push_back(kv); + } { RsTlvKeyValue kv; @@ -400,6 +419,7 @@ bool p3FileDatabase::loadList(std::list& load) std::list dirList; std::list ignored_prefixes,ignored_suffixes ; uint32_t ignore_flags = RS_FILE_SHARE_FLAGS_IGNORE_PREFIXES | RS_FILE_SHARE_FLAGS_IGNORE_SUFFIXES ; + uint32_t max_share_depth = 0; // OS-dependent default ignore lists #ifdef WINDOWS_SYS @@ -433,10 +453,14 @@ bool p3FileDatabase::loadList(std::list& load) if(sscanf(kit->value.c_str(),"%d",&t) == 1) setWatchPeriod(t); } - else if(kit->key == FOLLOW_SYMLINKS_SS) + else if(kit->key == FOLLOW_SYMLINKS_SS) { setFollowSymLinks(kit->value == "YES") ; } + else if(kit->key == IGNORE_DUPLICATES) + { + setIgnoreDuplicates(kit->value == "YES") ; + } else if(kit->key == WATCH_FILE_ENABLED_SS) { setWatchEnabled(kit->value == "YES") ; @@ -480,6 +504,12 @@ bool p3FileDatabase::loadList(std::list& load) if(sscanf(kit->value.c_str(),"%d",&t) == 1) ignore_flags = (uint32_t)t ; } + else if(kit->key == MAX_SHARE_DEPTH) + { + int t=0 ; + if(sscanf(kit->value.c_str(),"%d",&t) == 1) + max_share_depth = (uint32_t)t ; + } delete *it ; continue ; @@ -509,6 +539,7 @@ bool p3FileDatabase::loadList(std::list& load) /* set directories */ mLocalSharedDirs->setSharedDirectoryList(dirList); mLocalDirWatcher->setIgnoreLists(ignored_prefixes,ignored_suffixes,ignore_flags) ; + mLocalDirWatcher->setMaxShareDepth(max_share_depth); load.clear() ; @@ -1070,6 +1101,28 @@ bool p3FileDatabase::followSymLinks() const RS_STACK_MUTEX(mFLSMtx) ; return mLocalDirWatcher->followSymLinks() ; } +void p3FileDatabase::setIgnoreDuplicates(bool i) +{ + RS_STACK_MUTEX(mFLSMtx) ; + mLocalDirWatcher->setIgnoreDuplicates(i) ; + IndicateConfigChanged(); +} +bool p3FileDatabase::ignoreDuplicates() const +{ + RS_STACK_MUTEX(mFLSMtx) ; + return mLocalDirWatcher->ignoreDuplicates() ; +} +void p3FileDatabase::setMaxShareDepth(int i) +{ + RS_STACK_MUTEX(mFLSMtx) ; + mLocalDirWatcher->setMaxShareDepth(i) ; + IndicateConfigChanged(); +} +int p3FileDatabase::maxShareDepth() const +{ + RS_STACK_MUTEX(mFLSMtx) ; + return mLocalDirWatcher->maxShareDepth() ; +} void p3FileDatabase::setWatchEnabled(bool b) { RS_STACK_MUTEX(mFLSMtx) ; diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 774629b38..15f279484 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -130,6 +130,12 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub void setIgnoreLists(const std::list& ignored_prefixes,const std::list& ignored_suffixes, uint32_t ignore_flags) ; bool getIgnoreLists(std::list& ignored_prefixes,std::list& ignored_suffixes, uint32_t& ignore_flags) ; + void setIgnoreDuplicates(bool i) ; + bool ignoreDuplicates() const ; + + void setMaxShareDepth(int i) ; + int maxShareDepth() const ; + // computes/gathers statistics about shared directories int getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& stats); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 86f1ad999..7b546c31e 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -839,10 +839,14 @@ void ftServer::setIgnoreLists(const std::list& ignored_prefixes, co bool ftServer::watchEnabled() { return mFileDatabase->watchEnabled() ; } int ftServer::watchPeriod() const { return mFileDatabase->watchPeriod()/60 ; } bool ftServer::followSymLinks() const { return mFileDatabase->followSymLinks() ; } +bool ftServer::ignoreDuplicates() { return mFileDatabase->ignoreDuplicates() ; } +int ftServer::maxShareDepth() const { return mFileDatabase->maxShareDepth() ; } void ftServer::setWatchEnabled(bool b) { mFileDatabase->setWatchEnabled(b) ; } void ftServer::setWatchPeriod(int minutes) { mFileDatabase->setWatchPeriod(minutes*60) ; } void ftServer::setFollowSymLinks(bool b) { mFileDatabase->setFollowSymLinks(b) ; } +void ftServer::setIgnoreDuplicates(bool ignore) { mFileDatabase->setIgnoreDuplicates(ignore); } +void ftServer::setMaxShareDepth(int depth) { mFileDatabase->setMaxShareDepth(depth) ; } void ftServer::togglePauseHashingProcess() { mFileDatabase->togglePauseHashingProcess() ; } bool ftServer::hashingProcessPaused() { return mFileDatabase->hashingProcessPaused() ; } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index fa64a3fb9..191b201b4 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -228,6 +228,12 @@ public: virtual void togglePauseHashingProcess(); virtual bool hashingProcessPaused(); + virtual void setMaxShareDepth(int depth) ; + virtual int maxShareDepth() const; + + virtual bool ignoreDuplicates() ; + virtual void setIgnoreDuplicates(bool ignore) ; + /***************************************************************/ /*************** Data Transfer Interface ***********************/ /***************************************************************/ diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index a65706f94..313ca26eb 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -60,8 +60,11 @@ const uint32_t RS_FILE_RATE_STREAM_VIDEO = 0x00000006; const uint32_t RS_FILE_PEER_ONLINE = 0x00001000; const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000; -const uint32_t RS_FILE_SHARE_FLAGS_IGNORE_PREFIXES = 0x0001 ; -const uint32_t RS_FILE_SHARE_FLAGS_IGNORE_SUFFIXES = 0x0002 ; +const uint32_t RS_FILE_SHARE_FLAGS_IGNORE_PREFIXES = 0x0001 ; +const uint32_t RS_FILE_SHARE_FLAGS_IGNORE_SUFFIXES = 0x0002 ; +const uint32_t RS_FILE_SHARE_FLAGS_IGNORE_DUPLICATES = 0x0004 ; + +const uint32_t RS_FILE_SHARE_PARAMETER_DEFAULT_MAXIMUM_DEPTH = 8; /************************************ * Used To indicate where to search. @@ -269,6 +272,12 @@ class RsFiles virtual bool getShareDownloadDirectory() = 0; virtual bool shareDownloadDirectory(bool share) = 0; + virtual void setMaxShareDepth(int depth) =0; + virtual int maxShareDepth() const=0; + + virtual bool ignoreDuplicates() = 0; + virtual void setIgnoreDuplicates(bool ignore) = 0; + }; diff --git a/retroshare-gui/src/gui/settings/TransferPage.cpp b/retroshare-gui/src/gui/settings/TransferPage.cpp index ee3df7044..309990d3e 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.cpp +++ b/retroshare-gui/src/gui/settings/TransferPage.cpp @@ -59,6 +59,8 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags) QObject::connect(ui.prefixesIgnoreList_CB, SIGNAL(toggled(bool)), this,SLOT(updateIgnoreLists())) ; QObject::connect(ui.suffixesIgnoreList_LE, SIGNAL(editingFinished()), this,SLOT(updateIgnoreLists())) ; QObject::connect(ui.suffixesIgnoreList_CB, SIGNAL(toggled(bool)), this,SLOT(updateIgnoreLists())) ; + QObject::connect(ui.ignoreDuplicates_CB, SIGNAL(toggled(bool)), this,SLOT(updateIgnoreDuplicates())) ; + QObject::connect(ui.maxDepth_SB, SIGNAL(valueChanged(int)), this,SLOT(updateMaxShareDepth(int))) ; } void TransferPage::updateIgnoreLists() @@ -116,6 +118,8 @@ void TransferPage::updateFilePermDirectDL(int i) void TransferPage::load() { + ui.ignoreDuplicates_CB->setEnabled(rsFiles->followSymLinks()) ; + whileBlocking(ui.shareDownloadDirectoryCB)->setChecked(rsFiles->getShareDownloadDirectory()); int u = rsFiles->watchPeriod() ; @@ -125,6 +129,8 @@ void TransferPage::load() whileBlocking(ui.incomingDir)->setText(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str())); whileBlocking(ui.partialsDir)->setText(QString::fromUtf8(rsFiles->getPartialsDirectory().c_str())); whileBlocking(ui.followSymLinks_CB)->setChecked(rsFiles->followSymLinks()); + whileBlocking(ui.ignoreDuplicates_CB)->setChecked(rsFiles->ignoreDuplicates()); + whileBlocking(ui.maxDepth_SB)->setValue(rsFiles->maxShareDepth()); whileBlocking(ui._queueSize_SB)->setValue(rsFiles->getQueueSize()) ; @@ -199,6 +205,14 @@ void TransferPage::updateDiskSizeLimit(int s) { rsFiles->setFreeDiskSpaceLimit(s) ; } +void TransferPage::updateIgnoreDuplicates() +{ + rsFiles->setIgnoreDuplicates(ui.ignoreDuplicates_CB->isChecked()); +} +void TransferPage::updateMaxShareDepth(int s) +{ + rsFiles->setMaxShareDepth(s) ; +} void TransferPage::updateQueueSize(int s) { @@ -243,4 +257,4 @@ void TransferPage::editDirectories() void TransferPage::updateAutoCheckDirectories() { rsFiles->setWatchEnabled(ui.autoCheckDirectories_CB->isChecked()) ; } void TransferPage::updateAutoScanDirectoriesPeriod() { rsFiles->setWatchPeriod(ui.autoCheckDirectoriesDelay_SB->value()); } void TransferPage::updateShareDownloadDirectory() { rsFiles->shareDownloadDirectory(ui.shareDownloadDirectoryCB->isChecked());} -void TransferPage::updateFollowSymLinks() { rsFiles->setFollowSymLinks(ui.followSymLinks_CB->isChecked()); } +void TransferPage::updateFollowSymLinks() { rsFiles->setFollowSymLinks(ui.followSymLinks_CB->isChecked()); ui.ignoreDuplicates_CB->setEnabled(ui.followSymLinks_CB->isChecked());} diff --git a/retroshare-gui/src/gui/settings/TransferPage.h b/retroshare-gui/src/gui/settings/TransferPage.h index fc39160c3..73826c511 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.h +++ b/retroshare-gui/src/gui/settings/TransferPage.h @@ -51,6 +51,7 @@ class TransferPage: public ConfigPage void updateMaxUploadSlots(int); void updateFilePermDirectDL(int); void updateIgnoreLists(); + void updateMaxShareDepth(int); void editDirectories() ; void setIncomingDirectory(); @@ -61,6 +62,7 @@ class TransferPage: public ConfigPage void updateAutoScanDirectoriesPeriod() ; void updateShareDownloadDirectory() ; void updateFollowSymLinks() ; + void updateIgnoreDuplicates() ; private: diff --git a/retroshare-gui/src/gui/settings/TransferPage.ui b/retroshare-gui/src/gui/settings/TransferPage.ui index 3731b70f4..31c07bfac 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.ui +++ b/retroshare-gui/src/gui/settings/TransferPage.ui @@ -6,8 +6,8 @@ 0 0 - 1126 - 1103 + 1312 + 1305 @@ -18,33 +18,35 @@ - - - - - true - - - Automatically share incoming directory (Recommended) - - - true - - - - - - - Edit Share - - - - + + + Edit Share + + + + + + + true + + + Automatically share incoming directory (Recommended) + + + true + + + + + 0 + 0 + + Auto-check shared directories every @@ -88,6 +90,30 @@ + + + + + + Ignore duplicate files/directories + + + + + + + Maximum depth: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + @@ -132,47 +158,57 @@ Incoming Directory - - - - - true - - - - - - - - 31 - 31 - - - - - 31 - 31 - - - - Browse - - - - - - - :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png - - - - 24 - 24 - - - - - + + + + 21 + 52 + 244 + 36 + + + + true + + + + + + 1224 + 54 + 31 + 31 + + + + + 31 + 31 + + + + + 31 + 31 + + + + Browse + + + + + + + :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png + + + + 24 + 24 + + +