mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
Share Flags
- own directory browsing is now done through FileIndexMonitor. This allows: - to browse shared directories independently of their flags - to update files as they get hashed (yeah!) - still to do: - turtle requests should respect the share flags git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1507 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4157321000
commit
792ddf1d25
6 changed files with 228 additions and 47 deletions
|
@ -35,8 +35,8 @@
|
|||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#define FI_DEBUG 1
|
||||
/****
|
||||
* #define FI_DEBUG 1
|
||||
* #define FI_DEBUG_ALL 1
|
||||
****/
|
||||
|
||||
|
@ -1110,3 +1110,137 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
|
||||
{
|
||||
/* so cast *ref to a DirEntry */
|
||||
|
||||
FileEntry *file = (FileEntry *) ref;
|
||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||
|
||||
if (!ref)
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndexMonitor::RequestDirDetails() ref=NULL (root)" << std::endl;
|
||||
#endif
|
||||
/* local only */
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_PERSON;
|
||||
stub.name = root->name;
|
||||
stub.ref = root;
|
||||
details.children.push_back(stub);
|
||||
details.count = 1;
|
||||
|
||||
details.parent = NULL;
|
||||
details.prow = 0;
|
||||
details.ref = NULL;
|
||||
details.type = DIR_TYPE_ROOT;
|
||||
details.name = "";
|
||||
details.hash = "";
|
||||
details.path = "";
|
||||
details.age = 0;
|
||||
details.rank = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir) /* has children --- fill */
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndexStore::RequestDirDetails() ref=dir" << std::endl;
|
||||
#endif
|
||||
std::map<std::string, FileEntry *>::iterator fit;
|
||||
std::map<std::string, DirEntry *>::iterator dit;
|
||||
/* extract all the entries */
|
||||
for(dit = dir->subdirs.begin(); dit != dir->subdirs.end(); dit++)
|
||||
{
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_DIR;
|
||||
stub.name = (dit->second) -> name;
|
||||
stub.ref = (dit->second);
|
||||
|
||||
details.children.push_back(stub);
|
||||
}
|
||||
|
||||
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
|
||||
{
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_FILE;
|
||||
stub.name = (fit->second) -> name;
|
||||
stub.ref = (fit->second);
|
||||
|
||||
details.children.push_back(stub);
|
||||
}
|
||||
|
||||
details.type = DIR_TYPE_DIR;
|
||||
details.hash = "";
|
||||
details.count = dir->subdirs.size() + dir->files.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl;
|
||||
#endif
|
||||
details.type = DIR_TYPE_FILE;
|
||||
details.count = file->size;
|
||||
}
|
||||
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
||||
#endif
|
||||
details.ref = file;
|
||||
details.name = file->name;
|
||||
details.hash = file->hash;
|
||||
details.age = time(NULL) - file->modtime;
|
||||
details.rank = file->pop;
|
||||
|
||||
/* find parent pointer, and row */
|
||||
DirEntry *parent = file->parent;
|
||||
if (!parent) /* then must be root */
|
||||
{
|
||||
details.parent = NULL;
|
||||
details.prow = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
details.parent = parent;
|
||||
details.prow = parent->row;
|
||||
}
|
||||
|
||||
/* find peer id */
|
||||
parent = dir;
|
||||
if (!dir) /* cannot be null -> no files at root level */
|
||||
parent=file->parent;
|
||||
|
||||
// Well, yes, it can be null, beleive me. In such a case it may be that
|
||||
// file is a person entry.
|
||||
|
||||
PersonEntry *person;
|
||||
|
||||
if(parent==NULL)
|
||||
{
|
||||
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
||||
{
|
||||
std::cerr << "Major Error- Not PersonEntry!";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* NEW add path (to dir - if dir, or parent dir - if file? */
|
||||
details.path = parent->path;
|
||||
|
||||
while(parent->parent)
|
||||
parent = parent->parent;
|
||||
|
||||
/* we should end up on the PersonEntry */
|
||||
if (NULL == (person = dynamic_cast<PersonEntry *>(parent)))
|
||||
{
|
||||
std::cerr << "Major Error- Not PersonEntry!";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
details.id = person->id;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue