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:
csoler 2009-08-09 20:00:25 +00:00
parent 4157321000
commit 792ddf1d25
6 changed files with 228 additions and 47 deletions

View File

@ -160,6 +160,8 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
std::cerr << "FileIndexMonitor::loadCache() Success!"; std::cerr << "FileIndexMonitor::loadCache() Success!";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
fi.root->row = 0;
fi.root->name = data.pname ;
} }
else else
{ {
@ -466,6 +468,7 @@ void FileIndexMonitor::updateCycle()
std::cerr << "List of Files to rehash in: " << dirpath << std::endl; std::cerr << "List of Files to rehash in: " << dirpath << std::endl;
#endif #endif
fiMods = true; fiMods = true;
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
} }
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
@ -480,10 +483,10 @@ void FileIndexMonitor::updateCycle()
} }
#endif #endif
/* update files */ /* update files */
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++) for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
{ {
// currentJob = "Hashing file " + realpath ; // currentJob = "Hashing file " + realpath ;
if (hashFile(realpath, (*hit))) if (hashFile(realpath, (*hit)))
{ {
@ -492,8 +495,8 @@ void FileIndexMonitor::updateCycle()
/* update fileIndex with new time */ /* update fileIndex with new time */
/* update with new time */ /* update with new time */
fi.updateFileEntry(dirpath, *hit, stamp); fi.updateFileEntry(dirpath, *hit, stamp);
/* unlock dirs */ /* unlock dirs */
fiMutex.unlock(); fiMutex.unlock();
} }
@ -503,18 +506,20 @@ void FileIndexMonitor::updateCycle()
} }
/* don't hit the disk too hard! */ /* don't hit the disk too hard! */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
usleep(10000); /* 1/100 sec */ usleep(10000); /* 1/100 sec */
#else #else
Sleep(10); Sleep(10);
#endif #endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
} }
// currentJob = "" ;
} if (filesToHash.size() > 0)
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
}
fiMutex.lock(); { /* LOCKED DIRS */ fiMutex.lock(); { /* LOCKED DIRS */
@ -543,12 +548,12 @@ void FileIndexMonitor::updateCycle()
fiMods = true; fiMods = true;
} }
} fiMutex.unlock(); /* UNLOCKED DIRS */ }
if (fiMods) if (fiMods)
saveFileIndexes() ; locked_saveFileIndexes() ;
fiMutex.unlock(); /* UNLOCKED DIRS */
{ {
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/ RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
@ -557,10 +562,10 @@ void FileIndexMonitor::updateCycle()
cb->notifyHashingInfo("") ; cb->notifyHashingInfo("") ;
} }
void FileIndexMonitor::saveFileIndexes()
void FileIndexMonitor::locked_saveFileIndexes()
{ {
/* store to the cacheDirectory */ /* store to the cacheDirectory */
RsStackMutex mutex(fiMutex) ; /* LOCKED DIRS */
std::string path = getCacheDir(); std::string path = getCacheDir();
@ -634,6 +639,8 @@ void FileIndexMonitor::saveFileIndexes()
void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir) void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
{ {
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
bool fimods = false ; bool fimods = false ;
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ; std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ;
@ -665,11 +672,16 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
} }
} }
if(fimods) if(fimods)
saveFileIndexes() ; {
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
locked_saveFileIndexes() ;
}
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
} }
/* interface */ /* interface */
void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs) void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs)
{ {
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
std::list<SharedDirInfo> checkeddirs; std::list<SharedDirInfo> checkeddirs;
@ -703,32 +715,30 @@ void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs)
closedir(dir); closedir(dir);
} }
{ RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */
RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */
pendingDirs = true; pendingDirs = true;
pendingDirList = checkeddirs; pendingDirList = checkeddirs;
}
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
} }
/* interface */ /* interface */
void FileIndexMonitor::getSharedDirectories(std::list<SharedDirInfo> &dirs) void FileIndexMonitor::getSharedDirectories(std::list<SharedDirInfo> &dirs)
{ {
{ RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
/* must provide pendingDirs, as other parts depend on instanteous response */ /* must provide pendingDirs, as other parts depend on instanteous response */
if (pendingDirs) // if (pendingDirs)
dirs = pendingDirList; // dirs = pendingDirList;
else // else
{ // {
/* get actual list (not pending stuff) */ /* get actual list (not pending stuff) */
std::map<std::string, SharedDirInfo>::const_iterator it; std::map<std::string, SharedDirInfo>::const_iterator it;
for(it = directoryMap.begin(); it != directoryMap.end(); it++) for(it = directoryMap.begin(); it != directoryMap.end(); it++)
dirs.push_back(it->second) ; dirs.push_back(it->second) ;
} // }
}
} }
@ -821,6 +831,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
fi.setRootDirectories(topdirs, 0); fi.setRootDirectories(topdirs, 0);
locked_saveFileIndexes() ;
fiMutex.unlock(); /* UNLOCKED DIRS */ fiMutex.unlock(); /* UNLOCKED DIRS */
return true; return true;
@ -899,3 +910,29 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
return true; return true;
} }
int FileIndexMonitor::RequestDirDetails(std::string uid, std::string path, DirDetails &details) const
{
/* lock it up */
RsStackMutex mutex(fiMutex) ;
return (uid == fi.root->id) ;
}
int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
{
RsStackMutex mutex(fiMutex) ;
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::RequestDirDetails() ref=" << ref << " flags: " << flags << std::endl;
#endif
/* root case */
#ifdef FIM_DEBUG
fi.root->checkParentPointers();
#endif
return fi.RequestDirDetails(ref,details,flags) ;
}

View File

@ -67,9 +67,6 @@ class NotifyBase ;
* FileIndexMonitor * FileIndexMonitor
*****************************************************************************************/ *****************************************************************************************/
static const uint32_t RS_SHARED_FLAGS_PUBLIC = 0x0001 ;
static const uint32_t RS_SHARED_FLAGS_ANONYM = 0x0002 ;
class FileIndexMonitor: public CacheSource, public RsThread class FileIndexMonitor: public CacheSource, public RsThread
{ {
public: public:
@ -95,6 +92,11 @@ class FileIndexMonitor: public CacheSource, public RsThread
virtual void run(); /* overloaded from RsThread */ virtual void run(); /* overloaded from RsThread */
void updateCycle(); void updateCycle();
// Interface for browsing dir hirarchy
int RequestDirDetails(void*, DirDetails&, uint32_t) const ;
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const ;
// set/update shared directories
virtual void setSharedDirectories(std::list<SharedDirInfo> dirs); virtual void setSharedDirectories(std::list<SharedDirInfo> dirs);
void getSharedDirectories(std::list<SharedDirInfo>& dirs); void getSharedDirectories(std::list<SharedDirInfo>& dirs);
void updateShareFlags(const SharedDirInfo& info) ; void updateShareFlags(const SharedDirInfo& info) ;
@ -107,7 +109,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
private: private:
// saves file indexs and update the cache. // saves file indexs and update the cache.
void saveFileIndexes() ; void locked_saveFileIndexes() ;
/* the mutex should be locked before calling... these. */ /* the mutex should be locked before calling... these. */
std::string locked_findRealRoot(std::string base) const; std::string locked_findRealRoot(std::string base) const;

View File

@ -35,8 +35,8 @@
#include <openssl/sha.h> #include <openssl/sha.h>
#define FI_DEBUG 1
/**** /****
* #define FI_DEBUG 1
* #define FI_DEBUG_ALL 1 * #define FI_DEBUG_ALL 1
****/ ****/
@ -1110,3 +1110,137 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
return 0; 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;
}

View File

@ -30,6 +30,7 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <stdint.h> #include <stdint.h>
#include <rsiface/rstypes.h>
class ostream; class ostream;
@ -225,6 +226,8 @@ class FileIndex
int searchHash(std::string hash, std::list<FileEntry *> &results) const; int searchHash(std::string hash, std::list<FileEntry *> &results) const;
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const; int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
/* browse thru directories */
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const;
PersonEntry *root; PersonEntry *root;
}; };

View File

@ -423,7 +423,10 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
} }
#endif #endif
return mFiStore->RequestDirDetails(ref, details, flags); if(flags & DIR_FLAGS_LOCAL)
return mFiMon->RequestDirDetails(ref, details, flags);
else
return mFiStore->RequestDirDetails(ref, details, flags);
} }
/***************************************************************/ /***************************************************************/

View File

@ -55,7 +55,7 @@ ShareManager::ShareManager(QWidget *parent, Qt::WFlags flags)
connect( ui.shareddirList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirListCostumPopupMenu( QPoint ) ) ); connect( ui.shareddirList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirListCostumPopupMenu( QPoint ) ) );
ui.addButton->setToolTip(tr("Add a Share Directory")); ui.addButton->setToolTip(tr("Add a Share Directory"));
ui.removeButton->setToolTip(tr("Remove selected Shared Directory")); ui.removeButton->setToolTip(tr("Stop sharing selected Directory"));
load(); load();
@ -86,6 +86,8 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint point )
/** Loads the settings for this page */ /** Loads the settings for this page */
void ShareManager::load() void ShareManager::load()
{ {
std::cerr << "ShareManager:: In load !!!!!" << std::endl ;
std::list<SharedDirInfo>::const_iterator it; std::list<SharedDirInfo>::const_iterator it;
std::list<SharedDirInfo> dirs; std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs); rsFiles->getSharedDirectories(dirs);
@ -154,6 +156,7 @@ void ShareManager::load()
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory())); //ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
listWidget->update(); /* update display */ listWidget->update(); /* update display */
update();
} }
void ShareManager::showYourself() void ShareManager::showYourself()
@ -171,8 +174,8 @@ void ShareManager::addShareDirectory()
*/ */
QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "", QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
/* add it to the server */ /* add it to the server */
std::string dir = qdir.toStdString(); std::string dir = qdir.toStdString();
@ -184,8 +187,8 @@ void ShareManager::addShareDirectory()
rsFiles->addSharedDirectory(sdi); rsFiles->addSharedDirectory(sdi);
messageBoxOk(tr("Shared Directory Added!"));
load(); load();
messageBoxOk(tr("Shared Directory Added!"));
} }
} }
@ -236,7 +239,6 @@ void ShareManager::removeShareDirectory()
} }
else else
return; return;
} }
} }