mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-28 16:27:01 -05:00
added proper filtering of slash and backshash from directory and file names in RsCollection to avoid files that can be redirected to wrong locations
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5977 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
8078ad3aab
commit
bf3194f035
@ -52,6 +52,7 @@ RsCollectionDialog::RsCollectionDialog(const QString& CollectionFileName,const s
|
|||||||
|
|
||||||
uint64_t total_size ;
|
uint64_t total_size ;
|
||||||
uint32_t total_files ;
|
uint32_t total_files ;
|
||||||
|
bool wrong_chars = false ;
|
||||||
|
|
||||||
for(uint32_t i=0;i<size;++i)
|
for(uint32_t i=0;i<size;++i)
|
||||||
{
|
{
|
||||||
@ -66,6 +67,12 @@ RsCollectionDialog::RsCollectionDialog(const QString& CollectionFileName,const s
|
|||||||
item->setText(1, misc::friendlyUnit(dlinfo.size));
|
item->setText(1, misc::friendlyUnit(dlinfo.size));
|
||||||
item->setText(2, dlinfo.hash);
|
item->setText(2, dlinfo.hash);
|
||||||
|
|
||||||
|
if(dlinfo.filename_has_wrong_characters)
|
||||||
|
{
|
||||||
|
wrong_chars = true ;
|
||||||
|
item->setTextColor(0,QColor(255,80,120)) ;
|
||||||
|
}
|
||||||
|
|
||||||
_fileEntriesTW->addTopLevelItem(item);
|
_fileEntriesTW->addTopLevelItem(item);
|
||||||
|
|
||||||
total_size += dlinfo.size ;
|
total_size += dlinfo.size ;
|
||||||
@ -88,6 +95,9 @@ RsCollectionDialog::RsCollectionDialog(const QString& CollectionFileName,const s
|
|||||||
connect(_download_PB,SIGNAL(clicked()),this,SLOT(download())) ;
|
connect(_download_PB,SIGNAL(clicked()),this,SLOT(download())) ;
|
||||||
|
|
||||||
_fileEntriesTW->installEventFilter(this);
|
_fileEntriesTW->installEventFilter(this);
|
||||||
|
|
||||||
|
if(wrong_chars)
|
||||||
|
QMessageBox::warning(NULL,tr("Bad filenames have been cleaned"),tr("Some filenames or directory names in this collection file\ncontained '/' or '\\' characters. They have been substitued to '_',\nand are listed in red.")) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event)
|
bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
@ -51,12 +51,28 @@ void RsCollectionFile::downloadFiles() const
|
|||||||
QDomElement docElem = _xml_doc.documentElement();
|
QDomElement docElem = _xml_doc.documentElement();
|
||||||
|
|
||||||
std::vector<DLinfo> dlinfos ;
|
std::vector<DLinfo> dlinfos ;
|
||||||
recursCollectDLinfos(docElem,dlinfos,QString()) ;
|
|
||||||
|
recursCollectDLinfos(docElem,dlinfos,QString(),false) ;
|
||||||
|
|
||||||
RsCollectionDialog(_filename, dlinfos).exec() ;
|
RsCollectionDialog(_filename, dlinfos).exec() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLinfo>& dlinfos,const QString& current_path) const
|
static QString purifyFileName(const QString& input,bool& bad)
|
||||||
|
{
|
||||||
|
bad = false ;
|
||||||
|
QString output = input ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<output.length();++i)
|
||||||
|
if(output[i] == '/' || output[i] == '\\')
|
||||||
|
{
|
||||||
|
output[i] = '_' ;
|
||||||
|
bad = true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLinfo>& dlinfos,const QString& current_path, bool bad_chars_in_parent) const
|
||||||
{
|
{
|
||||||
QDomNode n = e.firstChild() ;
|
QDomNode n = e.firstChild() ;
|
||||||
|
|
||||||
@ -72,14 +88,21 @@ void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLi
|
|||||||
{
|
{
|
||||||
DLinfo i ;
|
DLinfo i ;
|
||||||
i.hash = ee.attribute(QString("sha1")) ;
|
i.hash = ee.attribute(QString("sha1")) ;
|
||||||
i.name = ee.attribute(QString("name")) ;
|
bool bad_chars_detected = false ;
|
||||||
|
i.name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected) ;
|
||||||
|
i.filename_has_wrong_characters = bad_chars_detected || bad_chars_in_parent ;
|
||||||
i.size = ee.attribute(QString("size")).toULongLong() ;
|
i.size = ee.attribute(QString("size")).toULongLong() ;
|
||||||
i.path = current_path ;
|
i.path = current_path ;
|
||||||
|
|
||||||
dlinfos.push_back(i) ;
|
dlinfos.push_back(i) ;
|
||||||
}
|
}
|
||||||
else if(ee.tagName() == QString("Directory"))
|
else if(ee.tagName() == QString("Directory"))
|
||||||
recursCollectDLinfos(ee,dlinfos,current_path + "/" + ee.attribute(QString("name"))) ;
|
{
|
||||||
|
bool bad_chars_detected = false ;
|
||||||
|
QString cleanDirName = purifyFileName(ee.attribute(QString("name")),bad_chars_detected) ;
|
||||||
|
|
||||||
|
recursCollectDLinfos(ee,dlinfos,current_path + "/" + cleanDirName, bad_chars_in_parent || bad_chars_detected) ;
|
||||||
|
}
|
||||||
|
|
||||||
n = n.nextSibling() ;
|
n = n.nextSibling() ;
|
||||||
}
|
}
|
||||||
@ -216,7 +239,7 @@ qulonglong RsCollectionFile::size()
|
|||||||
QDomElement docElem = _xml_doc.documentElement();
|
QDomElement docElem = _xml_doc.documentElement();
|
||||||
|
|
||||||
std::vector<DLinfo> dlinfos;
|
std::vector<DLinfo> dlinfos;
|
||||||
recursCollectDLinfos(docElem, dlinfos, QString());
|
recursCollectDLinfos(docElem, dlinfos, QString(),false);
|
||||||
|
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
|
|
||||||
|
@ -68,10 +68,11 @@ class RsCollectionFile
|
|||||||
qulonglong size ;
|
qulonglong size ;
|
||||||
QString path ;
|
QString path ;
|
||||||
QString hash ;
|
QString hash ;
|
||||||
|
bool filename_has_wrong_characters ;
|
||||||
};
|
};
|
||||||
|
|
||||||
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
|
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
|
||||||
void recursCollectDLinfos(const QDomElement&,std::vector<DLinfo>& dlinfos,const QString& current_dir) const ;
|
void recursCollectDLinfos(const QDomElement&,std::vector<DLinfo>& dlinfos,const QString& current_dir,bool bad_chars_in_parent) const ;
|
||||||
|
|
||||||
QDomDocument _xml_doc ;
|
QDomDocument _xml_doc ;
|
||||||
QString _filename ;
|
QString _filename ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user