Browse Source

Use "old file path" provided by libtorrent

Until libtorrent provided an "old_name" field in `file_renamed_alert` we relied
on a workaround with storing old file names to remove empty leftover folders.
PR #15356.
adaptive-webui-19844
Vladimir Golovnev 3 years ago committed by GitHub
parent
commit
b823d74ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/base/bittorrent/torrentimpl.cpp
  2. 6
      src/base/bittorrent/torrentimpl.h

11
src/base/bittorrent/torrentimpl.cpp

@ -1628,8 +1628,10 @@ void TorrentImpl::moveStorage(const QString &newPath, const MoveStorageMode mode @@ -1628,8 +1628,10 @@ void TorrentImpl::moveStorage(const QString &newPath, const MoveStorageMode mode
void TorrentImpl::renameFile(const int index, const QString &path)
{
#ifndef QBT_USES_LIBTORRENT2
const QString oldPath = filePath(index);
m_oldPath[lt::file_index_t {index}].push_back(oldPath);
#endif
++m_renameCount;
m_nativeHandle.rename_file(lt::file_index_t {index}, Utils::Fs::toNativePath(path).toStdString());
}
@ -1865,11 +1867,14 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p) @@ -1865,11 +1867,14 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
// Remove empty leftover folders
// For example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
// be removed if they are empty
#ifndef QBT_USES_LIBTORRENT2
const QString oldFilePath = m_oldPath[p->index].takeFirst();
const QString newFilePath = Utils::Fs::toUniformPath(p->new_name());
if (m_oldPath[p->index].isEmpty())
m_oldPath.remove(p->index);
#else
const QString oldFilePath = Utils::Fs::toUniformPath(p->old_name());
#endif
const QString newFilePath = Utils::Fs::toUniformPath(p->new_name());
QList<QStringView> oldPathParts = QStringView(oldFilePath).split('/', Qt::SkipEmptyParts);
oldPathParts.removeLast(); // drop file name part
@ -1909,9 +1914,11 @@ void TorrentImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert @@ -1909,9 +1914,11 @@ void TorrentImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert
.arg(name(), filePath(toLTUnderlyingType(p->index))
, QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING);
#ifndef QBT_USES_LIBTORRENT2
m_oldPath[p->index].removeFirst();
if (m_oldPath[p->index].isEmpty())
m_oldPath.remove(p->index);
#endif
--m_renameCount;
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())

6
src/base/bittorrent/torrentimpl.h

@ -302,9 +302,11 @@ namespace BitTorrent @@ -302,9 +302,11 @@ namespace BitTorrent
MaintenanceJob m_maintenanceJob = MaintenanceJob::None;
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
// we will rely on this workaround to remove empty leftover folders
#ifndef QBT_USES_LIBTORRENT2
// Until libtorrent provided an "old_name" field in `file_renamed_alert`
// we relied on this workaround to remove empty leftover folders
QHash<lt::file_index_t, QVector<QString>> m_oldPath;
#endif
QHash<QString, QMap<lt::tcp::endpoint, int>> m_trackerPeerCounts;
FileErrorInfo m_lastFileError;

Loading…
Cancel
Save