From 6f31a13f22079030aa3cd8cc57fc1e2f5193386c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 7 Dec 2024 20:43:16 +0800 Subject: [PATCH] Don't follow symlink when creating torrents on Windows Now on Windows, it won't follow/include .lnk files when creating torrents. Note that libtorrent will throw errors if we force adding .lnk files. Non-Windows OS will still follow symlinks. Closes #13286. PR #21944. --- src/base/bittorrent/torrentcreator.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentcreator.cpp b/src/base/bittorrent/torrentcreator.cpp index 3cd26ba7c03..727e9a9dc38 100644 --- a/src/base/bittorrent/torrentcreator.cpp +++ b/src/base/bittorrent/torrentcreator.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -123,7 +124,14 @@ void TorrentCreator::run() // need to sort the file names by natural sort order QStringList dirs = {m_params.sourcePath.data()}; - QDirIterator dirIter {m_params.sourcePath.data(), (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories}; +#ifdef Q_OS_WIN + // libtorrent couldn't handle .lnk files on Windows + // Also, Windows users do not expect torrent creator to traverse into .lnk files so skip over them + const QDir::Filters dirFilters {QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks}; +#else + const QDir::Filters dirFilters {QDir::AllDirs | QDir::NoDotAndDotDot}; +#endif + QDirIterator dirIter {m_params.sourcePath.data(), dirFilters, QDirIterator::Subdirectories}; while (dirIter.hasNext()) { const QString filePath = dirIter.next(); @@ -138,7 +146,12 @@ void TorrentCreator::run() { QStringList tmpNames; // natural sort files within each dir - QDirIterator fileIter {dir, QDir::Files}; +#ifdef Q_OS_WIN + const QDir::Filters fileFilters {QDir::Files | QDir::NoSymLinks}; +#else + const QDir::Filters fileFilters {QDir::Files}; +#endif + QDirIterator fileIter {dir, fileFilters}; while (fileIter.hasNext()) { const QFileInfo fileInfo = fileIter.nextFileInfo();