moved rsexpr to file_sharing directory

This commit is contained in:
mr-alice 2016-09-12 23:37:19 +02:00
parent 274f924ca0
commit 9f66c0050b
7 changed files with 102 additions and 56 deletions

View File

@ -2,6 +2,7 @@
#include "dir_hierarchy.h" #include "dir_hierarchy.h"
#include "filelist_io.h" #include "filelist_io.h"
//#include "rsexpr.h"
#define DEBUG_DIRECTORY_STORAGE 1 #define DEBUG_DIRECTORY_STORAGE 1
@ -570,6 +571,49 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list<D
return false; return false;
} }
int InternalFileHierarchyStorage::searchBoolExp(Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const
{
#ifdef TODO
for(std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
{
const std::string &str1 = static_cast<FileEntry*>(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<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &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<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
if(mNodes[it->second] != NULL)
{
const std::string &str1 = static_cast<FileEntry*>(mNodes[it->second])->file_name;
for(std::list<std::string>::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. bool InternalFileHierarchyStorage::check(std::string& error_string) const // checks consistency of storage.
{ {
// recurs go through all entries, check that all // recurs go through all entries, check that all

View File

@ -110,7 +110,12 @@ public:
uint32_t getType(DirectoryStorage::EntryIndex indx) const; uint32_t getType(DirectoryStorage::EntryIndex indx) const;
DirectoryStorage::EntryIndex getSubFileIndex(DirectoryStorage::EntryIndex parent_index,uint32_t file_tab_index); DirectoryStorage::EntryIndex getSubFileIndex(DirectoryStorage::EntryIndex parent_index,uint32_t file_tab_index);
DirectoryStorage::EntryIndex getSubDirIndex(DirectoryStorage::EntryIndex parent_index,uint32_t dir_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<DirectoryStorage::EntryIndex>& results); bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
int searchBoolExp(Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ;
bool check(std::string& error_string) const ;// checks consistency of storage. bool check(std::string& error_string) const ;// checks consistency of storage.

View File

@ -160,62 +160,29 @@ void DirectoryStorage::saveNextTag(unsigned char *data, uint32_t& offset, uint8_
void DirectoryStorage::load(const std::string& local_file_name) 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) ; RS_STACK_MUTEX(mDirStorageMtx) ;
mFileHierarchy->load(local_file_name); mFileHierarchy->load(local_file_name);
} }
void DirectoryStorage::save(const std::string& local_file_name) void DirectoryStorage::save(const std::string& local_file_name)
{ {
std::cerr << "DirectoryStorage::Save()" << std::endl;
RS_STACK_MUTEX(mDirStorageMtx) ; RS_STACK_MUTEX(mDirStorageMtx) ;
mFileHierarchy->save(local_file_name); mFileHierarchy->save(local_file_name);
// first write the header, than all fields.
} }
void DirectoryStorage::print() void DirectoryStorage::print()
{ {
RS_STACK_MUTEX(mDirStorageMtx) ; RS_STACK_MUTEX(mDirStorageMtx) ;
std::cerr << "LocalDirectoryStorage:" << std::endl;
mFileHierarchy->print(); mFileHierarchy->print();
} }
bool LocalDirectoryStorage::getFileInfo(DirectoryStorage::EntryIndex i,FileInfo& info) int DirectoryStorage::searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const
{ {
DirDetails d; RS_STACK_MUTEX(mDirStorageMtx) ;
extractData(i,d) ; return mFileHierarchy->searchTerms(terms,results);
}
info.storage_permission_flags = d.flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file. int DirectoryStorage::searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const
info.parent_groups = d.parent_groups; {
info.transfer_info_flags = TransferRequestFlags(); // various flags from RS_FILE_HINTS_* RS_STACK_MUTEX(mDirStorageMtx) ;
info.path = d.path + "/" + d.name; return mFileHierarchy->searchBoolExp(exp,results);
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<TransferInfo> peers;
info.priority = SPEED_NORMAL;
info.lastTS = 0;
return true;
} }
bool DirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) 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) ; 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<TransferInfo> peers;
info.priority = SPEED_NORMAL;
info.lastTS = 0;
return true;
}
bool LocalDirectoryStorage::getFileSharingPermissions(const EntryIndex& indx,FileStorageFlags& flags,std::list<RsNodeGroupId>& parent_groups) bool LocalDirectoryStorage::getFileSharingPermissions(const EntryIndex& indx,FileStorageFlags& flags,std::list<RsNodeGroupId>& parent_groups)
{ {
RS_STACK_MUTEX(mDirStorageMtx) ; RS_STACK_MUTEX(mDirStorageMtx) ;

View File

@ -24,9 +24,9 @@ class DirectoryStorage
void save() const ; void save() const ;
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const { NOT_IMPLEMENTED() ; return 0;} virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const ;
virtual int searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const ;
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ; virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ;
virtual int searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const { NOT_IMPLEMENTED() ; return 0; }
bool getDirUpdateTS(EntryIndex index,time_t& recurs_max_modf_TS,time_t& local_update_TS) ; 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) ; bool setDirUpdateTS(EntryIndex index,time_t recurs_max_modf_TS,time_t local_update_TS) ;

View File

@ -55,6 +55,7 @@ file_lists {
file_sharing/directory_storage.cc \ file_sharing/directory_storage.cc \
file_sharing/directory_updater.cc \ file_sharing/directory_updater.cc \
file_sharing/dir_hierarchy.cc \ file_sharing/dir_hierarchy.cc \
file_sharing/rsexpr.cc \
file_sharing/rsfilelistitems.cc file_sharing/rsfilelistitems.cc
} }
@ -366,11 +367,6 @@ INCLUDEPATH *= $${OPENPGPSDK_DIR}
PRE_TARGETDEPS *= $${OPENPGPSDK_DIR}/lib/libops.a PRE_TARGETDEPS *= $${OPENPGPSDK_DIR}/lib/libops.a
LIBS *= $${OPENPGPSDK_DIR}/lib/libops.a -lbz2 LIBS *= $${OPENPGPSDK_DIR}/lib/libops.a -lbz2
HEADERS += dbase/cachestrapper.h \
dbase/fimonitor.h \
dbase/findex.h \
dbase/fistore.h
HEADERS += ft/ftchunkmap.h \ HEADERS += ft/ftchunkmap.h \
ft/ftcontroller.h \ ft/ftcontroller.h \
ft/ftdata.h \ ft/ftdata.h \
@ -532,13 +528,6 @@ HEADERS += util/folderiterator.h \
util/rsscopetimer.h \ util/rsscopetimer.h \
util/stacktrace.h util/stacktrace.h
SOURCES += dbase/cachestrapper.cc \
dbase/fimonitor.cc \
dbase/findex.cc \
dbase/fistore.cc \
dbase/rsexpr.cc
SOURCES += ft/ftchunkmap.cc \ SOURCES += ft/ftchunkmap.cc \
ft/ftcontroller.cc \ ft/ftcontroller.cc \
ft/ftdatamultiplex.cc \ ft/ftdatamultiplex.cc \

View File

@ -236,7 +236,7 @@ public:
RsPeerId id; RsPeerId id;
std::string name; std::string name;
RsFileHash hash; 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; uint64_t count;
uint32_t age; uint32_t age;
FileStorageFlags flags; FileStorageFlags flags;