diff --git a/include/downloader.h b/include/downloader.h index 93a57603b..4cc7b7730 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -187,8 +187,6 @@ class Downloader * have different values for the download directory or output file name * options, after the download is reported to be complete the downloaded file * will be present only at the location specified for the first request. - * Also, due to the above peculiarity there is no straightforward way to - * repeat a completed or cancelled download whose files have been deleted. * * User should call `update` on the returned `Download` to have an accurate status. * diff --git a/src/downloader.cpp b/src/downloader.cpp index 44de4d40d..25dfc1e95 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -18,6 +18,7 @@ */ #include "downloader.h" +#include "tools.h" #include "tools/pathTools.h" #include "tools/stringTools.h" @@ -176,7 +177,25 @@ bool downloadCanBeReused(const Download& d, const auto& uris = d.getUris(); const bool sameURI = std::find(uris.begin(), uris.end(), uri) != uris.end(); - return sameURI; + if ( !sameURI ) + return false; + + switch ( d.getStatus() ) { + case Download::K_ERROR: + case Download::K_UNKNOWN: + case Download::K_REMOVED: + return false; + + case Download::K_ACTIVE: + case Download::K_WAITING: + case Download::K_PAUSED: + return true; // XXX: what if options are different? + + case Download::K_COMPLETE: + return fileExists(d.getPath()); // XXX: what if options are different? + } + + return false; } } // unnamed namespace