From 4784114281940c707b7d88463a1fe190a17a7aea Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 29 May 2011 20:59:45 +0900 Subject: [PATCH] Don't save removed download in --save-session text file. Now stat column of removed downloads in Download Results is 'RM' instead of INPR. --- src/RequestGroup.cc | 7 ++++--- src/RequestGroupMan.cc | 20 +++++++++++++++++--- src/RequestGroupMan.h | 3 +++ src/RpcMethodImpl.cc | 2 +- src/SessionSerializer.cc | 3 ++- src/error_code.h | 3 ++- test/RequestGroupTest.cc | 7 ++++++- test/SessionSerializerTest.cc | 28 ++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 10 deletions(-) diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 4d798164..6d2150af 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -197,9 +197,10 @@ error_code::Value RequestGroup::downloadResult() const if(downloadFinished() && !downloadContext_->isChecksumVerificationNeeded()) return error_code::FINISHED; else { - if(lastErrorCode_ == error_code::UNDEFINED) { - if(haltReason_ == RequestGroup::USER_REQUEST || - haltReason_ == RequestGroup::SHUTDOWN_SIGNAL) { + if(haltReason_ == RequestGroup::USER_REQUEST) { + return error_code::REMOVED; + } else if(lastErrorCode_ == error_code::UNDEFINED) { + if(haltReason_ == RequestGroup::SHUTDOWN_SIGNAL) { return error_code::IN_PROGRESS; } else { return error_code::UNKNOWN_ERROR; diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 4cc61c0d..fbb4bad4 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -270,6 +270,7 @@ void executeStopHook !option->blank(PREF_ON_DOWNLOAD_COMPLETE)) { util::executeHookByOptName(group, option, PREF_ON_DOWNLOAD_COMPLETE); } else if(result != error_code::IN_PROGRESS && + result != error_code::REMOVED && !option->blank(PREF_ON_DOWNLOAD_ERROR)) { util::executeHookByOptName(group, option, PREF_ON_DOWNLOAD_ERROR); } else if(!option->blank(PREF_ON_DOWNLOAD_STOP)) { @@ -571,6 +572,7 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const size_t finished = 0; size_t error = removedErrorResult_; size_t inprogress = 0; + size_t removed = 0; error_code::Value lastError = removedLastErrorResult_; for(std::deque >::const_iterator itr = downloadResults_.begin(), eoi = downloadResults_.end(); @@ -580,12 +582,17 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const } if((*itr)->result == error_code::FINISHED) { ++finished; + } else if((*itr)->result == error_code::IN_PROGRESS) { + ++inprogress; + } else if((*itr)->result == error_code::REMOVED) { + ++removed; } else { ++error; lastError = (*itr)->result; } } - return DownloadStat(finished, error, inprogress, reservedGroups_.size(), + return DownloadStat(finished, error, inprogress, removed, + reservedGroups_.size(), lastError); } @@ -594,6 +601,7 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const static const std::string MARK_OK("OK"); static const std::string MARK_ERR("ERR"); static const std::string MARK_INPR("INPR"); + static const std::string MARK_RM("RM"); // Download Results: // idx|stat|path/length @@ -611,7 +619,7 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const int ok = 0; int err = 0; int inpr = 0; - + int rm = 0; for(std::deque >::const_iterator itr = downloadResults_.begin(), eoi = downloadResults_.end(); itr != eoi; ++itr) { @@ -625,13 +633,16 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const } else if((*itr)->result == error_code::IN_PROGRESS) { status = MARK_INPR; ++inpr; + } else if((*itr)->result == error_code::REMOVED) { + status = MARK_RM; + ++rm; } else { status = MARK_ERR; ++err; } o << formatDownloadResult(status, *itr) << "\n"; } - if(ok > 0 || err > 0 || inpr > 0) { + if(ok > 0 || err > 0 || inpr > 0 || rm > 0) { o << "\n" << _("Status Legend:") << "\n"; @@ -644,6 +655,9 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const if(inpr > 0) { o << "(INPR):download in-progress."; } + if(rm > 0) { + o << "(RM):download removed."; + } o << "\n"; } } diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h index 296252c1..f4107d74 100644 --- a/src/RequestGroupMan.h +++ b/src/RequestGroupMan.h @@ -171,18 +171,21 @@ public: size_t completed_; size_t error_; size_t inProgress_; + size_t removed_; size_t waiting_; error_code::Value lastErrorResult_; public: DownloadStat(size_t completed, size_t error, size_t inProgress, + size_t removed, size_t waiting, error_code::Value lastErrorResult = error_code::FINISHED): completed_(completed), error_(error), inProgress_(inProgress), + removed_(removed), waiting_(waiting), lastErrorResult_(lastErrorResult) {} diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 4af1028a..a554be2b 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -800,7 +800,7 @@ void gatherStoppedDownload entryDict->put(KEY_ERROR_CODE, util::itos(static_cast(ds->result))); } if(requested_key(keys, KEY_STATUS)) { - if(ds->result == error_code::IN_PROGRESS) { + if(ds->result == error_code::REMOVED) { entryDict->put(KEY_STATUS, VLB_REMOVED); } else if(ds->result == error_code::FINISHED) { entryDict->put(KEY_STATUS, VLB_COMPLETE); diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index 886f610d..4c5acc3c 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -171,7 +171,8 @@ void SessionSerializer::save(std::ostream& out) const rgman_->getDownloadResults(); for(std::deque >::const_iterator itr = results.begin(), eoi = results.end(); itr != eoi; ++itr) { - if((*itr)->result == error_code::FINISHED) { + if((*itr)->result == error_code::FINISHED || + (*itr)->result == error_code::REMOVED) { continue; } else if((*itr)->result == error_code::IN_PROGRESS) { if(saveInProgress_) { diff --git a/src/error_code.h b/src/error_code.h index a721a3cc..34da3615 100644 --- a/src/error_code.h +++ b/src/error_code.h @@ -73,7 +73,8 @@ enum Value { MAGNET_PARSE_ERROR = 27, OPTION_ERROR = 28, HTTP_SERVICE_UNAVAILABLE = 29, - JSON_PARSE_ERROR = 30 + JSON_PARSE_ERROR = 30, + REMOVED = 31 }; } // namespace error_code diff --git a/test/RequestGroupTest.cc b/test/RequestGroupTest.cc index 2e169f64..fc60a33a 100644 --- a/test/RequestGroupTest.cc +++ b/test/RequestGroupTest.cc @@ -67,9 +67,14 @@ void RequestGroupTest::testCreateDownloadResult() CPPUNIT_ASSERT_EQUAL(error_code::UNKNOWN_ERROR, result->result); // if haltReason is set to RequestGroup::USER_REQUEST, download - // result becomes IN_PROGRESS + // result will become REMOVED. group.setHaltRequested(true, RequestGroup::USER_REQUEST); result = group.createDownloadResult(); + CPPUNIT_ASSERT_EQUAL(error_code::REMOVED, result->result); + // if haltReason is set to RequestGroup::SHUTDOWN_SIGNAL, download + // result will become IN_PROGRESS. + group.setHaltRequested(true, RequestGroup::SHUTDOWN_SIGNAL); + result = group.createDownloadResult(); CPPUNIT_ASSERT_EQUAL(error_code::IN_PROGRESS, result->result); } { diff --git a/test/SessionSerializerTest.cc b/test/SessionSerializerTest.cc index 874988af..9cd7d4d5 100644 --- a/test/SessionSerializerTest.cc +++ b/test/SessionSerializerTest.cc @@ -11,6 +11,7 @@ #include "prefs.h" #include "Option.h" #include "a2functional.h" +#include "FileEntry.h" namespace aria2 { @@ -26,6 +27,25 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION(SessionSerializerTest); +namespace { +SharedHandle createDownloadResult +(error_code::Value result, const std::string& uri) +{ + std::vector uris; + uris.push_back(uri); + SharedHandle entry(new FileEntry("/tmp/path", 1, 0, uris)); + std::vector > entries; + entries.push_back(entry); + SharedHandle dr(new DownloadResult()); + dr->fileEntries = entries; + dr->result = result; + dr->belongsTo = 0; + dr->inMemoryDownload = false; + dr->option = SharedHandle