return this->handleAskUser(context, *malware, pkgPtr);
}
-CsDetectedPtr CsLogic::scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath)
+CsDetectedPtr CsLogic::scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath, const std::function<void()> &isCancelled)
{
const auto &pkgPath = pkgPtr->getName();
const auto &pkgId = pkgPtr->getAppPkgId();
CsDetectedPtr riskiest;
// traverse files in app and take which is more danger than riskiest
auto visitor = FsVisitor::create([&](const FilePtr &file) {
+ if (isCancelled != nullptr)
+ isCancelled();
+
DEBUG("Scan file by engine: " << file->getPath());
auto timestamp = ::time(nullptr);
}
int CsLogic::scanApp(const CsContext &context, const FilePtr &pkgPtr,
- CsDetectedPtr &malware)
+ CsDetectedPtr &malware, const std::function<void()> &isCancelled)
{
const auto &pkgPath = pkgPtr->getName();
const auto &pkgId = pkgPtr->getAppPkgId();
auto history = this->m_db->getWorstByPkgPath(pkgPath, since);
// riskiest detected among newly scanned files
std::string riskiestPath;
- auto riskiest = this->scanAppDelta(pkgPtr, riskiestPath);
+ auto riskiest = this->scanAppDelta(pkgPtr, riskiestPath, isCancelled);
// history after delta scan. if worst file is changed, it's rescanned in scanAppDelta
// and deleted from db if it's cured. if history != nullptr && after == nullptr,
// it means worst detected item is cured anyway.
}
int CsLogic::scanFileInternal(const CsContext &context, const FilePtr &target,
- CsDetectedPtr &malware)
+ CsDetectedPtr &malware, const std::function<void()> &isCancelled)
{
if (target->isInApp())
- return this->scanApp(context, target, malware);
+ return this->scanApp(context, target, malware, isCancelled);
const auto &name = target->getName();
}
CsDetectedPtr malware;
- auto retcode = this->scanFileInternal(context, target, malware);
+ auto retcode = this->scanFileInternal(context, target, malware, isCancelled);
switch (retcode) {
case CSR_ERROR_NONE:
class CsLogic : public Logic {
public:
+ using CancelChecker = std::function<void()>;
+
CsLogic(const std::shared_ptr<CsLoader> &loader,
const std::shared_ptr<Db::Manager> &db);
virtual ~CsLogic() = default;
RawBuffer scanData(const CsContext &context, const RawBuffer &data);
RawBuffer scanFile(const CsContext &context, const std::string &filepath);
RawBuffer scanFilesAsync(const ConnShPtr &conn, const CsContext &context,
- StrSet &paths, const std::function<void()> &isCancelled);
+ StrSet &paths, const CancelChecker &isCancelled);
RawBuffer scanDirsAsync(const ConnShPtr &conn, const CsContext &context,
- StrSet &paths, const std::function<void()> &isCancelled);
+ StrSet &paths, const CancelChecker &isCancelled);
RawBuffer judgeStatus(const std::string &filepath, csr_cs_action_e action);
RawBuffer getDetected(const std::string &filepath);
RawBuffer getDetectedList(const StrSet &dirSet);
RawBuffer getIgnoredList(const StrSet &dirSet);
private:
- int scanFileInternal(const CsContext &context, const FilePtr &target, CsDetectedPtr &malware);
- int scanApp(const CsContext &context, const FilePtr &pkgPtr, CsDetectedPtr &malware);
+ int scanFileInternal(const CsContext &context, const FilePtr &target, CsDetectedPtr &malware, const CancelChecker &isCancelled = nullptr);
+ int scanApp(const CsContext &context, const FilePtr &pkgPtr, CsDetectedPtr &malware, const CancelChecker &isCancelled = nullptr);
int scanAppOnCloud(const CsContext &context, const FilePtr &pkgPtr, CsDetectedPtr &malware);
- CsDetectedPtr scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath);
+ CsDetectedPtr scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath, const CancelChecker &isCancelled = nullptr);
CsDetectedPtr convert(csre_cs_detected_h &result, const std::string &targetName,
time_t timestamp);