Browse Source

Merge pull request #6699 from fbriere/issue/6265-top-dirname-while-adding

Use actual top-level dirname to look for incomplete files in new torrent
adaptive-webui-19844
Vladimir Golovnev 8 years ago committed by GitHub
parent
commit
f3658daf72
  1. 43
      src/base/bittorrent/session.cpp

43
src/base/bittorrent/session.cpp

@ -33,7 +33,6 @@ @@ -33,7 +33,6 @@
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QHostAddress>
#include <QNetworkAddressEntry>
#include <QNetworkInterface>
@ -156,16 +155,6 @@ namespace @@ -156,16 +155,6 @@ namespace
return expanded;
}
QStringList findAllFiles(const QString &dirPath)
{
QStringList files;
QDirIterator it(dirPath, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
files << it.next();
return files;
}
template <typename T>
struct LowerLimited
{
@ -1731,35 +1720,19 @@ bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) c @@ -1731,35 +1720,19 @@ bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) c
{
auto findInDir = [](const QString &dirPath, TorrentInfo &torrentInfo) -> bool
{
const QDir dir(dirPath);
bool found = false;
if (torrentInfo.filesCount() == 1) {
const QString filePath = dirPath + torrentInfo.filePath(0);
if (QFile(filePath).exists()) {
for (int i = 0; i < torrentInfo.filesCount(); ++i) {
const QString filePath = torrentInfo.filePath(i);
if (dir.exists(filePath)) {
found = true;
}
else if (QFile(filePath + QB_EXT).exists()) {
else if (dir.exists(filePath + QB_EXT)) {
found = true;
torrentInfo.renameFile(0, torrentInfo.filePath(0) + QB_EXT);
}
}
else {
QSet<QString> allFiles;
int dirPathSize = dirPath.size();
foreach (const QString &file, findAllFiles(dirPath + torrentInfo.name()))
allFiles << file.mid(dirPathSize);
for (int i = 0; i < torrentInfo.filesCount(); ++i) {
QString filePath = torrentInfo.filePath(i);
if (allFiles.contains(filePath)) {
found = true;
}
else {
filePath += QB_EXT;
if (allFiles.contains(filePath)) {
found = true;
torrentInfo.renameFile(i, filePath);
}
}
torrentInfo.renameFile(i, filePath + QB_EXT);
}
if ((i % 100) == 0)
qApp->processEvents();
}
return found;

Loading…
Cancel
Save