summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-07-04 17:45:48 +0900
committerKyungwook Tak <k.tak@samsung.com>2016-07-04 17:45:48 +0900
commite9c41ca7377a172c93da68144a3136ac4d80281c (patch)
treea191b3c06505437e3d5d7854560ea28a0ddf3beb
parent9a0e9a7454565598f4f6378417863f637764d766 (diff)
downloadcsr-framework-e9c41ca7377a172c93da68144a3136ac4d80281c.tar.gz
csr-framework-e9c41ca7377a172c93da68144a3136ac4d80281c.tar.bz2
csr-framework-e9c41ca7377a172c93da68144a3136ac4d80281c.zip
Add cancel checker in scan app delta
For canceling faster while big app scanning Change-Id: I935e2fa79c4ce213b2679aef4024c2bc0fc1109d Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r--src/framework/service/cs-logic.cpp15
-rw-r--r--src/framework/service/cs-logic.h12
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<void()> &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<void()> &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<void()> &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<void()>;
+
CsLogic(const std::shared_ptr<CsLoader> &loader,
const std::shared_ptr<Db::Manager> &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<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);
@@ -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);