mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-30 07:55:56 +03:00
Merge pull request #7176 from glassez/temp-folder
Don't create subfolder inside temp folder. Closes #5503
This commit is contained in:
commit
6043584305
5 changed files with 37 additions and 14 deletions
|
@ -613,11 +613,14 @@ QString Session::tempPath() const
|
|||
return Utils::Fs::fromNativePath(m_tempPath);
|
||||
}
|
||||
|
||||
QString Session::torrentTempPath(const InfoHash &hash) const
|
||||
QString Session::torrentTempPath(const TorrentInfo &torrentInfo) const
|
||||
{
|
||||
return tempPath()
|
||||
+ static_cast<QString>(hash).left(7)
|
||||
if ((torrentInfo.filesCount() > 1) && !torrentInfo.hasRootFolder())
|
||||
return tempPath()
|
||||
+ QString::fromStdString(torrentInfo.nativeInfo()->orig_files().name())
|
||||
+ "/";
|
||||
|
||||
return tempPath();
|
||||
}
|
||||
|
||||
bool Session::isValidCategoryName(const QString &name)
|
||||
|
@ -1648,7 +1651,7 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
|||
|
||||
// Remove it from session
|
||||
if (deleteLocalFiles) {
|
||||
if (torrent->savePath(true) == torrentTempPath(torrent->hash())) {
|
||||
if (torrent->savePath(true) == torrentTempPath(torrent->info())) {
|
||||
m_savePathsToRemove[torrent->hash()] = torrent->savePath(true);
|
||||
}
|
||||
else {
|
||||
|
@ -1996,7 +1999,7 @@ bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) c
|
|||
|
||||
bool found = findInDir(savePath, torrentInfo);
|
||||
if (!found && isTempPathEnabled()) {
|
||||
savePath = torrentTempPath(torrentInfo.hash());
|
||||
savePath = torrentTempPath(torrentInfo);
|
||||
found = findInDir(savePath, torrentInfo);
|
||||
}
|
||||
|
||||
|
@ -3698,9 +3701,7 @@ void Session::handleTorrentRemovedAlert(libt::torrent_removed_alert *p)
|
|||
|
||||
void Session::handleTorrentDeletedAlert(libt::torrent_deleted_alert *p)
|
||||
{
|
||||
const QString path = m_savePathsToRemove.take(p->info_hash);
|
||||
if (path == torrentTempPath(p->info_hash))
|
||||
Utils::Fs::smartRemoveEmptyFolderTree(path);
|
||||
Utils::Fs::smartRemoveEmptyFolderTree(m_savePathsToRemove.take(p->info_hash));
|
||||
}
|
||||
|
||||
void Session::handleTorrentDeleteFailedAlert(libt::torrent_delete_failed_alert *p)
|
||||
|
|
|
@ -210,7 +210,7 @@ namespace BitTorrent
|
|||
void setTempPath(QString path);
|
||||
bool isTempPathEnabled() const;
|
||||
void setTempPathEnabled(bool enabled);
|
||||
QString torrentTempPath(const InfoHash &hash) const;
|
||||
QString torrentTempPath(const TorrentInfo &torrentInfo) const;
|
||||
|
||||
static bool isValidCategoryName(const QString &name);
|
||||
// returns category itself and all top level categories
|
||||
|
|
|
@ -1498,7 +1498,7 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p)
|
|||
}
|
||||
|
||||
qDebug("Torrent is successfully moved from %s to %s", qPrintable(m_oldPath), qPrintable(m_newPath));
|
||||
if (QDir(m_oldPath) == QDir(m_session->torrentTempPath(hash()))) {
|
||||
if (QDir(m_oldPath) == QDir(m_session->torrentTempPath(info()))) {
|
||||
qDebug() << "Removing torrent temp folder:" << m_oldPath;
|
||||
Utils::Fs::smartRemoveEmptyFolderTree(m_oldPath);
|
||||
}
|
||||
|
@ -1926,9 +1926,9 @@ void TorrentHandle::adjustActualSavePath_impl()
|
|||
path = savePath();
|
||||
}
|
||||
else {
|
||||
// Moving all downloading torrents to temporary save path
|
||||
path = m_session->torrentTempPath(hash());
|
||||
qDebug() << "Moving torrent to its temp save path:" << path;
|
||||
// Moving all downloading torrents to temporary folder
|
||||
path = m_session->torrentTempPath(info());
|
||||
qDebug() << "Moving torrent to its temporary folder:" << path;
|
||||
}
|
||||
|
||||
moveStorage(Utils::Fs::toNativePath(path));
|
||||
|
|
|
@ -308,9 +308,29 @@ int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool TorrentInfo::hasRootFolder() const
|
||||
{
|
||||
QString testRootFolder;
|
||||
for (int i = 0; i < filesCount(); ++i) {
|
||||
const QString filePath = this->filePath(i);
|
||||
if (QDir::isAbsolutePath(filePath)) continue;
|
||||
|
||||
const auto filePathElements = filePath.splitRef('/');
|
||||
// if at least one file has no root folder, no common root folder exists
|
||||
if (filePathElements.count() <= 1) return false;
|
||||
|
||||
if (testRootFolder.isEmpty())
|
||||
testRootFolder = filePathElements.at(0).toString();
|
||||
else if (testRootFolder != filePathElements.at(0))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TorrentInfo::stripRootFolder()
|
||||
{
|
||||
if (filesCount() <= 1) return;
|
||||
if (!hasRootFolder()) return;
|
||||
|
||||
libtorrent::file_storage files = m_nativeInfo->files();
|
||||
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace BitTorrent
|
|||
PieceRange filePieces(int fileIndex) const;
|
||||
|
||||
void renameFile(uint index, const QString &newPath);
|
||||
|
||||
bool hasRootFolder() const;
|
||||
void stripRootFolder();
|
||||
|
||||
NativePtr nativeInfo() const;
|
||||
|
|
Loading…
Reference in a new issue