From ac242ce58bde9bfe22eb49b323968ff771a5fd5d Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 16 Aug 2016 23:44:48 +0200 Subject: [PATCH] fixed display of own files --- .../src/file_sharing/directory_storage.cc | 160 ++++++++++-------- .../src/file_sharing/directory_storage.h | 8 +- libretroshare/src/file_sharing/p3filelists.cc | 57 +++++-- libretroshare/src/ft/ftserver.cc | 2 +- libretroshare/src/retroshare/rstypes.h | 5 +- libretroshare/src/rsserver/rstypes.cc | 21 ++- 6 files changed, 155 insertions(+), 98 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 7b913b4c3..77b9e70c9 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -3,6 +3,8 @@ #include "util/rsstring.h" #include "directory_storage.h" +#define DEBUG_DIRECTORY_STORAGE 1 + /******************************************************************************************************************/ /* Internal File Hierarchy Storage */ /******************************************************************************************************************/ @@ -71,7 +73,7 @@ class InternalFileHierarchyStorage { mNodes.push_back(new DirEntry("")) ; mNodes.back()->row=0; - mNodes.back()->parent_index=-1; + mNodes.back()->parent_index=0; } int parentRow(DirectoryStorage::EntryIndex e) @@ -153,7 +155,7 @@ class InternalFileHierarchyStorage if(mNodes.empty() || indx==DirectoryStorage::NO_INDEX || indx >= mNodes.size() || mNodes[indx] == NULL) return nodeAccessError("checkIndex(): Node does not exist") ; - if(! mNodes[indx]->type() & type) + if(! (mNodes[indx]->type() & type)) return nodeAccessError("checkIndex(): Node is of wrong type") ; return true; @@ -351,7 +353,10 @@ private: } DirEntry& d(*static_cast(mNodes[node])); - std::cerr << indent << "dir:" << d.dir_name << std::endl; + std::cerr << indent << "dir:" << d.dir_name << ", subdirs: " ; + for(int i=0;isubdirs.size() + dir_entry->subfiles.size(); + d.min_age = now - dir_entry->most_recent_time ; + d.name = dir_entry->dir_name; + d.path = dir_entry->dir_parent_path + "/" + dir_entry->dir_name ; + d.parent = (void*)(intptr_t)dir_entry->parent_index ; + + if(indx == 0) + { + d.type = DIR_TYPE_PERSON ; + d.name = mPeerId.toStdString(); + } + } + else + { + const InternalFileHierarchyStorage::FileEntry *file_entry = mFileHierarchy->getFileEntry(indx) ; +#ifdef DEBUG_DIRECTORY_STORAGE + std::cerr << "FileIndexStore::extractData() ref=file" << std::endl; +#endif + d.type = DIR_TYPE_FILE; + d.count = file_entry->file_size; + d.min_age = now - file_entry->file_modtime ; + d.name = file_entry->file_name; + d.hash = file_entry->file_hash; + d.age = now - file_entry->file_modtime; + d.parent = (void*)(intptr_t)file_entry->parent_index ; + + const InternalFileHierarchyStorage::DirEntry *parent_dir_entry = mFileHierarchy->getDirEntry(file_entry->parent_index); + + if(parent_dir_entry != NULL) + d.path = parent_dir_entry->dir_parent_path + "/" + parent_dir_entry->dir_name + "/" ; + else + d.path = "" ; + } + + d.flags.clear() ; + + return true; +} /******************************************************************************************************************/ /* Local Directory Storage */ /******************************************************************************************************************/ @@ -627,78 +708,19 @@ std::string LocalDirectoryStorage::locked_findRealRootFromVirtualFilename(const bool LocalDirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) { - d.children.clear() ; - time_t now = time(NULL) ; + bool res = DirectoryStorage::extractData(indx,d) ; - const InternalFileHierarchyStorage::DirEntry *dir_entry = mFileHierarchy->getDirEntry(indx) ; + if(!res) + return false; - if (dir_entry != NULL) /* has children --- fill */ - { -#ifdef FI_DEBUG - std::cerr << "FileIndex::extractData() ref=dir" << std::endl; -#endif - /* extract all the entries */ + // here we should update the file sharing flags - for(DirectoryStorage::DirIterator it(this,indx);it;++it) - { - DirStub stub; - stub.type = DIR_TYPE_DIR; - stub.name = it.name(); - stub.ref = (void*)(intptr_t)*it; // this is updated by the caller, who knows which friend we're dealing with - - d.children.push_back(stub); - } - - for(DirectoryStorage::FileIterator it(this,indx);it;++it) - { - DirStub stub; - stub.type = DIR_TYPE_FILE; - stub.name = it.name(); - stub.ref = (void*)(intptr_t)*it; - - d.children.push_back(stub); - } - - if(dir_entry->parent_index == 0) - d.type = DIR_TYPE_PERSON ; - else - d.type = DIR_TYPE_DIR; - - d.hash.clear() ; - d.count = dir_entry->subdirs.size() + dir_entry->subfiles.size(); - d.min_age = now - dir_entry->most_recent_time ; - d.name = dir_entry->dir_name; - d.path = dir_entry->dir_parent_path + "/" + dir_entry->dir_name ; - d.parent = (void*)(intptr_t)dir_entry->parent_index ; - } - else - { - const InternalFileHierarchyStorage::FileEntry *file_entry = mFileHierarchy->getFileEntry(indx) ; -#ifdef FI_DEBUG - std::cerr << "FileIndexStore::extractData() ref=file" << std::endl; -#endif - d.type = DIR_TYPE_FILE; - d.count = file_entry->file_size; - d.min_age = now - file_entry->file_modtime ; - d.name = file_entry->file_name; - d.hash = file_entry->file_hash; - d.age = now - file_entry->file_modtime; - d.parent = (void*)(intptr_t)file_entry->parent_index ; - - const InternalFileHierarchyStorage::DirEntry *parent_dir_entry = mFileHierarchy->getDirEntry(file_entry->parent_index); - - if(parent_dir_entry != NULL) - d.path = parent_dir_entry->dir_parent_path + "/" + parent_dir_entry->dir_name + "/" ; - else - d.path = "" ; - } - -#ifdef FI_DEBUG - std::cerr << "FileIndexStore::extractData() name: " << file->name << std::endl; -#endif d.flags.clear() ; /* find parent pointer, and row */ + std::cerr << "LocalDirectoryStorage::extractData(): Returning this:" << std::endl; + std::cerr << d << std::endl; + return true; } diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index a96790684..9f2b63be9 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -28,7 +28,7 @@ class DirectoryStorage void getFileDetails(EntryIndex i) ; uint32_t getEntryType(const EntryIndex& indx) ; // returns DIR_TYPE_*, not the internal directory storage stuff. - virtual bool extractData(const EntryIndex& indx,DirDetails& d) =0; + virtual bool extractData(const EntryIndex& indx,DirDetails& d); // This class allows to abstractly browse the stored directory hierarchy in a depth-first manner. // It gives access to sub-files and sub-directories below. @@ -121,12 +121,6 @@ class RemoteDirectoryStorage: public DirectoryStorage public: RemoteDirectoryStorage(const RsPeerId& pid,const std::string& fname) : DirectoryStorage(fname,pid) {} virtual ~RemoteDirectoryStorage() {} - - virtual bool extractData(const EntryIndex& indx,DirDetails& d) - { - NOT_IMPLEMENTED(); - return false; - } }; class LocalDirectoryStorage: public DirectoryStorage diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 09cf31e53..20e2c5c6c 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -137,7 +137,6 @@ void p3FileDatabase::stopThreads() void p3FileDatabase::tickWatchers() { - NOT_IMPLEMENTED(); } void p3FileDatabase::tickRecv() @@ -146,7 +145,6 @@ void p3FileDatabase::tickRecv() void p3FileDatabase::tickSend() { // go through the list of out requests and send them to the corresponding friends, if they are online. - NOT_IMPLEMENTED(); } bool p3FileDatabase::loadList(std::list& items) @@ -295,6 +293,13 @@ bool p3FileDatabase::convertPointerToEntryIndex(const void *p, EntryIndex& e, ui e = EntryIndex( *reinterpret_cast(&p) & ENTRY_INDEX_BIT_MASK ) ; friend_index = (*reinterpret_cast(&p)) >> NB_ENTRY_INDEX_BITS ; + if(friend_index == 0) + { + std::cerr << "(EE) Cannot find friend index in pointer. Encoded value is zero!" << std::endl; + return false; + } + friend_index--; + return true; } bool p3FileDatabase::convertEntryIndexToPointer(const EntryIndex& e, uint32_t fi, void *& p) @@ -309,13 +314,13 @@ bool p3FileDatabase::convertEntryIndexToPointer(const EntryIndex& e, uint32_t fi uint32_t fe = (uint32_t)e ; - if(fi >= (1<= (1<< NB_ENTRY_INDEX_BITS)) + if(fi+1 >= (1<= (1<< NB_ENTRY_INDEX_BITS)) { std::cerr << "(EE) cannot convert entry index " << e << " of friend with index " << fi << " to pointer." << std::endl; return false ; } - p = reinterpret_cast( (fi << NB_ENTRY_INDEX_BITS ) + (fe & ENTRY_INDEX_BIT_MASK)) ; + p = reinterpret_cast( ( (1+fi) << NB_ENTRY_INDEX_BITS ) + (fe & ENTRY_INDEX_BIT_MASK)) ; return true; } @@ -325,10 +330,36 @@ bool p3FileDatabase::convertEntryIndexToPointer(const EntryIndex& e, uint32_t fi int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags flags) const { // Case where the pointer is NULL, which means we're at the top of the list of shared directories for all friends (including us) + // or at the top of our own list of shred directories, depending on the flags. if (ref == NULL) { - for(uint32_t i=0;igetOwnId().toStdString(); + stub.ref = p; + d.children.push_back(stub); + } + else for(uint32_t i=1;iroot(),i,p); @@ -339,24 +370,14 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags stub.ref = p; d.children.push_back(stub); } - d.count = mDirectories.size(); - d.parent = NULL; - d.prow = -1; - d.ref = NULL; - d.type = DIR_TYPE_ROOT; - d.name = "root"; - d.hash.clear() ; - d.path = "root"; - d.age = 0; - d.flags.clear() ; - d.min_age = 0 ; + d.count = d.children.size(); return true ; } uint32_t fi; - EntryIndex e ; + DirectoryStorage::EntryIndex e ; convertPointerToEntryIndex(ref,e,fi); @@ -505,7 +526,7 @@ int p3FileDatabase::filterResults(const std::list& firesults,std::li for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) { DirDetails cdetails ; - RequestDirDetails ((void*)*rit,cdetails,FileSearchFlags(0u)); + RequestDirDetails ((void*)(intptr_t)*rit,cdetails,FileSearchFlags(0u)); #ifdef P3FILELISTS_DEBUG std::cerr << "Filtering candidate " << (*rit) << ", flags=" << cdetails.flags << ", peer=" << peer_id ; #endif diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 8a0424a5c..1268ea831 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -240,7 +240,7 @@ bool ftServer::getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& re bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info) { - return mFtController->alreadyHaveFile(hash, info); + return mFileDatabase->search(hash, RS_FILE_HINTS_LOCAL, info); } bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index d30b156eb..9ab56c70b 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -215,8 +215,7 @@ class FileInfo std::list parent_groups ; }; -std::ostream &operator<<(std::ostream &out, const FileInfo &info); - +std::ostream &operator<<(std::ostream &out, const FileInfo& info); class DirStub { @@ -247,6 +246,8 @@ public: std::list parent_groups; // parent groups for the shared directory }; +std::ostream &operator<<(std::ostream &out, const DirDetails& details); + class FileDetail { public: diff --git a/libretroshare/src/rsserver/rstypes.cc b/libretroshare/src/rsserver/rstypes.cc index c5c3c8b02..128f08005 100644 --- a/libretroshare/src/rsserver/rstypes.cc +++ b/libretroshare/src/rsserver/rstypes.cc @@ -44,7 +44,26 @@ * **********************************************************************/ - +std::ostream &operator<<(std::ostream &out, const DirDetails& d) +{ + std::cerr << "====DIR DETAILS====" << std::endl; + std::cerr << " parent pointer: " << (intptr_t)d.parent << std::endl; + std::cerr << " current pointer: " << (intptr_t)d.ref << std::endl; + std::cerr << " parent row : " << d.prow << std::endl; + std::cerr << " type : " << (int)d.type << std::endl; + std::cerr << " PeerId : " << d.id << std::endl; + std::cerr << " Name : " << d.name << std::endl; + std::cerr << " Hash : " << d.hash << std::endl; + std::cerr << " Path : " << d.path << std::endl; + std::cerr << " Count : " << d.count << std::endl; + std::cerr << " Age : " << d.age << std::endl; + std::cerr << " Min age : " << d.min_age << std::endl; + std::cerr << " Flags : " << d.flags << std::endl; + std::cerr << " Parent groups : " ; for(std::list::const_iterator it(d.parent_groups.begin());it!=d.parent_groups.end();++it) std::cerr << (*it) << " "; std::cerr << std::endl; + std::cerr << " Children : " ; for(std::list::const_iterator it(d.children.begin());it!=d.children.end();++it) std::cerr << (intptr_t)(*it).ref << " "; std::cerr << std::endl; + std::cerr << "===================" << std::endl; + return out; +} std::ostream &operator<<(std::ostream &out, const FileInfo &info) { out << "FileInfo: path: " << info.path;