diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-03-13 16:11:29 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-03-13 16:11:29 +0900 |
| commit | 4595aa75e17884f36982e9ba2d56c24725d30538 (patch) | |
| tree | f3441af64b0616e4f2d80883de534cebf8612571 | |
| parent | 1a0e5e32f3291e79908edfab584f38cb9bd652c4 (diff) | |
SessionSerializer: Fix bug that pause=true is added to wrong item
This change also defers writing metadata download to the location
where first its follower download is written.
| -rw-r--r-- | src/SessionSerializer.cc | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index 38a89ce4..7688cd26 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -189,10 +189,11 @@ bool writeUri(IOFile& fp, InputIterator first, InputIterator last, namespace { bool writeDownloadResult(IOFile& fp, std::set<a2_gid_t>& metainfoCache, - const std::shared_ptr<DownloadResult>& dr) + const std::shared_ptr<DownloadResult>& dr, + bool pauseRequested) { const std::shared_ptr<MetadataInfo>& mi = dr->metadataInfo; - if (dr->belongsTo != 0 || (mi && mi->dataOnly())) { + if (dr->belongsTo != 0 || (mi && mi->dataOnly()) || !dr->followedBy.empty()) { return true; } if (!mi) { @@ -258,6 +259,15 @@ bool writeDownloadResult(IOFile& fp, std::set<a2_gid_t>& metainfoCache, } } } + + // PREF_PAUSE was removed from option, so save it here looking + // property separately. + if (pauseRequested) { + if (!writeOptionLine(fp, PREF_PAUSE, A2_V_TRUE)) { + return false; + } + } + return writeOption(fp, dr->option); } } // namespace @@ -270,7 +280,7 @@ bool SessionSerializer::save(IOFile& fp) const if (dr->result == error_code::FINISHED || dr->result == error_code::REMOVED) { if (dr->option->getAsBool(PREF_FORCE_SAVE)) { - if (!writeDownloadResult(fp, metainfoCache, dr)) { + if (!writeDownloadResult(fp, metainfoCache, dr, false)) { return false; } } @@ -280,7 +290,7 @@ bool SessionSerializer::save(IOFile& fp) const } else if (dr->result == error_code::IN_PROGRESS) { if (saveInProgress_) { - if (!writeDownloadResult(fp, metainfoCache, dr)) { + if (!writeDownloadResult(fp, metainfoCache, dr, false)) { return false; } } @@ -288,7 +298,7 @@ bool SessionSerializer::save(IOFile& fp) const else { // error download if (saveError_) { - if (!writeDownloadResult(fp, metainfoCache, dr)) { + if (!writeDownloadResult(fp, metainfoCache, dr, false)) { return false; } } @@ -303,7 +313,8 @@ bool SessionSerializer::save(IOFile& fp) const dr->result == error_code::REMOVED; if ((!stopped && saveInProgress_) || (stopped && dr->option->getAsBool(PREF_FORCE_SAVE))) { - if (!writeDownloadResult(fp, metainfoCache, dr)) { + if (!writeDownloadResult(fp, metainfoCache, dr, + rg->isPauseRequested())) { return false; } } @@ -313,16 +324,10 @@ bool SessionSerializer::save(IOFile& fp) const const RequestGroupList& groups = rgman_->getReservedGroups(); for (const auto& rg : groups) { std::shared_ptr<DownloadResult> result = rg->createDownloadResult(); - if (!writeDownloadResult(fp, metainfoCache, result)) { + if (!writeDownloadResult(fp, metainfoCache, result, + rg->isPauseRequested())) { return false; } - // PREF_PAUSE was removed from option, so save it here looking - // property separately. - if (rg->isPauseRequested()) { - if (!writeOptionLine(fp, PREF_PAUSE, A2_V_TRUE)) { - return false; - } - } } } return true; |
