mirror of https://github.com/aria2/aria2
[ProtocolDetector] Added detector for aria2 control file
parent
02f2d0d847
commit
273dee180c
|
@ -44,3 +44,4 @@ compile
|
|||
main.log
|
||||
main.trs
|
||||
test-suite.log
|
||||
.vscode/
|
||||
|
|
|
@ -372,6 +372,11 @@ Time File::getModifiedTime()
|
|||
return Time(fstat.st_mtime);
|
||||
}
|
||||
|
||||
std::string File::getExtension() const
|
||||
{
|
||||
return name_.substr(name_.find_last_of("."));
|
||||
}
|
||||
|
||||
std::string File::getCurrentDir()
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
|
|
@ -120,6 +120,8 @@ public:
|
|||
|
||||
Time getModifiedTime();
|
||||
|
||||
std::string getExtension() const;
|
||||
|
||||
// Returns the current working directory. If the current working
|
||||
// directory cannot be retrieved or its length is larger than 2048,
|
||||
// returns ".".
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#ifdef ENABLE_BITTORRENT
|
||||
# include "bittorrent_helper.h"
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#include "DefaultBtProgressInfoFile.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -107,4 +108,16 @@ 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;
|
||||
}
|
||||
|
||||
const auto control_file_suffix = DefaultBtProgressInfoFile::getSuffix();
|
||||
return control_file.getExtension() == control_file_suffix;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -60,6 +60,10 @@ public:
|
|||
// Returns true if ProtocolDetector thinks uri is a path of Metalink XML
|
||||
// file, otherwise return false.
|
||||
bool guessMetalinkFile(const std::string& uri) const;
|
||||
|
||||
// Returns true if ProtocolDetector thinks uri is a path to aria2 control
|
||||
// file, otherwise return false
|
||||
bool guessAria2ControlFile(const std::string& uri) const;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -445,7 +445,13 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ENABLE_METALINK
|
||||
//TOOD: ifdef of ENABLE aria2
|
||||
else if (!ignoreLocalPath_ && detector_.guessAria2ControlFile(uri))
|
||||
{
|
||||
|
||||
}
|
||||
else {
|
||||
if (throwOnError_) {
|
||||
throw DL_ABORT_EX(fmt(MSG_UNRECOGNIZED_URI, uri.c_str()));
|
||||
|
|
|
@ -14,6 +14,7 @@ class ProtocolDetectorTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testGuessTorrentFile);
|
||||
CPPUNIT_TEST(testGuessTorrentMagnet);
|
||||
CPPUNIT_TEST(testGuessMetalinkFile);
|
||||
CPPUNIT_TEST(testGuessAria2ControlFile);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
@ -25,6 +26,7 @@ public:
|
|||
void testGuessTorrentFile();
|
||||
void testGuessTorrentMagnet();
|
||||
void testGuessMetalinkFile();
|
||||
void testGuessAria2ControlFile();
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
|
||||
|
@ -66,4 +68,12 @@ void ProtocolDetectorTest::testGuessMetalinkFile()
|
|||
CPPUNIT_ASSERT(!detector.guessMetalinkFile(A2_TEST_DIR "/test.torrent"));
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue