loading/saving parent groups for directories.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5770 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-03 15:25:25 +00:00
parent 1762c7a842
commit d77c73adf4
7 changed files with 53 additions and 10 deletions

View File

@ -1036,7 +1036,13 @@ void FileIndexMonitor::locked_saveFileIndexes()
std::set<std::string> forbidden_dirs ;
for(std::map<std::string,SharedDirInfo>::const_iterator dit(directoryMap.begin());dit!=directoryMap.end();++dit)
{
std::cerr << " dir=" << dit->first << " : " ;
#ifdef FIM_DEBUG
std::cerr << " dir=" << dit->first << ", " ;
std::cerr << "parent groups: " ;
for(std::list<std::string>::const_iterator mit(dit->second.parent_groups.begin());mit!=dit->second.parent_groups.end();++mit)
std::cerr << (*mit) << ", " ;
std::cerr << std::endl;;
#endif
FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(*it,dit->second.shareflags,dit->second.parent_groups) ;
@ -1132,6 +1138,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
{
std::cerr << "** Updating to " << (*it).shareflags << "!!" << std::endl ;
(*it).shareflags = dir.shareflags ;
(*it).parent_groups = dir.parent_groups ;
break ;
}
}
@ -1143,6 +1150,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
{
std::cerr << "** Updating from " << it->second.shareflags << "!!" << std::endl ;
(*it).second.shareflags = dir.shareflags ;
(*it).second.parent_groups = dir.parent_groups ;
fimods = true ;
break ;
}

View File

@ -247,6 +247,7 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list<RsItem *>& sList)
fi->file.path = (*it).filename ;
fi->file.name = (*it).virtualname ;
fi->flags = (*it).shareflags.toUInt32() ;
fi->parent_groups = (*it).parent_groups ;
sList.push_back(fi);
}
@ -347,6 +348,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
SharedDirInfo info ;
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
info.virtualname = fi->file.name;
info.parent_groups = fi->parent_groups;
info.shareflags = FileStorageFlags(fi->flags) ;
info.shareflags &= PERMISSION_MASK ;

View File

@ -170,20 +170,24 @@ void RsFileConfigItem::clear()
file.TlvClear();
flags = 0;
parent_groups.clear() ;
}
std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileConfigItem", indent);
printRsItemBase(out, "RsFileConfigItem", indent);
uint16_t int_Indent = indent + 2;
file.print(out, int_Indent);
printIndent(out, int_Indent);
out << "flags: " << flags << std::endl;
printIndent(out, int_Indent); out << "flags: " << flags << std::endl;
printIndent(out, int_Indent); out << "groups:" ;
printRsItemEnd(out, "RsFileConfigItem", indent);
return out;
for(std::list<std::string>::const_iterator it(parent_groups.begin());it!=parent_groups.end();++it)
out << (*it) << " " ;
out << std::endl;
printRsItemEnd(out, "RsFileConfigItem", indent);
return out;
}
/*************************************************************************/
@ -348,7 +352,10 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item)
{
uint32_t s = 8; /* header */
s += item->file.TlvSize();
s += 4;
s += 4; // flags
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups
s += GetTlvStringSize(*it);
return s;
}
@ -377,9 +384,11 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
/* add mandatory parts first */
ok &= item->file.SetTlv(data, tlvsize, &offset);
ok &= setRawUInt32(data, tlvsize, &offset, item->flags);
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());ok && it!=item->parent_groups.end();++it) // parent groups
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, *it);
if (offset != tlvsize)
{
ok = false;
@ -427,6 +436,15 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
ok &= item->file.GetTlv(data, rssize, &offset);
ok &= getRawUInt32(data, rssize, &offset, &(item->flags));
while(offset < rssize)
{
std::string tmp ;
if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp))
item->parent_groups.push_back(tmp) ;
else
break ;
}
if (offset != rssize)
{
/* error */

View File

@ -300,6 +300,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file;
uint32_t flags;
std::list<std::string> parent_groups ;
};
/**************************************************************************/

View File

@ -131,9 +131,10 @@ void ShareDialog::addDirectory()
rsFiles->addSharedDirectory(sdi);
break;
}
if (it->shareflags != sdi.shareflags) {
if (it->shareflags != sdi.shareflags || it->parent_groups != sdi.parent_groups) {
/* modifies the flags */
it->shareflags = sdi.shareflags;
it->parent_groups = sdi.parent_groups;
rsFiles->updateShareFlags(*it);
break;
}

View File

@ -133,7 +133,17 @@ void ShareManager::load()
listWidget->setRowHeight(row, 32);
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem(QString(" - "))) ; // no groups!
QString group_string ;
int n=0;
for(std::list<std::string>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n)
{
if(n>0)
group_string += ", " ;
group_string += QString::fromStdString(*it2) ;
}
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem(group_string)) ;
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;

View File

@ -22,7 +22,10 @@ std::list<std::string> GroupSelectionBox::selectedGroups() const
std::list<std::string> out ;
for(QList<QListWidgetItem*>::const_iterator it(selected_items.begin());it!=selected_items.end();++it)
{
out.push_back((*it)->text().toStdString()) ;
std::cerr << "Addign selected item " << out.back() << std::endl;
}
return out ;
}