More reasonable criteria for reusing a download

This commit is contained in:
Veloman Yunkan 2024-02-27 19:51:12 +04:00
parent 9fe81e9bce
commit 3733e506c1
2 changed files with 20 additions and 3 deletions

View File

@ -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.
*

View File

@ -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