From e9c41ca7377a172c93da68144a3136ac4d80281c Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Mon, 4 Jul 2016 17:45:48 +0900 Subject: [PATCH] Add cancel checker in scan app delta For canceling faster while big app scanning Change-Id: I935e2fa79c4ce213b2679aef4024c2bc0fc1109d Signed-off-by: Kyungwook Tak --- src/framework/service/cs-logic.cpp | 15 +++++++++------ src/framework/service/cs-logic.h | 12 +++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/framework/service/cs-logic.cpp b/src/framework/service/cs-logic.cpp index 6218478..efd0e10 100644 --- a/src/framework/service/cs-logic.cpp +++ b/src/framework/service/cs-logic.cpp @@ -236,7 +236,7 @@ int CsLogic::scanAppOnCloud(const CsContext &context, const FilePtr &pkgPtr, 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 &isCancelled) { const auto &pkgPath = pkgPtr->getName(); const auto &pkgId = pkgPtr->getAppPkgId(); @@ -252,6 +252,9 @@ CsDetectedPtr CsLogic::scanAppDelta(const FilePtr &pkgPtr, std::string &riskiest 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); @@ -288,7 +291,7 @@ CsDetectedPtr CsLogic::scanAppDelta(const FilePtr &pkgPtr, std::string &riskiest } int CsLogic::scanApp(const CsContext &context, const FilePtr &pkgPtr, - CsDetectedPtr &malware) + CsDetectedPtr &malware, const std::function &isCancelled) { const auto &pkgPath = pkgPtr->getName(); const auto &pkgId = pkgPtr->getAppPkgId(); @@ -303,7 +306,7 @@ int CsLogic::scanApp(const CsContext &context, const FilePtr &pkgPtr, 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. @@ -426,10 +429,10 @@ int CsLogic::scanApp(const CsContext &context, const FilePtr &pkgPtr, } int CsLogic::scanFileInternal(const CsContext &context, const FilePtr &target, - CsDetectedPtr &malware) + CsDetectedPtr &malware, const std::function &isCancelled) { if (target->isInApp()) - return this->scanApp(context, target, malware); + return this->scanApp(context, target, malware, isCancelled); const auto &name = target->getName(); @@ -524,7 +527,7 @@ RawBuffer CsLogic::scanFilesAsync(const ConnShPtr &conn, const CsContext &contex } CsDetectedPtr malware; - auto retcode = this->scanFileInternal(context, target, malware); + auto retcode = this->scanFileInternal(context, target, malware, isCancelled); switch (retcode) { case CSR_ERROR_NONE: diff --git a/src/framework/service/cs-logic.h b/src/framework/service/cs-logic.h index 3399fbc..1cc4cc7 100644 --- a/src/framework/service/cs-logic.h +++ b/src/framework/service/cs-logic.h @@ -40,6 +40,8 @@ namespace Csr { class CsLogic : public Logic { public: + using CancelChecker = std::function; + CsLogic(const std::shared_ptr &loader, const std::shared_ptr &db); virtual ~CsLogic() = default; @@ -47,9 +49,9 @@ public: 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 &isCancelled); + StrSet &paths, const CancelChecker &isCancelled); RawBuffer scanDirsAsync(const ConnShPtr &conn, const CsContext &context, - StrSet &paths, const std::function &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); @@ -57,10 +59,10 @@ public: 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); -- 2.7.4