From b06903bb4ed32df38c7adf1a5b9db021643a2809 Mon Sep 17 00:00:00 2001 From: Idan Geraffi Date: Sat, 17 Feb 2024 12:50:50 +0200 Subject: [PATCH] [DetectorTest] Fixed ControlFile test --- src/ProtocolDetector.cc | 1 + src/download_helper.cc | 10 +++++++++- test/ProtocolDetectorTest.cc | 2 +- test/control_file.aria | Bin 0 -> 213 bytes test/control_file.aria2 | Bin 0 -> 213 bytes 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/control_file.aria create mode 100644 test/control_file.aria2 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 0000000000000000000000000000000000000000..bcd66cac3cedc0b20194107af0bd63524dc5ce5e GIT binary patch literal 213 zcmZQzWME(bVUgD_{Qs>sUvs0zY~m5K(A{SG%ypRz3P2ekm{oUz1;PT8vys??kqH2f CHVoJR literal 0 HcmV?d00001 diff --git a/test/control_file.aria2 b/test/control_file.aria2 new file mode 100644 index 0000000000000000000000000000000000000000..bcd66cac3cedc0b20194107af0bd63524dc5ce5e GIT binary patch literal 213 zcmZQzWME(bVUgD_{Qs>sUvs0zY~m5K(A{SG%ypRz3P2ekm{oUz1;PT8vys??kqH2f CHVoJR literal 0 HcmV?d00001