Pass download directory directly to startDownload

This commit is contained in:
sgourdas 2024-08-11 23:45:27 +03:00
parent ff6d8a4b30
commit 566b40a2f8
3 changed files with 7 additions and 4 deletions

View File

@ -191,10 +191,11 @@ class Downloader
* User should call `update` on the returned `Download` to have an accurate status. * User should call `update` on the returned `Download` to have an accurate status.
* *
* @param uri: The uri of the thing to download. * @param uri: The uri of the thing to download.
* @param downloadDir: The download directory where the thing should be stored (takes precedence over any "dir" in `options`).
* @param options: A series of pair <option_name, option_value> to pass to aria. * @param options: A series of pair <option_name, option_value> to pass to aria.
* @return: The newly created Download. * @return: The newly created Download.
*/ */
std::shared_ptr<Download> startDownload(const std::string& uri, const Options& options = {}); std::shared_ptr<Download> startDownload(const std::string& uri, const std::string& downloadDir, Options options = {});
/** /**
* Get a download corrsponding to a download id (did) * Get a download corrsponding to a download id (did)

View File

@ -65,7 +65,6 @@ Aria2::Aria2():
std::vector<const char*> callCmd; std::vector<const char*> callCmd;
std::string rpc_port = "--rpc-listen-port=" + to_string(m_port); std::string rpc_port = "--rpc-listen-port=" + to_string(m_port);
std::string download_dir = "--dir=" + getDataDirectory();
std::string session_file = appendToDirectory(getDataDirectory(), "kiwix.session"); std::string session_file = appendToDirectory(getDataDirectory(), "kiwix.session");
pauseAnyActiveDownloads(session_file); pauseAnyActiveDownloads(session_file);
std::string session = "--save-session=" + session_file; std::string session = "--save-session=" + session_file;
@ -94,7 +93,6 @@ Aria2::Aria2():
callCmd.push_back("--enable-rpc"); callCmd.push_back("--enable-rpc");
callCmd.push_back(rpc_secret.c_str()); callCmd.push_back(rpc_secret.c_str());
callCmd.push_back(rpc_port.c_str()); callCmd.push_back(rpc_port.c_str());
callCmd.push_back(download_dir.c_str());
if (fileReadable(session_file)) { if (fileReadable(session_file)) {
callCmd.push_back(inputFile.c_str()); callCmd.push_back(inputFile.c_str());
} }

View File

@ -209,9 +209,13 @@ bool downloadCanBeReused(const Download& d,
} // unnamed namespace } // unnamed namespace
std::shared_ptr<Download> Downloader::startDownload(const std::string& uri, const Options& options) std::shared_ptr<Download> Downloader::startDownload(const std::string& uri, const std::string& downloadDir, Options options)
{ {
std::unique_lock<std::mutex> lock(m_lock); std::unique_lock<std::mutex> lock(m_lock);
options.erase(std::remove_if(options.begin(), options.end(), [](const auto& option) {
return option.first == "dir";
}), options.end());
options.push_back({"dir", downloadDir});
for (auto& p: m_knownDownloads) { for (auto& p: m_knownDownloads) {
auto& d = p.second; auto& d = p.second;
if ( downloadCanBeReused(*d, uri, options) ) if ( downloadCanBeReused(*d, uri, options) )