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.
pull/567/merge
Tatsuhiro Tsujikawa 2016-03-13 16:11:29 +09:00
parent 1a0e5e32f3
commit 4595aa75e1
1 changed files with 19 additions and 14 deletions

View File

@ -189,10 +189,11 @@ bool writeUri(IOFile& fp, InputIterator first, InputIterator last,
namespace { namespace {
bool writeDownloadResult(IOFile& fp, std::set<a2_gid_t>& metainfoCache, 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; 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; return true;
} }
if (!mi) { 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); return writeOption(fp, dr->option);
} }
} // namespace } // namespace
@ -270,7 +280,7 @@ bool SessionSerializer::save(IOFile& fp) const
if (dr->result == error_code::FINISHED || if (dr->result == error_code::FINISHED ||
dr->result == error_code::REMOVED) { dr->result == error_code::REMOVED) {
if (dr->option->getAsBool(PREF_FORCE_SAVE)) { if (dr->option->getAsBool(PREF_FORCE_SAVE)) {
if (!writeDownloadResult(fp, metainfoCache, dr)) { if (!writeDownloadResult(fp, metainfoCache, dr, false)) {
return false; return false;
} }
} }
@ -280,7 +290,7 @@ bool SessionSerializer::save(IOFile& fp) const
} }
else if (dr->result == error_code::IN_PROGRESS) { else if (dr->result == error_code::IN_PROGRESS) {
if (saveInProgress_) { if (saveInProgress_) {
if (!writeDownloadResult(fp, metainfoCache, dr)) { if (!writeDownloadResult(fp, metainfoCache, dr, false)) {
return false; return false;
} }
} }
@ -288,7 +298,7 @@ bool SessionSerializer::save(IOFile& fp) const
else { else {
// error download // error download
if (saveError_) { if (saveError_) {
if (!writeDownloadResult(fp, metainfoCache, dr)) { if (!writeDownloadResult(fp, metainfoCache, dr, false)) {
return false; return false;
} }
} }
@ -303,7 +313,8 @@ bool SessionSerializer::save(IOFile& fp) const
dr->result == error_code::REMOVED; dr->result == error_code::REMOVED;
if ((!stopped && saveInProgress_) || if ((!stopped && saveInProgress_) ||
(stopped && dr->option->getAsBool(PREF_FORCE_SAVE))) { (stopped && dr->option->getAsBool(PREF_FORCE_SAVE))) {
if (!writeDownloadResult(fp, metainfoCache, dr)) { if (!writeDownloadResult(fp, metainfoCache, dr,
rg->isPauseRequested())) {
return false; return false;
} }
} }
@ -313,16 +324,10 @@ bool SessionSerializer::save(IOFile& fp) const
const RequestGroupList& groups = rgman_->getReservedGroups(); const RequestGroupList& groups = rgman_->getReservedGroups();
for (const auto& rg : groups) { for (const auto& rg : groups) {
std::shared_ptr<DownloadResult> result = rg->createDownloadResult(); std::shared_ptr<DownloadResult> result = rg->createDownloadResult();
if (!writeDownloadResult(fp, metainfoCache, result)) { if (!writeDownloadResult(fp, metainfoCache, result,
rg->isPauseRequested())) {
return false; 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; return true;