diff --git a/doc/manual-src/en/aria2c.rst b/doc/manual-src/en/aria2c.rst index c073ab53..b806f338 100644 --- a/doc/manual-src/en/aria2c.rst +++ b/doc/manual-src/en/aria2c.rst @@ -1334,14 +1334,30 @@ Advanced Options .. option:: --save-session= Save error/unfinished downloads to FILE on exit. You can pass this - output file to aria2c with :option:`--input-file <-i>` option on restart. Please note that - downloads added by :func:`aria2.addTorrent` and - :func:`aria2.addMetalink` - RPC method and whose metadata could not be saved as a file are not saved. - Downloads removed using - :func:`aria2.remove` and - :func:`aria2.forceRemove` - will not be saved. + output file to aria2c with :option:`--input-file <-i>` option on + restart. Please note that downloads added by + :func:`aria2.addTorrent` and :func:`aria2.addMetalink` RPC method + and whose metadata could not be saved as a file are not saved. + Downloads removed using :func:`aria2.remove` and + :func:`aria2.forceRemove` will not be saved. GID is also saved with + :option:`gid <--gid>`, but there are some restrictions, see below. + + .. note:: + + Normally, GID of the download itself is saved. But some downloads + use metadata (e.g., BitTorrent and Metalink). In this case, there + are some restrictions. + + 1. magnet URI, and followed by torrent download + GID of BitTorrent metadata download is saved. + 2. URI to torrent file, and followed by torrent download + GID of torrent file download is saved. + 3. URI to metalink file, and followed by file downloads described in metalink file + GID of metalink file download is saved. + 4. local torrent file + GID of torrent download is saved. + 5. local metalink file + Any meaningful GID is not saved. .. option:: --stop= diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc index 35976814..614b0c69 100644 --- a/src/BtPostDownloadHandler.cc +++ b/src/BtPostDownloadHandler.cc @@ -108,7 +108,8 @@ void BtPostDownloadHandler::getNextRequestGroups torrent); requestGroup->followedBy(newRgs.begin(), newRgs.end()); SharedHandle mi = - createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); + createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(), + requestGroup->getDownloadContext()); if(mi) { setMetadataInfo(newRgs.begin(), newRgs.end(), mi); } diff --git a/src/MetadataInfo.cc b/src/MetadataInfo.cc index bfed340f..df3077a1 100644 --- a/src/MetadataInfo.cc +++ b/src/MetadataInfo.cc @@ -36,22 +36,13 @@ namespace aria2 { -int64_t MetadataInfo::count_ = 0; - -MetadataInfo::MetadataInfo(const std::string& uri) - : id_(genId()), uri_(uri), dataOnly_(false) +MetadataInfo::MetadataInfo(const SharedHandle& gid, + const std::string& uri) + : gid_(gid), uri_(uri) {} -MetadataInfo::MetadataInfo():id_(genId()), dataOnly_(true) {} +MetadataInfo::MetadataInfo() {} MetadataInfo::~MetadataInfo() {} -int64_t MetadataInfo::genId() -{ - if(count_ == INT64_MAX) { - count_ = 0; - } - return ++count_; -} - } // namespace aria2 diff --git a/src/MetadataInfo.h b/src/MetadataInfo.h index 482a82dc..7a5ac7f9 100644 --- a/src/MetadataInfo.h +++ b/src/MetadataInfo.h @@ -39,16 +39,17 @@ #include +#include "SharedHandle.h" +#include "GroupId.h" + namespace aria2 { class MetadataInfo { private: - int64_t id_; + SharedHandle gid_; std::string uri_; - bool dataOnly_; - static int64_t count_; public: - MetadataInfo(const std::string& uri); + MetadataInfo(const SharedHandle& gid, const std::string& uri); MetadataInfo(); @@ -56,7 +57,7 @@ public: bool dataOnly() const { - return dataOnly_; + return !gid_; } const std::string& getUri() const @@ -64,12 +65,11 @@ public: return uri_; } - int64_t getId() const + a2_gid_t getGID() const { - return id_; + assert(gid_); + return gid_->getNumericId(); } - - static int64_t genId(); }; } // namespace aria2 diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 3a282618..d849e52c 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -123,7 +123,9 @@ Metalink2RequestGroup::generate if(metalinkFile == DEV_STDIN) { mi.reset(new MetadataInfo()); } else { - mi.reset(new MetadataInfo(metalinkFile)); + // TODO Downloads from local metalink file does not save neither + // its gid nor MetadataInfo's gid. + mi.reset(new MetadataInfo(GroupId::create(), metalinkFile)); } setMetadataInfo(tempgroups.begin(), tempgroups.end(), mi); groups.insert(groups.end(), tempgroups.begin(), tempgroups.end()); diff --git a/src/MetalinkPostDownloadHandler.cc b/src/MetalinkPostDownloadHandler.cc index f504bf01..44f794cf 100644 --- a/src/MetalinkPostDownloadHandler.cc +++ b/src/MetalinkPostDownloadHandler.cc @@ -106,7 +106,8 @@ void MetalinkPostDownloadHandler::getNextRequestGroups requestGroup->getOption(), baseUri); requestGroup->followedBy(newRgs.begin(), newRgs.end()); SharedHandle mi = - createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); + createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(), + requestGroup->getDownloadContext()); if(mi) { setMetadataInfo(newRgs.begin(), newRgs.end(), mi); } diff --git a/src/RequestGroup.h b/src/RequestGroup.h index df35c19e..7713d4ba 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -265,6 +265,11 @@ public: return gid_->getNumericId(); } + const SharedHandle& getGroupId() const + { + return gid_; + } + TransferStat calculateStat() const; const SharedHandle& getDownloadContext() const 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