From 7b534ba299cc62b9eb49d35b301e69c5ed55fa28 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 11 Aug 2009 19:43:51 +0000 Subject: [PATCH] - 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 --- libretroshare/src/dbase/fimonitor.cc | 3 +++ libretroshare/src/dbase/findex.cc | 25 ++++++++++++++++++++++- retroshare-gui/src/gui/RemoteDirModel.cpp | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index fee6e7fc3..93cae47ee 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -968,6 +968,9 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t bool b = fi.RequestDirDetails(ref,details,flags) ; + if(!b) + return false ; + // look for the top level and setup flags accordingly FileEntry *file = (FileEntry *) ref; diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 7e6eb4419..0bb5bc560 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -40,6 +40,13 @@ * #define FI_DEBUG_ALL 1 ****/ +static std::set _pointers ; +static void registerEntry(void*p) { _pointers.insert(p) ; } +static void unregisterEntry(void*p) +{ + _pointers.erase(p) ; +} + DirEntry::~DirEntry() { /* cleanup */ @@ -48,12 +55,14 @@ DirEntry::~DirEntry() for(dit = subdirs.begin(); dit != subdirs.end(); dit++) { + unregisterEntry((void*)dit->second) ; delete (dit->second); } subdirs.clear(); for(fit = files.begin(); fit != files.end(); fit++) { + unregisterEntry((void*)fit->second) ; delete (fit->second); } files.clear(); @@ -129,6 +138,7 @@ int DirEntry::removeDir(std::string name) ndir = (it->second); subdirs.erase(it); + unregisterEntry((void*)ndir) ; delete ndir; /* update row counters */ updateChildRows(); @@ -158,6 +168,7 @@ int DirEntry::removeFile(std::string name) nfile = (it->second); files.erase(it); + unregisterEntry((void*)nfile) ; delete nfile; /* update row counters */ updateChildRows(); @@ -188,6 +199,7 @@ int DirEntry::removeOldDir(std::string name, time_t old) std::cerr << std::endl; #endif subdirs.erase(it); + unregisterEntry((void*)ndir) ; delete ndir; /* update row counters */ @@ -363,6 +375,7 @@ DirEntry *DirEntry::updateDir(FileEntry fe, time_t utime) std::cerr << std::endl; #endif ndir = new DirEntry(); + registerEntry((void*)ndir) ; ndir -> parent = this; ndir -> path = path + "/" + fe.name; ndir -> name = fe.name; @@ -404,6 +417,7 @@ FileEntry *DirEntry::updateFile(FileEntry fe, time_t utime) #endif nfile = new FileEntry(); + registerEntry((void*)nfile) ; nfile -> parent = this; nfile -> name = fe.name; nfile -> hash = fe.hash; @@ -485,10 +499,12 @@ int DirEntry::print(std::ostream &out) FileIndex::FileIndex(std::string pid) { root = new PersonEntry(pid); + registerEntry(root) ; } FileIndex::~FileIndex() { + unregisterEntry((void*)root) ; delete root; } @@ -661,7 +677,6 @@ int FileIndex::printFileIndex(std::ostream &out) return 1; } - int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_t size) { 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: { std::string pid = root -> id; + unregisterEntry((void*)root) ; delete root; /* to clean up old entries */ root = new PersonEntry(pid); + registerEntry((void*)root) ; /* shallow copy of all except id */ ndir = dirlist.back(); @@ -746,6 +763,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_ /* now cleanup (can't call standard delete) */ ndir->subdirs.clear(); ndir->files.clear(); + unregisterEntry((void*)ndir) ; delete ndir; ndir = NULL; @@ -806,6 +824,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_ goto error; } nfile = new FileEntry(); + registerEntry((void*)nfile) ; nfile->name = tokens[0]; nfile->hash = tokens[1]; nfile->size = atoll(tokens[2].c_str()); @@ -830,6 +849,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_ goto error; } ndir = new DirEntry(); + registerEntry((void*)ndir) ; ndir->name = tokens[0]; ndir->path = tokens[1]; 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 */ + if(ref != NULL && _pointers.find(ref) == _pointers.end()) + return false ; + FileEntry *file = (FileEntry *) ref; DirEntry *dir = dynamic_cast(file); diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 8329344ac..c52148226 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -712,7 +712,7 @@ QString RemoteDirModel::getFlagsString(uint32_t flags) std::cerr << "RemoteDirModel::preMods()" << std::endl; #endif //modelAboutToBeReset(); - reset(); +// reset(); layoutAboutToBeChanged(); }