From fd8157f6ba68c2234e24858f0cb5aa0a9a05321d Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 10 Apr 2011 15:00:27 +0000 Subject: [PATCH] Do not delete unwanted files that were already present when adding the torrent --- src/qtlibtorrent/qtorrenthandle.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index 44b00ec2f..775a893ad 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -328,8 +328,11 @@ QStringList QTorrentHandle::uneeded_files_path() const { torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); int i = 0; while(fi != torrent_handle::get_torrent_info().end_files()) { - if(fp[i] == 0) - res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi))); + if(fp[i] == 0) { + const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi))); + if(file_path.contains(".unwanted")) + res << file_path; + } fi++; ++i; } @@ -511,6 +514,12 @@ void QTorrentHandle::prioritize_files(const vector &files) const { // Move unwanted files to a .unwanted subfolder if(files[i] == 0 && progress[i] < filesize_at(i)) { QString old_path = filepath_at(i); + // Make sure the file does not already exists + if(QFile::exists(QDir(save_path()).absoluteFilePath(old_path))) { + qWarning() << "File" << old_path << "already exists at destination."; + qWarning() << "We do not move it to .unwanted folder"; + continue; + } QString old_name = filename_at(i); QString parent_path = misc::branchPath(old_path); if(parent_path.isEmpty() || QDir(parent_path).dirName() != ".unwanted") {