diff --git a/include/downloader.h b/include/downloader.h index 4cc7b7730..8342c4f40 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -191,10 +191,11 @@ class Downloader * User should call `update` on the returned `Download` to have an accurate status. * * @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 to pass to aria. * @return: The newly created Download. */ - std::shared_ptr startDownload(const std::string& uri, const Options& options = {}); + std::shared_ptr startDownload(const std::string& uri, const std::string& downloadDir, Options options = {}); /** * Get a download corrsponding to a download id (did) diff --git a/src/aria2.cpp b/src/aria2.cpp index 206a3032e..f2725c9fd 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -65,7 +65,6 @@ Aria2::Aria2(): std::vector callCmd; 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"); pauseAnyActiveDownloads(session_file); std::string session = "--save-session=" + session_file; @@ -94,7 +93,6 @@ Aria2::Aria2(): callCmd.push_back("--enable-rpc"); callCmd.push_back(rpc_secret.c_str()); callCmd.push_back(rpc_port.c_str()); - callCmd.push_back(download_dir.c_str()); if (fileReadable(session_file)) { callCmd.push_back(inputFile.c_str()); } diff --git a/src/downloader.cpp b/src/downloader.cpp index 5193c51de..ffc9d321e 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -209,9 +209,13 @@ bool downloadCanBeReused(const Download& d, } // unnamed namespace -std::shared_ptr Downloader::startDownload(const std::string& uri, const Options& options) +std::shared_ptr Downloader::startDownload(const std::string& uri, const std::string& downloadDir, Options options) { std::unique_lock 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) { auto& d = p.second; if ( downloadCanBeReused(*d, uri, options) )