Merge branch 'sandbox/kwon/transaction' into devel 40/77840/5
authorKyungwook Tak <k.tak@samsung.com>
Tue, 5 Jul 2016 06:52:37 +0000 (15:52 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Tue, 5 Jul 2016 07:04:07 +0000 (16:04 +0900)
Change-Id: I5207e7e1a33a00c0ea47582b6456e2e35a9b8a43
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
1  2 
src/framework/db/cache.h
src/framework/db/manager.cpp
src/framework/db/manager.h
src/framework/service/cs-logic.cpp
src/framework/service/cs-logic.h
test/internals/test-db.cpp

index 0000000,20fc5b2..6bf2ec4
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,54 +1,54 @@@
 -      std::vector<CsDetected> detecteds;
+ /*
+  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+  *
+  *  Licensed under the Apache License, Version 2.0 (the "License");
+  *  you may not use this file except in compliance with the License.
+  *  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  *  Unless required by applicable law or agreed to in writing, software
+  *  distributed under the License is distributed on an "AS IS" BASIS,
+  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  *  See the License for the specific language governing permissions and
+  *  limitations under the License
+  */
+ /*
+  * @file        cache.h
+  * @author      Sangwan Kwon (sangwan.kwon@samsung.com)
+  * @version     1.0
+  * @brief       Cache for hold the data temporally before insert to DB
+  */
+ #pragma once
+ #include <string>
+ #include <vector>
+ #include <ctime>
+ #include "common/cs-detected.h"
+ namespace Csr {
+ namespace Db {
+ struct Cache {
+ public:
+       Cache() = default;
+       virtual ~Cache() = default;
+       Cache(const Cache &) = delete;
+       Cache &operator=(const Cache &) = delete;
+       Cache(Cache &&) noexcept;
+       Cache &operator=(Cache &&) noexcept;
+       std::string pkgPath;
+       std::string pkgId;
+       std::string dataVersion;
+       std::string riskiestPath;
+       std::vector<std::string> filePaths;
++      std::vector<CsDetectedPtr> detecteds;
+       CsDetectedPtr riskiest;
+       time_t scanTime;
+ };
+ } // namespace Db
+ } // namespace Csr
@@@ -461,12 -462,19 +461,12 @@@ void Manager::insertDetectedFile(const 
  {
        std::lock_guard<std::mutex> l(this->m_mutex);
  
 -      this->insertName(filepath);
 -      this->insertDetected(d, filepath, dataVersion);
 -}
 -
 -void Manager::insertDetectedFileInApp(const std::string &pkgpath, const std::string &filepath,
 -                                                                        const CsDetected &d, const std::string &dataVersion)
 -{
 -      this->insertName(pkgpath);
 -      this->insertDetected(d, filepath, dataVersion);
 +      this->insertName(d.targetName);
 +      this->insertDetected(d, d.targetName, dataVersion);
  }
  
- void Manager::insertDetectedFileInApp(const std::string &filepath,
-                                                                         const CsDetected &d, const std::string &dataVersion)
+ void Manager::insertDetectedAppByCloud(const std::string &name, const std::string &pkgId,
+                                                                          const CsDetected &d, const std::string &dataVersion)
  {
        std::lock_guard<std::mutex> l(this->m_mutex);
  
@@@ -479,8 -486,9 +478,9 @@@ void Manager::insertCache(const Cache &
  {
        std::lock_guard<std::mutex> l(this->m_mutex);
  
-       this->insertName(name);
-       this->insertDetectedCloud(d, pkgId, name, dataVersion);
 -      for(std::vector<int>::size_type i = 0; i < c.detecteds.size(); i++)
 -              this->insertDetectedFileInApp(
 -                      c.pkgPath, c.filePaths[i], c.detecteds[i], c.dataVersion);
++      this->insertName(c.pkgPath);
++      for (std::vector<int>::size_type i = 0; i < c.detecteds.size(); ++i)
++              this->insertDetected(*c.detecteds[i], c.filePaths[i], c.dataVersion);
  }
  
  void Manager::insertName(const std::string &name)
@@@ -66,9 -67,9 +67,8 @@@ public
        RowShPtrs getDetectedByFilepathOnDir(const std::string &dir, time_t since);
        RowShPtr getWorstByPkgPath(const std::string &pkgPath, time_t since);
  
 -      void insertDetectedFile(const std::string &filepath, const CsDetected &d,
 -                                                      const std::string &dataVersion);
+       void insertCache(const Cache &c);
-       void insertDetectedFileInApp(const std::string &filepath,
-                                                                const CsDetected &d, const std::string &dataVersion);
 +      void insertDetectedFile(const CsDetected &d, const std::string &dataVersion);
        void insertDetectedAppByCloud(const std::string &name, const std::string &pkgId,
                                                         const CsDetected &d, const std::string &dataVersion);
        void insertWorst(const std::string &pkgId, const std::string &name,
@@@ -225,36 -182,34 +226,39 @@@ int CsLogic::scanAppOnCloud(const CsCon
        this->m_loader->scanAppOnCloud(c, pkgPath, &result);
  
        if (!result)
 -              return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
 +              return CSR_ERROR_NONE;
  
 -      auto detected = this->convert(result, pkgPath, timestamp);
 -      detected.isApp = true;
 -      detected.pkgId = pkgId;
 +      malware = this->convert(result, pkgPath, timestamp);
 +      malware->isApp = true;
 +      malware->pkgId = pkgId;
  
 -      this->m_db->insertDetectedAppByCloud(pkgPath, pkgId, detected, this->m_dataVersion);
 +      this->m_db->insertDetectedAppByCloud(pkgPath, pkgId, *malware, this->m_dataVersion);
  
 -      return this->handleAskUser(context, detected);
 +      return this->handleAskUser(context, *malware, pkgPtr);
  }
  
- CsDetectedPtr CsLogic::scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath, const std::function<void()> &isCancelled)
 -Db::Cache CsLogic::scanAppDelta(const std::string &pkgPath, const std::string &pkgId)
++Db::Cache CsLogic::scanAppDelta(const FilePtr &pkgPtr, const CancelChecker &isCancelled)
  {
-       auto starttime = ::time(nullptr);
 +      const auto &pkgPath = pkgPtr->getName();
 +      const auto &pkgId = pkgPtr->getAppPkgId();
 +
        CsEngineContext engineContext(this->m_loader);
        auto &c = engineContext.get();
  
        auto t = this->m_loader->getEngineLatestUpdateTime(c);
        auto lastScanTime = this->m_db->getLastScanTime(pkgPath, t);
  
-       CsDetectedPtr riskiest;
 -      // traverse files in app and take which is more danger than riskiest
 -      auto visitor = FsVisitor::create(pkgPath, lastScanTime);
+       Db::Cache cache;
+       cache.pkgPath = pkgPath;
+       cache.pkgId = pkgId;
+       cache.scanTime = ::time(nullptr);
+       cache.dataVersion = this->m_dataVersion;
 -      while (auto file = visitor->next()) {
 +      // 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);
                INFO("New malware detected on file: " << file->getPath());
  
                auto candidate = this->convert(result, pkgPath, timestamp);
 -              candidate.isApp = true;
 -              candidate.pkgId = pkgId;
 -
 -              cache.filePaths.push_back(file->getPath());
 -              cache.detecteds.push_back(candidate);
 +              candidate->isApp = true;
 +              candidate->pkgId = pkgId;
  
-               this->m_db->insertDetectedFileInApp(file->getPath(), *candidate, this->m_dataVersion);
-               if (riskiest == nullptr || *riskiest < *candidate) {
-                       riskiest = std::move(candidate);
-                       riskiestPath = file->getPath();
+               if (!cache.riskiest) {
 -                      cache.riskiest.reset(new CsDetected(std::move(candidate)));
++                      cache.riskiest.reset(new CsDetected(*candidate));
+                       cache.riskiestPath = file->getPath();
 -              } else if (*(cache.riskiest) < candidate) {
 -                      *(cache.riskiest) = std::move(candidate);
++              } else if (*(cache.riskiest) < *candidate) {
++                      *(cache.riskiest) = *candidate;
+                       cache.riskiestPath = file->getPath();
                }
 -      }
++
++              cache.filePaths.push_back(file->getPath());
++              cache.detecteds.emplace_back(std::move(candidate));
 +      }, pkgPath, false, lastScanTime);
 +
 +      visitor->run();
  
-       this->m_db->insertLastScanTime(pkgPath, this->m_dataVersion, starttime);
-       return riskiest;
+       return cache;
  }
  
 -RawBuffer CsLogic::scanApp(const CsContext &context, const std::string &pkgPath)
 +int CsLogic::scanApp(const CsContext &context, const FilePtr &pkgPtr,
 +                                       CsDetectedPtr &malware, const std::function<void()> &isCancelled)
  {
 -      auto fileptr = File::create(pkgPath);
 -
 -      if (!fileptr)
 -              ThrowExc(CSR_ERROR_SERVER, "fileptr shouldn't be empty because didn't check modified");
 -      if (!fileptr->isInApp())
 -              ThrowExc(CSR_ERROR_SERVER, "fileptr should be in app.");
 -
 -      const auto &pkgId = fileptr->getAppPkgId();
 +      const auto &pkgPath = pkgPtr->getName();
 +      const auto &pkgId = pkgPtr->getAppPkgId();
  
        if (context.isScanOnCloud && this->m_loader->scanAppOnCloudSupported())
 -              return this->scanAppOnCloud(context, pkgPath, pkgId);
 +              return this->scanAppOnCloud(context, pkgPtr, malware);
  
        CsEngineContext engineContext(this->m_loader);
        auto since = this->m_loader->getEngineLatestUpdateTime(engineContext.get());
  
        // old history
        auto history = this->m_db->getWorstByPkgPath(pkgPath, since);
        // riskiest detected among newly scanned files
-       std::string 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.
 -      auto cache = this->scanAppDelta(pkgPath, pkgId);
++      auto cache = this->scanAppDelta(pkgPtr, isCancelled);
+       // history after delta scan.
+       // if worst file is changed, it's rescanned in scanAppDelta
        auto after = this->m_db->getWorstByPkgPath(pkgPath, since);
-       if (history && after && riskiest) {
-               if (*history < *riskiest) {
-                       INFO("worst case is remained but the more worst newly detected. on pkg[" <<
-                                pkgPath << "]");
-                       if (history->isIgnored)
-                               this->m_db->updateIgnoreFlag(pkgPath, false);
-                       this->m_db->insertWorst(pkgId, pkgPath, riskiestPath);
-                       malware.reset(new CsDetected());
-                       *malware = std::move(*riskiest);
-                       return this->handleAskUser(context, *malware);
-               } else {
-                       INFO("worst case is remained and can be re-used on pkg[" << pkgPath << "]");
-                       if (history->isIgnored)
-                               return CSR_ERROR_NONE;
  
-                       malware.reset(new CsDetected());
-                       *malware = std::move(*history);
-                       return this->handleAskUser(context, *malware);
-               }
-       } else if (history && after && !riskiest) {
-               INFO("worst case is remained and NO new detected. history can be re-used. "
-                        "on pkg[" << pkgPath << "]");
-               if (history->isIgnored)
+       Db::RowShPtr jHistory;
+       Db::RowShPtr jWorse;
+       auto &riskiest = cache.riskiest;
+       INFO("start to judge scan stage on pkg[" << pkgPath << "]");
 -      switch (this->judgeScanStage(history, after, riskiest,
 -                      jWorse, jHistory, since)) {
++      switch (this->judgeScanStage(history, after, riskiest, jWorse, jHistory, since)) {
+       case CsLogic::ScanStage::NEW_RISKIEST :
+               this->m_db->transactionBegin();
+               this->m_db->insertCache(cache);
+               this->m_db->insertWorst(pkgId, pkgPath, cache.riskiestPath);
+               this->m_db->updateIgnoreFlag(pkgPath, false);
+               this->m_db->insertLastScanTime(pkgPath, cache.dataVersion, cache.scanTime);
+               this->m_db->transactionEnd();
 -              return this->handleAskUser(context, *riskiest);
++
++              malware = std::move(riskiest);
++              return this->handleAskUser(context, *malware, pkgPtr);
+       case CsLogic::ScanStage::NEW_RISKIEST_KEEP_FLAG :
+               this->m_db->transactionBegin();
+               this->m_db->insertCache(cache);
+               this->m_db->insertWorst(pkgId, pkgPath, cache.riskiestPath);
+               this->m_db->insertLastScanTime(pkgPath, cache.dataVersion, cache.scanTime);
+               this->m_db->transactionEnd();
+               if (jWorse->isIgnored)
 -                      return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
++                      return CSR_ERROR_NONE;
 -              return this->handleAskUser(context, *riskiest);
++              malware = std::move(riskiest);
++              return this->handleAskUser(context, *malware, pkgPtr);
+       case CsLogic::ScanStage::HISTORY_RISKIEST :
+               this->m_db->transactionBegin();
+               this->m_db->insertCache(cache);
+               this->m_db->insertLastScanTime(pkgPath, cache.dataVersion, cache.scanTime);
+               this->m_db->transactionEnd();
+               if (jHistory->isIgnored)
 -                      return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
 -              return this->handleAskUser(context, *jHistory);
 +                      return CSR_ERROR_NONE;
 +
 +              malware.reset(new CsDetected());
-               *malware = std::move(*history);
-               return this->handleAskUser(context, *malware);
-       } else if (history && !after && riskiest) {
-               INFO("worst case is deleted but new detected. we have to find out "
-                        "worse case in db and compare it with riskiest first. on pkg[" << pkgPath <<
-                        "]");
-               Db::RowShPtr worse;
-               since = this->m_loader->getEngineLatestUpdateTime(engineContext.get());
-               for (auto &row : this->m_db->getDetectedByFilepathOnDir(pkgPath, since))
-                       if (!worse || *worse < *row)
-                               worse = std::move(row);
-               if (!worse) {
-                       INFO("No detected malware found in db.... Newly detected malware is removed by "
-                                "other client. Handle it as fully clean case.");
++              *malware = *jHistory;
++              return this->handleAskUser(context, *malware, pkgPtr);
+       case CsLogic::ScanStage::WORSE_RISKIEST :
+               this->m_db->transactionBegin();
+               this->m_db->insertCache(cache);
+               this->m_db->insertWorst(pkgId, pkgPath, jWorse->fileInAppPath);
+               this->m_db->insertLastScanTime(pkgPath, cache.dataVersion, cache.scanTime);
+               this->m_db->transactionEnd();
+               if (jWorse->isIgnored)
 -                      return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
 -              return this->handleAskUser(context, *jWorse);
 +                      return CSR_ERROR_NONE;
-               }
 +
-               if (*riskiest < *worse) {
-                       INFO("worse case in db is worse than riskiest. on pkg[" << pkgPath << "]");
-                       riskiestPath = worse->fileInAppPath;
-                       *riskiest = std::move(*worse);
-               }
++              malware.reset(new CsDetected());
++              *malware = *jWorse;
++              return this->handleAskUser(context, *malware, pkgPtr);
  
-               if (*history < *riskiest) {
-                       INFO("worst case is deleted but the more worst newly detected. on pkg[" <<
-                                pkgPath << "]");
-                       if (history->isIgnored)
-                               this->m_db->updateIgnoreFlag(pkgPath, false);
+       case CsLogic::ScanStage::NO_DETECTED :
+               this->m_db->insertLastScanTime(pkgPath, cache.dataVersion, cache.scanTime);
 -              return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
++              return CSR_ERROR_NONE;
  
-                       this->m_db->insertWorst(pkgId, pkgPath, riskiestPath);
+       default:
+               ThrowExc(CSR_ERROR_SERVER, "Invalid scan app status.");
+       }
+ }
  
-                       malware.reset(new CsDetected());
-                       *malware = std::move(*riskiest);
-                       return this->handleAskUser(context, *malware);
-               } else {
-                       INFO("worst case is deleted but same or less level newly detected. on pkg[" <<
-                                pkgPath << "]");
-                       this->m_db->insertWorst(pkgId, pkgPath, riskiestPath);
+ Db::RowShPtr CsLogic::getWorseByPkgPath(const std::string &pkgPath, time_t since)
+ {
+       Db::RowShPtr worse;
+       for (auto &row : this->m_db->getDetectedByFilepathOnDir(pkgPath, since))
+               if (!worse || *worse < *row)
+                       worse = std::move(row);
  
-                       if (history->isIgnored)
-                               return CSR_ERROR_NONE;
+       return worse;
+ }
  
-                       malware.reset(new CsDetected());
-                       *malware = std::move(*riskiest);
-                       return this->handleAskUser(context, *malware);
+ CsLogic::ScanStage CsLogic::judgeScanStage(
+               const Db::RowShPtr &history,
+               const Db::RowShPtr &after,
+               const CsDetectedPtr &riskiest,
+               Db::RowShPtr &jWorse,
+               Db::RowShPtr &jHistory,
+               time_t since)
+ {
+       if (riskiest == nullptr) {
+               if (after) {
+                       INFO("no new detected. after case can be re-used.");
+                       jHistory = after;
+                       return ScanStage::HISTORY_RISKIEST;
+               } else if (history) {
+                       INFO("no new detected. after case is removed. clean-up history");
+                       this->m_db->deleteDetectedByNameOnPath(history->targetName);
+                       return ScanStage::NO_DETECTED;
+               } else {
+                       INFO("no new detected and no history.");
+                       return ScanStage::NO_DETECTED;
                }
-       } else if (history && !after && !riskiest) {
-               since = this->m_loader->getEngineLatestUpdateTime(engineContext.get());
-               auto rows = this->m_db->getDetectedByFilepathOnDir(pkgPath, since);
-               if (!rows.empty()) {
-                       INFO("worst case is deleted cascadingly and NO new detected and "
-                                "worse case exist on pkg[" << pkgPath << "]. insert it to worst.");
-                       Db::RowShPtr worse;
-                       for (auto &row : rows)
-                               if (!worse || *worse < *row)
-                                       worse = std::move(row);
-                       if (worse) {
-                               this->m_db->insertWorst(pkgId, pkgPath, worse->fileInAppPath);
-                               if (worse->isIgnored)
-                                       return CSR_ERROR_NONE;
-                               malware.reset(new CsDetected());
-                               *malware = std::move(*worse);
-                               return this->handleAskUser(context, *malware);
-                       }
+       } else if (after != nullptr) {
+               if (*after < *riskiest) {
+                       INFO("worst case is remained but the more worst newly detected.");
+                       return ScanStage::NEW_RISKIEST;
+               } else {
+                       INFO("worst case is remained and can be re-used.");
+                       jHistory = after;
+                       return ScanStage::HISTORY_RISKIEST;
                }
+       } else if (history != nullptr) {
  
-               INFO("worst case is deleted cascadingly and NO new detected and "
-                        "NO worse case. the pkg[" << pkgPath << "] is clean.");
-               this->m_db->deleteDetectedByNameOnPath(pkgPath);
-               return CSR_ERROR_NONE;
-       } else if (!history && riskiest) {
-               INFO("no history and new detected");
-               this->m_db->insertWorst(pkgId, pkgPath, riskiestPath);
+               jWorse = this->getWorseByPkgPath(history->targetName, since);
  
-               malware.reset(new CsDetected());
-               *malware = std::move(*riskiest);
-               return this->handleAskUser(context, *malware);
+               if (jWorse == nullptr) {
+                       INFO("No detected malware found in db...."
+                                "The only malware in package is changed/removed.");
+                       return ScanStage::NEW_RISKIEST;
+               } else {
+                       if (*jWorse < *riskiest) {
+                               if (*history < *riskiest) {
+                                       INFO("worst case is deleted. but newly detected"
+                                                " malware is more risky.");
+                                       return ScanStage::NEW_RISKIEST;
+                               } else {
+                                       INFO("riskiest case is worse than in db."
+                                                "but history is worse than riskiest.");
+                                       return ScanStage::NEW_RISKIEST_KEEP_FLAG;
+                               }
+                       } else {
+                               INFO("worse case in db is worse than riskiest.");
+                               return ScanStage::WORSE_RISKIEST;
+                       }
+               }
        } else {
-               DEBUG("no history and no new detected");
-               return CSR_ERROR_NONE;
+               INFO("no history and no after case. insert newly detected");
+               return ScanStage::NEW_RISKIEST;
        }
  }
  
@@@ -59,15 -58,37 +61,33 @@@ public
        RawBuffer getIgnoredList(const StrSet &dirSet);
  
  private:
 -      RawBuffer scanApp(const CsContext &context, const std::string &pkgPath);
 -      RawBuffer scanAppOnCloud(const CsContext &context, const std::string &pkgPath,
 -                                                       const std::string &pkgId);
 -      Db::Cache scanAppDelta(const std::string &pkgPath, const std::string &pkgId);
 -
 -      RawBuffer scanFileWithoutDelta(const CsContext &context, const std::string &filepath,
 -                                                                 FilePtr &&fileptr);
 +      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);
++      Db::Cache scanAppDelta(const FilePtr &pkgPtr, const CancelChecker &isCancelled = nullptr);
 +      int scanAppOnCloud(const CsContext &context, const FilePtr &pkgPtr, CsDetectedPtr &malware);
-       CsDetectedPtr scanAppDelta(const FilePtr &pkgPtr, std::string &riskiestPath, const CancelChecker &isCancelled = nullptr);
  
 -      CsDetected convert(csre_cs_detected_h &result, const std::string &targetName,
 +      CsDetectedPtr convert(csre_cs_detected_h &result, const std::string &targetName,
                                           time_t timestamp);
 -      RawBuffer handleAskUser(const CsContext &c, CsDetected &d,
 -                                                      FilePtr &&fileptr = nullptr);
 +      int handleAskUser(const CsContext &c, CsDetected &d, const FilePtr &fileptr = nullptr);
  
+       Db::RowShPtr getWorseByPkgPath(const std::string &pkgPath, time_t since);
+       enum class ScanStage : int {
+               NEW_RISKIEST           = 0x1001,
+               NEW_RISKIEST_KEEP_FLAG = 0x1002,
+               HISTORY_RISKIEST       = 0x1003,
+               WORSE_RISKIEST         = 0x1004,
+               NO_DETECTED            = 0x1005
+       };
+       CsLogic::ScanStage judgeScanStage(
+                       const Db::RowShPtr &history,
+                       const Db::RowShPtr &after,
+                       const CsDetectedPtr &riskiest,
+                       Db::RowShPtr &jWorse,
+                       Db::RowShPtr &jHistory,
+                       time_t since);
        std::shared_ptr<CsLoader> m_loader;
        std::shared_ptr<Db::Manager> m_db;
  
@@@ -221,4 -241,49 +241,49 @@@ BOOST_AUTO_TEST_CASE(detected_malware_f
        EXCEPTION_GUARD_END
  }
  
 -              db.insertDetectedFile(d.targetName, d, dataVersion);
+ BOOST_AUTO_TEST_CASE(transaction_time)
+ {
+       EXCEPTION_GUARD_START
+       Db::Manager db(TEST_DB_FILE, TEST_DB_SCRIPTS);
+       const int testSize = 500;
+       std::string dataVersion = "1.0.0";
+       // select test with vacant data
+       auto detectedList = db.getDetectedAllByNameOnDir("/opt", 0);
+       ASSERT_IF(detectedList.empty(), true);
+       BOOST_MESSAGE("Start to time check about insert DB");
+       auto start = timeCheckStart();
+       db.transactionBegin();
+       for(int i = 0; i < testSize; i++) {
+               CsDetected d;
+               d.targetName = appendIdxToStr("/opt/transmalware", i);
+               d.severity = CSR_CS_SEVERITY_LOW;
+               d.malwareName = appendIdxToStr("transmalware", i);
+               d.detailedUrl = appendIdxToStr("http://detailed.transmalware", i);
+               d.ts = 100;
 -              db.insertDetectedFile(d.targetName, d, dataVersion);
++              db.insertDetectedFile(d, dataVersion);
+       }
+       db.transactionEnd();
+       timeCheckEnd(start);
+       BOOST_MESSAGE("Start to time check about insert DB");
+       auto start2 = timeCheckStart();
+       for(int i = 0; i < testSize; i++) {
+               CsDetected d;
+               d.targetName = appendIdxToStr("/opt/testmalware", i);
+               d.severity = CSR_CS_SEVERITY_LOW;
+               d.malwareName = appendIdxToStr("testmalware", i);
+               d.detailedUrl = appendIdxToStr("http://detailed.malware", i);
+               d.ts = 100;
++              db.insertDetectedFile(d, dataVersion);
+       }
+       timeCheckEnd(start2);
+       EXCEPTION_GUARD_END
+ }
  BOOST_AUTO_TEST_SUITE_END()