From 4b77bb57add14e12de3a63149e69b789749282c2 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 23 Jul 2010 17:15:47 +0000 Subject: [PATCH] Fix crash on torrent completion --- src/bittorrent.cpp | 22 +++++++++++----------- src/qtorrenthandle.cpp | 12 ++++++------ src/qtorrenthandle.h | 12 ++++++------ src/src.pro | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 93ab12155..4ea86a25f 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1999,22 +1999,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(appendqBExtension) appendqBextensionToTorrent(h, false); #endif - // Move to download directory if necessary - if(!defaultTempPath.isEmpty()) { - // Check if directory is different - const QDir current_dir(h.save_path()); - const QDir save_dir(getSavePath(hash)); - if(current_dir != save_dir) { - h.move_storage(save_dir.path()); - } - } const bool was_already_seeded = TorrentPersistentData::isSeed(hash); if(!was_already_seeded) { h.save_resume_data(); qDebug("Checking if the torrent contains torrent files to download"); // Check if there are torrent files inside - torrent_info::file_iterator it; - for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { + for(torrent_info::file_iterator it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { + qDebug("File path: %s", it->path.string().c_str()); const QString torrent_relpath = misc::toQStringU(it->path.string()).replace("\\", "/"); if(torrent_relpath.endsWith(".torrent", Qt::CaseInsensitive)) { qDebug("Found possible recursive torrent download."); @@ -2034,6 +2025,15 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } } } + // Move to download directory if necessary + if(!defaultTempPath.isEmpty()) { + // Check if directory is different + const QDir current_dir(h.save_path()); + const QDir save_dir(getSavePath(hash)); + if(current_dir != save_dir) { + h.move_storage(save_dir.absolutePath()); + } + } // Recheck if the user asked to if(Preferences::recheckTorrentsOnCompletion() && !was_already_seeded) { // Remember finished state diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 3c9f6bab4..6bfcf6b8b 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -50,12 +50,12 @@ QTorrentHandle::QTorrentHandle(torrent_handle h): h(h) {} // Getters // -torrent_handle QTorrentHandle::get_torrent_handle() const { +const torrent_handle& QTorrentHandle::get_torrent_handle() const { Q_ASSERT(h.is_valid()); return h; } -torrent_info QTorrentHandle::get_torrent_info() const { +const torrent_info& QTorrentHandle::get_torrent_info() const { Q_ASSERT(h.is_valid()); return h.get_torrent_info(); } @@ -302,7 +302,7 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const { return h.get_torrent_info().file_at(index).size; } -std::vector QTorrentHandle::trackers() const { +const std::vector& QTorrentHandle::trackers() const { Q_ASSERT(h.is_valid()); return h.trackers(); } @@ -531,7 +531,7 @@ void QTorrentHandle::set_max_connections(int val) { h.set_max_connections(val); } -void QTorrentHandle::prioritize_files(std::vector v) { +void QTorrentHandle::prioritize_files(const std::vector &v) { // Does not do anything for seeding torrents Q_ASSERT(h.is_valid()); if(v.size() != (unsigned int)h.get_torrent_info().num_files()) @@ -546,7 +546,7 @@ void QTorrentHandle::set_ratio(float ratio) const { h.set_ratio(ratio); } -void QTorrentHandle::replace_trackers(std::vector const& v) const { +void QTorrentHandle::replace_trackers(const std::vector & v) const { Q_ASSERT(h.is_valid()); h.replace_trackers(v); } @@ -653,7 +653,7 @@ void QTorrentHandle::set_peer_download_limit(libtorrent::asio::ip::tcp::endpoint h.set_peer_download_limit(ip, limit); } -void QTorrentHandle::add_tracker(announce_entry const& url) { +void QTorrentHandle::add_tracker(const announce_entry& url) { Q_ASSERT(h.is_valid()); #if LIBTORRENT_VERSION_MINOR > 14 h.add_tracker(url); diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index e6c084232..46ff6b567 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -60,8 +60,8 @@ class QTorrentHandle { // Getters // - torrent_handle get_torrent_handle() const; - torrent_info get_torrent_info() const; + const torrent_handle& get_torrent_handle() const; + const torrent_info& get_torrent_info() const; QString hash() const; QString name() const; float progress() const; @@ -97,7 +97,7 @@ class QTorrentHandle { bool is_queued() const; QString file_at(unsigned int index) const; size_type filesize_at(unsigned int index) const; - std::vector trackers() const; + const std::vector& trackers() const; torrent_status::state_t state() const; QString creator() const; QString comment() const; @@ -148,10 +148,10 @@ class QTorrentHandle { void add_url_seed(QString seed); void set_max_uploads(int val); void set_max_connections(int val); - void prioritize_files(std::vector v); + void prioritize_files(const std::vector &v); void file_priority(int index, int priority) const; void set_ratio(float ratio) const; - void replace_trackers(std::vector const&) const; + void replace_trackers(const std::vector& trackers) const; void force_reannounce(); void set_sequential_download(bool); void set_tracker_login(QString username, QString password); @@ -170,7 +170,7 @@ class QTorrentHandle { void connect_peer(libtorrent::asio::ip::tcp::endpoint const& adr, int source = 0) const; void set_peer_upload_limit(libtorrent::asio::ip::tcp::endpoint ip, int limit) const; void set_peer_download_limit(libtorrent::asio::ip::tcp::endpoint ip, int limit) const; - void add_tracker(announce_entry const& url); + void add_tracker(const announce_entry& url); void prioritize_first_last_piece(bool b); void rename_file(int index, QString name); bool save_torrent_file(QString path); diff --git a/src/src.pro b/src/src.pro index e3626225b..c4510a4ab 100644 --- a/src/src.pro +++ b/src/src.pro @@ -12,9 +12,9 @@ CONFIG += qt \ # Update this VERSION for each release os2 { - DEFINES += VERSION=\'\"v2.3.0rc8\"\' + DEFINES += VERSION=\'\"v2.3.0rc9\"\' } else { - DEFINES += VERSION=\\\"v2.3.0rc8\\\" + DEFINES += VERSION=\\\"v2.3.0rc9\\\" } DEFINES += VERSION_MAJOR=2 DEFINES += VERSION_MINOR=3