mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-30 20:28:05 -06:00
Merge pull request #3984 from glassez/root_path
Fix TorrentHandle path methods. Closes #3847.
This commit is contained in:
@@ -827,11 +827,7 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
||||
|
||||
// Remove it from session
|
||||
if (deleteLocalFiles) {
|
||||
QString tmp = torrent->filePath(0);
|
||||
tmp.truncate(tmp.indexOf("/")); // get the torrent root directory name
|
||||
if (!tmp.isEmpty())
|
||||
m_savePathsToRemove[torrent->hash()] = torrent->actualSavePath() + tmp;
|
||||
|
||||
m_savePathsToRemove[torrent->hash()] = torrent->rootPath(true);
|
||||
m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_files);
|
||||
}
|
||||
else {
|
||||
@@ -1736,7 +1732,7 @@ void Session::handleTorrentFinished(TorrentHandle *const torrent)
|
||||
const QString torrentRelpath = torrent->filePath(i);
|
||||
if (torrentRelpath.endsWith(".torrent", Qt::CaseInsensitive)) {
|
||||
qDebug("Found possible recursive torrent download.");
|
||||
const QString torrentFullpath = torrent->actualSavePath() + "/" + torrentRelpath;
|
||||
const QString torrentFullpath = torrent->savePath(true) + "/" + torrentRelpath;
|
||||
qDebug("Full subtorrent path is %s", qPrintable(torrentFullpath));
|
||||
TorrentInfo torrentInfo = TorrentInfo::loadFromFile(torrentFullpath);
|
||||
if (torrentInfo.isValid()) {
|
||||
|
||||
@@ -294,21 +294,30 @@ QString TorrentHandle::currentTracker() const
|
||||
return Utils::String::fromStdString(m_nativeStatus.current_tracker);
|
||||
}
|
||||
|
||||
QString TorrentHandle::savePath() const
|
||||
QString TorrentHandle::savePath(bool actual) const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(m_savePath);
|
||||
if (actual)
|
||||
return Utils::Fs::fromNativePath(nativeActualSavePath());
|
||||
else
|
||||
return Utils::Fs::fromNativePath(m_savePath);
|
||||
}
|
||||
|
||||
QString TorrentHandle::rootPath() const
|
||||
QString TorrentHandle::rootPath(bool actual) const
|
||||
{
|
||||
if (filesCount() > 1) {
|
||||
QString first_filepath = filePath(0);
|
||||
const int slashIndex = first_filepath.indexOf("/");
|
||||
if (slashIndex >= 0)
|
||||
return QDir(actualSavePath()).absoluteFilePath(first_filepath.left(slashIndex));
|
||||
}
|
||||
QString firstFilePath = filePath(0);
|
||||
const int slashIndex = firstFilePath.indexOf("/");
|
||||
if (slashIndex >= 0)
|
||||
return QDir(savePath(actual)).absoluteFilePath(firstFilePath.left(slashIndex));
|
||||
else
|
||||
return QDir(savePath(actual)).absoluteFilePath(firstFilePath);
|
||||
}
|
||||
|
||||
return actualSavePath();
|
||||
QString TorrentHandle::contentPath(bool actual) const
|
||||
{
|
||||
if (filesCount() == 1)
|
||||
return QDir(savePath(actual)).absoluteFilePath(filePath(0));
|
||||
else
|
||||
return rootPath(actual);
|
||||
}
|
||||
|
||||
QString TorrentHandle::nativeActualSavePath() const
|
||||
@@ -316,11 +325,6 @@ QString TorrentHandle::nativeActualSavePath() const
|
||||
return Utils::String::fromStdString(m_nativeStatus.save_path);
|
||||
}
|
||||
|
||||
QString TorrentHandle::actualSavePath() const
|
||||
{
|
||||
return Utils::Fs::fromNativePath(nativeActualSavePath());
|
||||
}
|
||||
|
||||
QList<TrackerEntry> TorrentHandle::trackers() const
|
||||
{
|
||||
QList<TrackerEntry> entries;
|
||||
@@ -530,7 +534,7 @@ QStringList TorrentHandle::absoluteFilePaths() const
|
||||
{
|
||||
if (!hasMetadata()) return QStringList();
|
||||
|
||||
QDir saveDir(actualSavePath());
|
||||
QDir saveDir(savePath(true));
|
||||
QStringList res;
|
||||
for (int i = 0; i < filesCount(); ++i)
|
||||
res << Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
|
||||
@@ -541,7 +545,7 @@ QStringList TorrentHandle::absoluteFilePathsUnwanted() const
|
||||
{
|
||||
if (!hasMetadata()) return QStringList();
|
||||
|
||||
QDir saveDir(actualSavePath());
|
||||
QDir saveDir(savePath(true));
|
||||
QStringList res;
|
||||
std::vector<int> fp;
|
||||
SAFE_GET(fp, file_priorities);
|
||||
@@ -1486,7 +1490,7 @@ void TorrentHandle::handleFileRenamedAlert(libtorrent::file_renamed_alert *p)
|
||||
QString newPath = newPathParts.join("/");
|
||||
if (!newPathParts.isEmpty() && (oldPath != newPath)) {
|
||||
qDebug("oldPath(%s) != newPath(%s)", qPrintable(oldPath), qPrintable(newPath));
|
||||
oldPath = QString("%1/%2").arg(actualSavePath()).arg(oldPath);
|
||||
oldPath = QString("%1/%2").arg(savePath(true)).arg(oldPath);
|
||||
qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(oldPath));
|
||||
QDir().rmpath(oldPath);
|
||||
}
|
||||
@@ -1781,7 +1785,7 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
|
||||
SAFE_CALL(prioritize_files, priorities.toStdVector());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder and conversely...";
|
||||
QString spath = actualSavePath();
|
||||
QString spath = savePath(true);
|
||||
for (int i = 0; i < priorities.size(); ++i) {
|
||||
QString filepath = filePath(i);
|
||||
// Move unwanted files to a .unwanted subfolder
|
||||
|
||||
@@ -179,9 +179,50 @@ namespace BitTorrent
|
||||
qlonglong pieceLength() const;
|
||||
qlonglong wastedSize() const;
|
||||
QString currentTracker() const;
|
||||
QString actualSavePath() const;
|
||||
QString savePath() const;
|
||||
QString rootPath() const;
|
||||
|
||||
// 1. savePath() - the path where all the files and subfolders of torrent are stored (as always).
|
||||
// 2. rootPath() - absolute path of torrent file tree (save path + first item from 1st torrent file path).
|
||||
// 3. contentPath() - absolute path of torrent content (root path for multifile torrents, absolute file path for singlefile torrents).
|
||||
//
|
||||
// These methods have 'actual' parameter (defaults to false) which allow to get actual or final path variant.
|
||||
//
|
||||
// Examples.
|
||||
// Suppose we have three torrent with following structures and save path `/home/user/torrents`:
|
||||
//
|
||||
// Torrent A (multifile)
|
||||
//
|
||||
// torrentA/
|
||||
// subdir1/
|
||||
// subdir2/
|
||||
// file1
|
||||
// file2
|
||||
// file3
|
||||
// file4
|
||||
//
|
||||
//
|
||||
// Torrent B (singlefile)
|
||||
//
|
||||
// torrentB/
|
||||
// subdir1/
|
||||
// file1
|
||||
//
|
||||
//
|
||||
// Torrent C (singlefile)
|
||||
//
|
||||
// file1
|
||||
//
|
||||
//
|
||||
// Results:
|
||||
// | | rootPath | contentPath |
|
||||
// |---|------------------------------|--------------------------------------------|
|
||||
// | A | /home/user/torrents/torrentA | /home/user/torrents/torrentA |
|
||||
// | B | /home/user/torrents/torrentB | /home/user/torrents/torrentB/subdir1/file1 |
|
||||
// | C | /home/user/torrents/file1 | /home/user/torrents/file1 |
|
||||
|
||||
QString savePath(bool actual = false) const;
|
||||
QString rootPath(bool actual = false) const;
|
||||
QString contentPath(bool actual = false) const;
|
||||
|
||||
int filesCount() const;
|
||||
int piecesCount() const;
|
||||
int piecesHave() const;
|
||||
|
||||
Reference in New Issue
Block a user