/* */ #include "CheckIntegrityCommand.h" #include "CheckIntegrityEntry.h" #include "DownloadEngine.h" #include "RequestGroup.h" #include "Logger.h" #include "LogFactory.h" #include "message.h" #include "prefs.h" #include "DownloadContext.h" #include "a2functional.h" #include "RecoverableException.h" #include "util.h" #include "fmt.h" namespace aria2 { CheckIntegrityCommand::CheckIntegrityCommand (cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e, CheckIntegrityEntry* entry) : RealtimeCommand{cuid, requestGroup, e}, entry_{entry} {} CheckIntegrityCommand::~CheckIntegrityCommand() { getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry(); } bool CheckIntegrityCommand::executeInternal() { if(getRequestGroup()->isHaltRequested()) { return true; } entry_->validateChunk(); if(entry_->finished()) { // Enable control file saving here. See also // RequestGroup::processCheckIntegrityEntry() to know why this is // needed. getRequestGroup()->enableSaveControlFile(); if(getRequestGroup()->downloadFinished()) { A2_LOG_NOTICE (fmt(MSG_VERIFICATION_SUCCESSFUL, getRequestGroup()->getDownloadContext()->getBasePath().c_str())); std::vector> commands; entry_->onDownloadFinished(commands, getDownloadEngine()); getDownloadEngine()->addCommand(std::move(commands)); } else { A2_LOG_ERROR (fmt(MSG_VERIFICATION_FAILED, getRequestGroup()->getDownloadContext()->getBasePath().c_str())); std::vector> commands; entry_->onDownloadIncomplete(commands, getDownloadEngine()); getDownloadEngine()->addCommand(std::move(commands)); } getDownloadEngine()->setNoWait(true); return true; } else { getDownloadEngine()->addCommand(std::unique_ptr(this)); return false; } } bool CheckIntegrityCommand::handleException(Exception& e) { A2_LOG_ERROR_EX(fmt(MSG_FILE_VALIDATION_FAILURE, getCuid()), e); A2_LOG_ERROR (fmt(MSG_DOWNLOAD_NOT_COMPLETE, getCuid(), getRequestGroup()->getDownloadContext()->getBasePath().c_str())); return true; } } // namespace aria2