From 9f66c0050b63bca5e22119cf6b090ea624379186 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Mon, 12 Sep 2016 23:37:19 +0200 Subject: [PATCH] moved rsexpr to file_sharing directory --- .../src/file_sharing/dir_hierarchy.cc | 44 +++++++++ .../src/file_sharing/dir_hierarchy.h | 5 ++ .../src/file_sharing/directory_storage.cc | 90 ++++++++++--------- .../src/file_sharing/directory_storage.h | 4 +- .../src/{dbase => file_sharing}/rsexpr.cc | 0 libretroshare/src/libretroshare.pro | 13 +-- libretroshare/src/retroshare/rstypes.h | 2 +- 7 files changed, 102 insertions(+), 56 deletions(-) rename libretroshare/src/{dbase => file_sharing}/rsexpr.cc (100%) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index d58d91170..778d1cffb 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -2,6 +2,7 @@ #include "dir_hierarchy.h" #include "filelist_io.h" +//#include "rsexpr.h" #define DEBUG_DIRECTORY_STORAGE 1 @@ -570,6 +571,49 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list &results) const +{ +#ifdef TODO + for(std::map::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it) + { + const std::string &str1 = static_cast(mNodes[fit->second])->file_name; + + { + /*Evaluate the boolean expression and add it to the results if its true*/ + bool ret = exp->eval(fit->second); + if (ret == true){ + results.push_back(fit->second); + } + } +#endif +} + +int InternalFileHierarchyStorage::searchTerms(const std::list& terms, std::list &results) const +{ + // most entries are likely to be files, so we could do a linear search over the entries tab. + // instead we go through the table of hashes. + + for(std::map::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it) + if(mNodes[it->second] != NULL) + { + const std::string &str1 = static_cast(mNodes[it->second])->file_name; + + for(std::list::const_iterator iter(terms.begin()); iter != terms.end(); ++iter) + { + /* always ignore case */ + const std::string &str2 = (*iter); +#ifdef TODO + if(str1.end() != std::search( str1.begin(), str1.end(), str2.begin(), str2.end(), CompareCharIC() )) + { + results.push_back(fit->second); + break; + } +#endif + } + } + return 0 ; +} + bool InternalFileHierarchyStorage::check(std::string& error_string) const // checks consistency of storage. { // recurs go through all entries, check that all diff --git a/libretroshare/src/file_sharing/dir_hierarchy.h b/libretroshare/src/file_sharing/dir_hierarchy.h index 33c5a562e..f2e81844f 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.h +++ b/libretroshare/src/file_sharing/dir_hierarchy.h @@ -110,7 +110,12 @@ public: uint32_t getType(DirectoryStorage::EntryIndex indx) const; DirectoryStorage::EntryIndex getSubFileIndex(DirectoryStorage::EntryIndex parent_index,uint32_t file_tab_index); DirectoryStorage::EntryIndex getSubDirIndex(DirectoryStorage::EntryIndex parent_index,uint32_t dir_tab_index); + + // search. SearchHash is logarithmic. The other two are linear. + bool searchHash(const RsFileHash& hash,std::list& results); + int searchBoolExp(Expression * exp, std::list &results) const ; + int searchTerms(const std::list& terms, std::list &results) const ; bool check(std::string& error_string) const ;// checks consistency of storage. diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 779a2c04d..4130481df 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -160,62 +160,29 @@ void DirectoryStorage::saveNextTag(unsigned char *data, uint32_t& offset, uint8_ void DirectoryStorage::load(const std::string& local_file_name) { - std::cerr << "DirectoryStorage::load()" << std::endl; - - // first load the header, than all fields. - RS_STACK_MUTEX(mDirStorageMtx) ; mFileHierarchy->load(local_file_name); } void DirectoryStorage::save(const std::string& local_file_name) { - std::cerr << "DirectoryStorage::Save()" << std::endl; - RS_STACK_MUTEX(mDirStorageMtx) ; mFileHierarchy->save(local_file_name); - - // first write the header, than all fields. } void DirectoryStorage::print() { RS_STACK_MUTEX(mDirStorageMtx) ; - std::cerr << "LocalDirectoryStorage:" << std::endl; mFileHierarchy->print(); } -bool LocalDirectoryStorage::getFileInfo(DirectoryStorage::EntryIndex i,FileInfo& info) +int DirectoryStorage::searchTerms(const std::list& terms, std::list &results) const { - DirDetails d; - extractData(i,d) ; - - info.storage_permission_flags = d.flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file. - info.parent_groups = d.parent_groups; - info.transfer_info_flags = TransferRequestFlags(); // various flags from RS_FILE_HINTS_* - info.path = d.path + "/" + d.name; - info.fname = d.name; - info.hash = d.hash; - info.size = d.count; - - // all this stuff below is not useful in this case. - - info.mId = 0; /* (GUI) Model Id -> unique number */ - info.ext.clear(); - info.avail = 0; /* how much we have */ - info.rank = 0; - info.age = 0; - info.queue_position =0; - info.searchId = 0; /* 0 if none */ - - /* Transfer Stuff */ - info.transfered = 0; - info.tfRate = 0; /* in kbytes */ - info.downloadStatus = FT_STATE_COMPLETE ; - std::list peers; - - info.priority = SPEED_NORMAL; - info.lastTS = 0; - - return true; + RS_STACK_MUTEX(mDirStorageMtx) ; + return mFileHierarchy->searchTerms(terms,results); +} +int DirectoryStorage::searchBoolExp(Expression * exp, std::list &results) const +{ + RS_STACK_MUTEX(mDirStorageMtx) ; + return mFileHierarchy->searchBoolExp(exp,results); } bool DirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) @@ -444,6 +411,47 @@ bool LocalDirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) return getFileSharingPermissions(indx,d.flags,d.parent_groups) ; } +bool LocalDirectoryStorage::getFileInfo(DirectoryStorage::EntryIndex i,FileInfo& info) +{ + DirDetails d; + extractData(i,d) ; + + if(d.type != DIR_TYPE_FILE) + { + std::cerr << "(EE) LocalDirectoryStorage: asked for file info for index " << i << " which is not a file." << std::endl; + return false; + } + + info.storage_permission_flags = d.flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file. + info.parent_groups = d.parent_groups; + info.transfer_info_flags = TransferRequestFlags(); // various flags from RS_FILE_HINTS_* + info.path = d.path + "/" + d.name; + info.fname = d.name; + info.hash = d.hash; + info.size = d.count; + + // all this stuff below is not useful in this case. + + info.mId = 0; /* (GUI) Model Id -> unique number */ + info.ext.clear(); + info.avail = 0; /* how much we have */ + info.rank = 0; + info.age = 0; + info.queue_position =0; + info.searchId = 0; /* 0 if none */ + + /* Transfer Stuff */ + info.transfered = 0; + info.tfRate = 0; /* in kbytes */ + info.downloadStatus = FT_STATE_COMPLETE ; + std::list peers; + + info.priority = SPEED_NORMAL; + info.lastTS = 0; + + return true; +} + bool LocalDirectoryStorage::getFileSharingPermissions(const EntryIndex& indx,FileStorageFlags& flags,std::list& parent_groups) { RS_STACK_MUTEX(mDirStorageMtx) ; diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 78fcb46ba..7c88ffe21 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -24,9 +24,9 @@ class DirectoryStorage void save() const ; - virtual int searchTerms(const std::list& terms, std::list &results) const { NOT_IMPLEMENTED() ; return 0;} + virtual int searchTerms(const std::list& terms, std::list &results) const ; + virtual int searchBoolExp(Expression * exp, std::list &results) const ; virtual int searchHash(const RsFileHash& hash, std::list &results) const ; - virtual int searchBoolExp(Expression * exp, std::list &results) const { NOT_IMPLEMENTED() ; return 0; } bool getDirUpdateTS(EntryIndex index,time_t& recurs_max_modf_TS,time_t& local_update_TS) ; bool setDirUpdateTS(EntryIndex index,time_t recurs_max_modf_TS,time_t local_update_TS) ; diff --git a/libretroshare/src/dbase/rsexpr.cc b/libretroshare/src/file_sharing/rsexpr.cc similarity index 100% rename from libretroshare/src/dbase/rsexpr.cc rename to libretroshare/src/file_sharing/rsexpr.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 56d36469c..f839ab2d5 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -55,6 +55,7 @@ file_lists { file_sharing/directory_storage.cc \ file_sharing/directory_updater.cc \ file_sharing/dir_hierarchy.cc \ + file_sharing/rsexpr.cc \ file_sharing/rsfilelistitems.cc } @@ -366,11 +367,6 @@ INCLUDEPATH *= $${OPENPGPSDK_DIR} PRE_TARGETDEPS *= $${OPENPGPSDK_DIR}/lib/libops.a LIBS *= $${OPENPGPSDK_DIR}/lib/libops.a -lbz2 -HEADERS += dbase/cachestrapper.h \ - dbase/fimonitor.h \ - dbase/findex.h \ - dbase/fistore.h - HEADERS += ft/ftchunkmap.h \ ft/ftcontroller.h \ ft/ftdata.h \ @@ -532,13 +528,6 @@ HEADERS += util/folderiterator.h \ util/rsscopetimer.h \ util/stacktrace.h -SOURCES += dbase/cachestrapper.cc \ - dbase/fimonitor.cc \ - dbase/findex.cc \ - dbase/fistore.cc \ - dbase/rsexpr.cc - - SOURCES += ft/ftchunkmap.cc \ ft/ftcontroller.cc \ ft/ftdatamultiplex.cc \ diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 8ca770a76..0a8537bb7 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -236,7 +236,7 @@ public: RsPeerId id; std::string name; RsFileHash hash; - std::string path; + std::string path; // full path of the parent directory, when it is a file; full path of the dir otherwise. uint64_t count; uint32_t age; FileStorageFlags flags;