Skip to content

Commit

Permalink
More reasonable criteria for reusing a download
Browse files Browse the repository at this point in the history
  • Loading branch information
veloman-yunkan committed Mar 20, 2024
1 parent 9fe81e9 commit 3733e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 0 additions & 2 deletions include/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 20 additions & 1 deletion src/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "downloader.h"
#include "tools.h"
#include "tools/pathTools.h"
#include "tools/stringTools.h"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3733e50

Please sign in to comment.