summaryrefslogtreecommitdiff
path: root/src/SessionSerializer.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-17 00:29:15 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-17 00:33:11 +0900
commit77a4ee4de008ff38d884f283c0b2f6ba4ce75390 (patch)
tree70e71d8a90a468b71bd361ed68cb0bdcc3588560 /src/SessionSerializer.cc
parent983cb3683afd1fa540192059cbe38fb62cc6ffba (diff)
Save gid option with --save-session option
Diffstat (limited to 'src/SessionSerializer.cc')
-rw-r--r--src/SessionSerializer.cc39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc
index 952f6889..185cda06 100644
--- a/src/SessionSerializer.cc
+++ b/src/SessionSerializer.cc
@@ -107,9 +107,23 @@ bool writeOption(BufferedFile& fp, const SharedHandle<Option>& op)
}
} // namespace
+// The downloads whose followedBy() is empty is persisited with its
+// GID without no problem. For other cases, there are several patterns.
+//
+// 1. magnet URI
+// GID of metadata download is persisted.
+// 2. URI to torrent file
+// GID of torrent file download is persisted.
+// 3. URI to metalink file
+// GID of metalink file download is persisted.
+// 4. local torrent file
+// GID of torrent download itself is persisted.
+// 5. local metalink file
+// No GID is persisted. GID is saved but it is just a random GID.
+
namespace {
bool writeDownloadResult
-(BufferedFile& fp, std::set<int64_t>& metainfoCache,
+(BufferedFile& fp, std::set<a2_gid_t>& metainfoCache,
const SharedHandle<DownloadResult>& dr)
{
const SharedHandle<MetadataInfo>& mi = dr->metadataInfo;
@@ -117,6 +131,15 @@ bool writeDownloadResult
return true;
}
if(!mi) {
+ // With --force-save option, same gid may be saved twice. (e.g.,
+ // Downloading .meta4 followed by its conent download. First
+ // .meta4 download is saved and second content download is also
+ // saved with the same gid.)
+ if(metainfoCache.count(dr->gid->getNumericId()) != 0) {
+ return true;
+ } else {
+ metainfoCache.insert(dr->gid->getNumericId());
+ }
// only save first file entry
if(dr->fileEntries.empty()) {
return true;
@@ -136,14 +159,22 @@ bool writeDownloadResult
if(fp.write("\n", 1) != 1) {
return false;
}
+ if(fp.printf(" gid=%s\n", dr->gid->toHex().c_str()) < 0) {
+ return false;
+ }
} else {
- if(metainfoCache.count(mi->getId()) != 0) {
+ if(metainfoCache.count(mi->getGID()) != 0) {
return true;
} else {
- metainfoCache.insert(mi->getId());
+ metainfoCache.insert(mi->getGID());
if(fp.printf("%s\n", mi->getUri().c_str()) < 0) {
return false;
}
+ // For downloads generated by metadata (e.g., BitTorrent,
+ // Metalink), save gid of Metadata download.
+ if(fp.printf(" gid=%s\n", GroupId::toHex(mi->getGID()).c_str()) < 0) {
+ return false;
+ }
}
}
return writeOption(fp, dr->option);
@@ -152,7 +183,7 @@ bool writeDownloadResult
bool SessionSerializer::save(BufferedFile& fp) const
{
- std::set<int64_t> metainfoCache;
+ std::set<a2_gid_t> metainfoCache;
const std::deque<SharedHandle<DownloadResult> >& results =
rgman_->getDownloadResults();
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr =