From fb60a6489b553bb0c221c425b0fe36f676efd178 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 15 Feb 2012 21:13:42 +0200 Subject: [PATCH] Fix potential bug when moving single file torrents to tmp folder (closes #932861) --- src/qtlibtorrent/qtorrenthandle.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index ef739af1e..a31897cb3 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -670,7 +670,9 @@ void QTorrentHandle::prioritize_files(const vector &files) const { bool was_seed = is_seed(); vector progress; file_progress(progress); + qDebug() << Q_FUNC_INFO << "Changing files priorities..."; torrent_handle::prioritize_files(files); + qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder..."; for(uint i=0; i &files) const { } } // Move wanted files back to their original folder + qDebug() << Q_FUNC_INFO << "Moving wanted files back from .unwanted folder"; if(files[i] > 0) { - QString old_path = filepath_at(i); - QString old_name = filename_at(i); - QDir parent_path(misc::branchPath(old_path)); - if(parent_path.dirName() == ".unwanted") { - QDir new_path(misc::branchPath(parent_path.path())); - rename_file(i, new_path.filePath(old_name)); + QString parent_relpath = misc::branchPath(filepath_at(i)); + if(QDir(parent_relpath).dirName() == ".unwanted") { + QString old_name = filename_at(i); + QString new_relpath = misc::branchPath(parent_relpath); + if (new_relpath.isEmpty()) + rename_file(i, old_name); + else + rename_file(i, QDir(new_relpath).filePath(old_name)); // Remove .unwanted directory if empty - new_path.rmdir(".unwanted"); + qDebug() << "Attempting to remove .unwanted folder at " << QDir(save_path() + QDir::separator() + new_relpath).absoluteFilePath(".unwanted"); + QDir(save_path() + QDir::separator() + new_relpath).rmdir(".unwanted"); } } } + if(was_seed && !is_seed()) { + qDebug() << "Torrent is no longer SEEDING"; // Save seed status TorrentPersistentData::saveSeedStatus(*this); // Move to temp folder if necessary @@ -728,6 +736,7 @@ void QTorrentHandle::prioritize_files(const vector &files) const { QString root_folder = TorrentPersistentData::getRootFolder(hash()); if(!root_folder.isEmpty()) tmp_path = QDir(tmp_path).absoluteFilePath(root_folder); + qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << save_path(); move_storage(tmp_path); } }