Safe filepath processing at new torrent content selection
Review Request #130052 - Created March 27, 2017 and submitted
Today I've tried to create a torrent file with current KT build that contains a directory. And got something like this.
The name of torrent is empty and the root subfolder is empty too. I have debugged this and found out that
nameargument that passed to libktorrent's
TorrentCreator()is empty. This is due to lack of filename check on KTorrent side.
KUrlRequesteris currently not working as expected on my machine, perhaps this is because i'm selecting directories by browsing inside them and pressing Open button while nothing else is selected, but my
KUrlRequester m_urlalways returns path to directory with trailing slash. Like
/tmp/1/. In this case
QUrl::fileName()returns empty string. And surprisingly there is no any validation of this value. Also user can just type in path to directory with trailing slash.
Thus I suggest more accurate name processing by replacing
QString name = url.fileName();
withQString name = url.toLocalFile(); name = QFileInfo(name).isDir() ? QDir(name).dirName() : url.fileName();
it'll return proper name for any local filepath except someone select root folder itself - in this case name will be empty.
This is for when you create a torrent?
but url.toLocalFile() needs to be a file, no?
I mean how does
work if it's a dir? It creates a torrent of the dir?