From a9d4b38bd3465b1f9104942d37f00964c4108d8c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 18 Oct 2010 17:44:37 +0000 Subject: [PATCH] Remove uneeded files on torrent deletion Fix encoding error in file renaming --- src/qtlibtorrent/qbtsession.cpp | 6 ++++++ src/qtlibtorrent/qtorrenthandle.cpp | 18 +++++++++++++++++- src/qtlibtorrent/qtorrenthandle.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 50ae8f337..61f3b6c17 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -774,7 +774,13 @@ void QBtSession::deleteTorrent(QString hash, bool delete_local_files) { savePathsToRemove[hash] = save_dir.absolutePath(); s->remove_torrent(h.get_torrent_handle(), session::delete_files); } else { + QStringList uneeded_files = h.uneeded_files_path(); s->remove_torrent(h.get_torrent_handle()); + // Remove unneeded files + foreach(const QString &uneeded_file, uneeded_files) { + qDebug("Removing uneeded file: %s", qPrintable(uneeded_file)); + misc::safeRemove(uneeded_file); + } } // Remove it from torrent backup directory QDir torrentBackup(misc::BTBackupLocation()); diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index 5934a96ad..4fe18460f 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -379,7 +379,7 @@ size_type QTorrentHandle::total_payload_upload() const { // to all files in a torrent QStringList QTorrentHandle::files_path() const { Q_ASSERT(h.is_valid()); - QDir saveDir(misc::toQString(h.save_path().string())); + QDir saveDir(save_path()); QStringList res; torrent_info::file_iterator fi = h.get_torrent_info().begin_files(); while(fi != h.get_torrent_info().end_files()) { @@ -389,6 +389,22 @@ QStringList QTorrentHandle::files_path() const { return res; } +QStringList QTorrentHandle::uneeded_files_path() const { + Q_ASSERT(h.is_valid()); + QDir saveDir(save_path()); + QStringList res; + std::vector fp = h.file_priorities(); + torrent_info::file_iterator fi = h.get_torrent_info().begin_files(); + int i = 0; + while(fi != h.get_torrent_info().end_files()) { + if(fp[i] == 0) + res << QDir::cleanPath(saveDir.absoluteFilePath(misc::toQStringU(fi->path.string()))); + fi++; + ++i; + } + return res; +} + bool QTorrentHandle::has_missing_files() const { const QStringList paths = files_path(); foreach(const QString &path, paths) { diff --git a/src/qtlibtorrent/qtorrenthandle.h b/src/qtlibtorrent/qtorrenthandle.h index ed640a6ea..1001b5b5f 100644 --- a/src/qtlibtorrent/qtorrenthandle.h +++ b/src/qtlibtorrent/qtorrenthandle.h @@ -110,6 +110,7 @@ class QTorrentHandle { size_type all_time_download() const; size_type total_done() const; QStringList files_path() const; + QStringList uneeded_files_path() const; bool has_missing_files() const; int num_uploads() const; bool is_seed() const;