- added a pointer controller to findex to avoid RemoteDirModel to incidentally request for deleted pointers.

- suppressed auto-collapse of directories when updated.

Still To do:
	- auto-update QTreeView in PostMod() to avoid display inconsistencies.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1520 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-08-11 19:43:51 +00:00
parent cf2343105b
commit 7b534ba299
3 changed files with 28 additions and 2 deletions

View File

@ -968,6 +968,9 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
bool b = fi.RequestDirDetails(ref,details,flags) ; bool b = fi.RequestDirDetails(ref,details,flags) ;
if(!b)
return false ;
// look for the top level and setup flags accordingly // look for the top level and setup flags accordingly
FileEntry *file = (FileEntry *) ref; FileEntry *file = (FileEntry *) ref;

View File

@ -40,6 +40,13 @@
* #define FI_DEBUG_ALL 1 * #define FI_DEBUG_ALL 1
****/ ****/
static std::set<void*> _pointers ;
static void registerEntry(void*p) { _pointers.insert(p) ; }
static void unregisterEntry(void*p)
{
_pointers.erase(p) ;
}
DirEntry::~DirEntry() DirEntry::~DirEntry()
{ {
/* cleanup */ /* cleanup */
@ -48,12 +55,14 @@ DirEntry::~DirEntry()
for(dit = subdirs.begin(); dit != subdirs.end(); dit++) for(dit = subdirs.begin(); dit != subdirs.end(); dit++)
{ {
unregisterEntry((void*)dit->second) ;
delete (dit->second); delete (dit->second);
} }
subdirs.clear(); subdirs.clear();
for(fit = files.begin(); fit != files.end(); fit++) for(fit = files.begin(); fit != files.end(); fit++)
{ {
unregisterEntry((void*)fit->second) ;
delete (fit->second); delete (fit->second);
} }
files.clear(); files.clear();
@ -129,6 +138,7 @@ int DirEntry::removeDir(std::string name)
ndir = (it->second); ndir = (it->second);
subdirs.erase(it); subdirs.erase(it);
unregisterEntry((void*)ndir) ;
delete ndir; delete ndir;
/* update row counters */ /* update row counters */
updateChildRows(); updateChildRows();
@ -158,6 +168,7 @@ int DirEntry::removeFile(std::string name)
nfile = (it->second); nfile = (it->second);
files.erase(it); files.erase(it);
unregisterEntry((void*)nfile) ;
delete nfile; delete nfile;
/* update row counters */ /* update row counters */
updateChildRows(); updateChildRows();
@ -188,6 +199,7 @@ int DirEntry::removeOldDir(std::string name, time_t old)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
subdirs.erase(it); subdirs.erase(it);
unregisterEntry((void*)ndir) ;
delete ndir; delete ndir;
/* update row counters */ /* update row counters */
@ -363,6 +375,7 @@ DirEntry *DirEntry::updateDir(FileEntry fe, time_t utime)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
ndir = new DirEntry(); ndir = new DirEntry();
registerEntry((void*)ndir) ;
ndir -> parent = this; ndir -> parent = this;
ndir -> path = path + "/" + fe.name; ndir -> path = path + "/" + fe.name;
ndir -> name = fe.name; ndir -> name = fe.name;
@ -404,6 +417,7 @@ FileEntry *DirEntry::updateFile(FileEntry fe, time_t utime)
#endif #endif
nfile = new FileEntry(); nfile = new FileEntry();
registerEntry((void*)nfile) ;
nfile -> parent = this; nfile -> parent = this;
nfile -> name = fe.name; nfile -> name = fe.name;
nfile -> hash = fe.hash; nfile -> hash = fe.hash;
@ -485,10 +499,12 @@ int DirEntry::print(std::ostream &out)
FileIndex::FileIndex(std::string pid) FileIndex::FileIndex(std::string pid)
{ {
root = new PersonEntry(pid); root = new PersonEntry(pid);
registerEntry(root) ;
} }
FileIndex::~FileIndex() FileIndex::~FileIndex()
{ {
unregisterEntry((void*)root) ;
delete root; delete root;
} }
@ -661,7 +677,6 @@ int FileIndex::printFileIndex(std::ostream &out)
return 1; return 1;
} }
int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_t size) int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_t size)
{ {
std::ifstream file (filename.c_str(), std::ifstream::binary); std::ifstream file (filename.c_str(), std::ifstream::binary);
@ -735,8 +750,10 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
case 1: case 1:
{ {
std::string pid = root -> id; std::string pid = root -> id;
unregisterEntry((void*)root) ;
delete root; /* to clean up old entries */ delete root; /* to clean up old entries */
root = new PersonEntry(pid); root = new PersonEntry(pid);
registerEntry((void*)root) ;
/* shallow copy of all except id */ /* shallow copy of all except id */
ndir = dirlist.back(); ndir = dirlist.back();
@ -746,6 +763,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
/* now cleanup (can't call standard delete) */ /* now cleanup (can't call standard delete) */
ndir->subdirs.clear(); ndir->subdirs.clear();
ndir->files.clear(); ndir->files.clear();
unregisterEntry((void*)ndir) ;
delete ndir; delete ndir;
ndir = NULL; ndir = NULL;
@ -806,6 +824,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
goto error; goto error;
} }
nfile = new FileEntry(); nfile = new FileEntry();
registerEntry((void*)nfile) ;
nfile->name = tokens[0]; nfile->name = tokens[0];
nfile->hash = tokens[1]; nfile->hash = tokens[1];
nfile->size = atoll(tokens[2].c_str()); nfile->size = atoll(tokens[2].c_str());
@ -830,6 +849,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
goto error; goto error;
} }
ndir = new DirEntry(); ndir = new DirEntry();
registerEntry((void*)ndir) ;
ndir->name = tokens[0]; ndir->name = tokens[0];
ndir->path = tokens[1]; ndir->path = tokens[1];
ndir->size = atoi(tokens[2].c_str()); ndir->size = atoi(tokens[2].c_str());
@ -1114,6 +1134,9 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
{ {
/* so cast *ref to a DirEntry */ /* so cast *ref to a DirEntry */
if(ref != NULL && _pointers.find(ref) == _pointers.end())
return false ;
FileEntry *file = (FileEntry *) ref; FileEntry *file = (FileEntry *) ref;
DirEntry *dir = dynamic_cast<DirEntry *>(file); DirEntry *dir = dynamic_cast<DirEntry *>(file);

View File

@ -712,7 +712,7 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
std::cerr << "RemoteDirModel::preMods()" << std::endl; std::cerr << "RemoteDirModel::preMods()" << std::endl;
#endif #endif
//modelAboutToBeReset(); //modelAboutToBeReset();
reset(); // reset();
layoutAboutToBeChanged(); layoutAboutToBeChanged();
} }