fixed display of own files

This commit is contained in:
mr-alice 2016-08-16 23:44:48 +02:00
parent ca8f95c7f7
commit ac242ce58b
6 changed files with 155 additions and 98 deletions

View File

@ -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<DirEntry*>(mNodes[node]));
std::cerr << indent << "dir:" << d.dir_name << std::endl;
std::cerr << indent << "dir:" << d.dir_name << ", subdirs: " ;
for(int i=0;i<d.subdirs.size();++i)
std::cerr << d.subdirs[i] << " " ;
std::cerr << std::endl;
for(int i=0;i<d.subdirs.size();++i)
recursPrint(depth+1,d.subdirs[i]) ;
@ -531,6 +536,82 @@ bool LocalDirectoryStorage::getFileInfo(DirectoryStorage::EntryIndex i,FileInfo&
return true;
}
bool DirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d)
{
d.children.clear() ;
time_t now = time(NULL) ;
std::cerr << "LocalDirectoryStorage::extractData(). Index=" << indx << std::endl;
const InternalFileHierarchyStorage::DirEntry *dir_entry = mFileHierarchy->getDirEntry(indx) ;
if (dir_entry != NULL) /* has children --- fill */
{
#ifdef DEBUG_DIRECTORY_STORAGE
std::cerr << "FileIndex::extractData() ref=dir" << std::endl;
#endif
/* extract all the entries */
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);
}
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 ;
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;
}

View File

@ -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

View File

@ -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<RsItem *>& items)
@ -295,6 +293,13 @@ bool p3FileDatabase::convertPointerToEntryIndex(const void *p, EntryIndex& e, ui
e = EntryIndex( *reinterpret_cast<uint32_t*>(&p) & ENTRY_INDEX_BIT_MASK ) ;
friend_index = (*reinterpret_cast<uint32_t*>(&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<<NB_FRIEND_INDEX_BITS) || fe >= (1<< NB_ENTRY_INDEX_BITS))
if(fi+1 >= (1<<NB_FRIEND_INDEX_BITS) || fe >= (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<void*>( (fi << NB_ENTRY_INDEX_BITS ) + (fe & ENTRY_INDEX_BIT_MASK)) ;
p = reinterpret_cast<void*>( ( (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;i<mDirectories.size();++i)
d.ref = NULL ;
d.type = DIR_TYPE_ROOT;
d.count = 1;
d.parent = NULL;
d.prow = -1;
d.ref = NULL;
d.name = "root";
d.hash.clear() ;
d.path = "";
d.age = 0;
d.flags.clear() ;
d.min_age = 0 ;
d.children.clear();
if(flags & RS_FILE_HINTS_LOCAL)
{
void *p;
convertEntryIndexToPointer(0,0,p);
DirStub stub;
stub.type = DIR_TYPE_PERSON;
stub.name = mServCtrl->getOwnId().toStdString();
stub.ref = p;
d.children.push_back(stub);
}
else for(uint32_t i=1;i<mDirectories.size();++i)
{
void *p;
convertEntryIndexToPointer(mDirectories[i]->root(),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<EntryIndex>& firesults,std::li
for(std::list<EntryIndex>::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

View File

@ -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<RsPeerId>& srcIds)

View File

@ -215,8 +215,7 @@ class FileInfo
std::list<std::string> 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<std::string> parent_groups; // parent groups for the shared directory
};
std::ostream &operator<<(std::ostream &out, const DirDetails& details);
class FileDetail
{
public:

View File

@ -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<std::string>::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<DirStub>::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;