mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 17:36:19 -05: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
@ -160,6 +160,8 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
||||
std::cerr << "FileIndexMonitor::loadCache() Success!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
fi.root->row = 0;
|
||||
fi.root->name = data.pname ;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -466,6 +468,7 @@ void FileIndexMonitor::updateCycle()
|
||||
std::cerr << "List of Files to rehash in: " << dirpath << std::endl;
|
||||
#endif
|
||||
fiMods = true;
|
||||
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
}
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
@ -480,10 +483,10 @@ void FileIndexMonitor::updateCycle()
|
||||
}
|
||||
#endif
|
||||
|
||||
/* update files */
|
||||
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
||||
{
|
||||
// currentJob = "Hashing file " + realpath ;
|
||||
/* update files */
|
||||
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
||||
{
|
||||
// currentJob = "Hashing file " + realpath ;
|
||||
|
||||
if (hashFile(realpath, (*hit)))
|
||||
{
|
||||
@ -492,8 +495,8 @@ void FileIndexMonitor::updateCycle()
|
||||
|
||||
/* update fileIndex with new time */
|
||||
/* update with new time */
|
||||
fi.updateFileEntry(dirpath, *hit, stamp);
|
||||
|
||||
fi.updateFileEntry(dirpath, *hit, stamp);
|
||||
|
||||
/* unlock dirs */
|
||||
fiMutex.unlock();
|
||||
}
|
||||
@ -503,18 +506,20 @@ void FileIndexMonitor::updateCycle()
|
||||
}
|
||||
|
||||
/* don't hit the disk too hard! */
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep(10000); /* 1/100 sec */
|
||||
#else
|
||||
|
||||
Sleep(10);
|
||||
Sleep(10);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
}
|
||||
// currentJob = "" ;
|
||||
}
|
||||
}
|
||||
|
||||
if (filesToHash.size() > 0)
|
||||
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
}
|
||||
|
||||
fiMutex.lock(); { /* LOCKED DIRS */
|
||||
|
||||
@ -543,12 +548,12 @@ void FileIndexMonitor::updateCycle()
|
||||
fiMods = true;
|
||||
}
|
||||
|
||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||
|
||||
}
|
||||
|
||||
if (fiMods)
|
||||
saveFileIndexes() ;
|
||||
locked_saveFileIndexes() ;
|
||||
|
||||
fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||
|
||||
{
|
||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||
@ -557,10 +562,10 @@ void FileIndexMonitor::updateCycle()
|
||||
cb->notifyHashingInfo("") ;
|
||||
}
|
||||
|
||||
void FileIndexMonitor::saveFileIndexes()
|
||||
|
||||
void FileIndexMonitor::locked_saveFileIndexes()
|
||||
{
|
||||
/* store to the cacheDirectory */
|
||||
RsStackMutex mutex(fiMutex) ; /* LOCKED DIRS */
|
||||
|
||||
std::string path = getCacheDir();
|
||||
|
||||
@ -634,6 +639,8 @@ void FileIndexMonitor::saveFileIndexes()
|
||||
|
||||
void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
|
||||
{
|
||||
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
|
||||
bool fimods = false ;
|
||||
#ifdef FIM_DEBUG
|
||||
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)
|
||||
saveFileIndexes() ;
|
||||
{
|
||||
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
|
||||
locked_saveFileIndexes() ;
|
||||
}
|
||||
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
}
|
||||
/* interface */
|
||||
void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs)
|
||||
{
|
||||
cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
|
||||
std::list<SharedDirInfo> checkeddirs;
|
||||
|
||||
@ -703,32 +715,30 @@ void FileIndexMonitor::setSharedDirectories(std::list<SharedDirInfo> dirs)
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */
|
||||
RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */
|
||||
|
||||
pendingDirs = true;
|
||||
pendingDirList = checkeddirs;
|
||||
}
|
||||
pendingDirs = true;
|
||||
pendingDirList = checkeddirs;
|
||||
|
||||
cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0);
|
||||
}
|
||||
|
||||
/* interface */
|
||||
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 */
|
||||
if (pendingDirs)
|
||||
dirs = pendingDirList;
|
||||
else
|
||||
{
|
||||
/* get actual list (not pending stuff) */
|
||||
std::map<std::string, SharedDirInfo>::const_iterator it;
|
||||
/* must provide pendingDirs, as other parts depend on instanteous response */
|
||||
// if (pendingDirs)
|
||||
// dirs = pendingDirList;
|
||||
// else
|
||||
// {
|
||||
/* get actual list (not pending stuff) */
|
||||
std::map<std::string, SharedDirInfo>::const_iterator it;
|
||||
|
||||
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
|
||||
dirs.push_back(it->second) ;
|
||||
}
|
||||
}
|
||||
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
|
||||
dirs.push_back(it->second) ;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -821,6 +831,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
|
||||
|
||||
fi.setRootDirectories(topdirs, 0);
|
||||
|
||||
locked_saveFileIndexes() ;
|
||||
fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||
|
||||
return true;
|
||||
@ -899,3 +910,29 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
|
||||
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) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,9 +67,6 @@ class NotifyBase ;
|
||||
* 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
|
||||
{
|
||||
public:
|
||||
@ -95,6 +92,11 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||
virtual void run(); /* overloaded from RsThread */
|
||||
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);
|
||||
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
|
||||
void updateShareFlags(const SharedDirInfo& info) ;
|
||||
@ -107,7 +109,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||
|
||||
private:
|
||||
// saves file indexs and update the cache.
|
||||
void saveFileIndexes() ;
|
||||
void locked_saveFileIndexes() ;
|
||||
|
||||
/* the mutex should be locked before calling... these. */
|
||||
std::string locked_findRealRoot(std::string base) const;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <rsiface/rstypes.h>
|
||||
|
||||
class ostream;
|
||||
|
||||
@ -225,6 +226,8 @@ class FileIndex
|
||||
int searchHash(std::string hash, 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;
|
||||
};
|
||||
|
||||
|
@ -423,7 +423,10 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
@ -55,7 +55,7 @@ ShareManager::ShareManager(QWidget *parent, Qt::WFlags flags)
|
||||
connect( ui.shareddirList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirListCostumPopupMenu( QPoint ) ) );
|
||||
|
||||
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();
|
||||
|
||||
@ -86,6 +86,8 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint point )
|
||||
/** Loads the settings for this page */
|
||||
void ShareManager::load()
|
||||
{
|
||||
std::cerr << "ShareManager:: In load !!!!!" << std::endl ;
|
||||
|
||||
std::list<SharedDirInfo>::const_iterator it;
|
||||
std::list<SharedDirInfo> dirs;
|
||||
rsFiles->getSharedDirectories(dirs);
|
||||
@ -154,6 +156,7 @@ void ShareManager::load()
|
||||
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
|
||||
|
||||
listWidget->update(); /* update display */
|
||||
update();
|
||||
}
|
||||
|
||||
void ShareManager::showYourself()
|
||||
@ -171,8 +174,8 @@ void ShareManager::addShareDirectory()
|
||||
*/
|
||||
|
||||
|
||||
QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "",
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "",
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
/* add it to the server */
|
||||
std::string dir = qdir.toStdString();
|
||||
@ -184,8 +187,8 @@ void ShareManager::addShareDirectory()
|
||||
|
||||
rsFiles->addSharedDirectory(sdi);
|
||||
|
||||
messageBoxOk(tr("Shared Directory Added!"));
|
||||
load();
|
||||
messageBoxOk(tr("Shared Directory Added!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +239,6 @@ void ShareManager::removeShareDirectory()
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user