diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc index 1e496202..9a50a5a9 100644 --- a/src/ProtocolDetector.cc +++ b/src/ProtocolDetector.cc @@ -111,6 +111,7 @@ bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const bool ProtocolDetector::guessAria2ControlFile(const std::string& uri) const { File control_file(uri); + if(!control_file.isFile()) { return false; diff --git a/src/download_helper.cc b/src/download_helper.cc index ca903f71..93d19ee2 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -64,10 +64,12 @@ #include "download_handlers.h" #include "SimpleRandomizer.h" #ifdef ENABLE_BITTORRENT -# include "bittorrent_helper.h" # include "BtConstants.h" # include "ValueBaseBencodeParser.h" #endif // ENABLE_BITTORRENT +// TODO ENABLE CONTROLFILE +#include "TorrentAttribute.h" +#include "bittorrent_helper.h" namespace aria2 { @@ -450,7 +452,13 @@ public: //TOOD: ifdef of ENABLE aria2 else if (!ignoreLocalPath_ && detector_.guessAria2ControlFile(uri)) { + // Extract hash and construct a magnet to feed into createBtMagentRequestGroup + + auto torrent_attribute = std::make_unique(); + // torrent_attribute->infoHash = the hash from the file + const auto magent = aria2::bittorrent::torrent2Magnet(torrent_attribute.get()); + requestGroups_.push_back(createBtMagnetRequestGroup(magent, option_)); } else { if (throwOnError_) { diff --git a/test/ProtocolDetectorTest.cc b/test/ProtocolDetectorTest.cc index 3d5d988b..84d8ce30 100644 --- a/test/ProtocolDetectorTest.cc +++ b/test/ProtocolDetectorTest.cc @@ -73,7 +73,7 @@ void ProtocolDetectorTest::testGuessAria2ControlFile() const ProtocolDetector detector; CPPUNIT_ASSERT(detector.guessAria2ControlFile(A2_TEST_DIR "/control_file.aria2")); CPPUNIT_ASSERT(!detector.guessAria2ControlFile(A2_TEST_DIR)); - CPPUNIT_ASSERT(detector.guessAria2ControlFile(A2_TEST_DIR "/control_file.aria")); + CPPUNIT_ASSERT(!detector.guessAria2ControlFile(A2_TEST_DIR "/control_file.aria")); } } // namespace aria2 diff --git a/test/control_file.aria b/test/control_file.aria new file mode 100644 index 00000000..bcd66cac Binary files /dev/null and b/test/control_file.aria differ diff --git a/test/control_file.aria2 b/test/control_file.aria2 new file mode 100644 index 00000000..bcd66cac Binary files /dev/null and b/test/control_file.aria2 differ