Don't return malware handle when the file removed 11/73911/1
authorKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 02:17:06 +0000 (11:17 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 04:46:30 +0000 (13:46 +0900)
Change-Id: I61aadc3b3a8db53bf57fedd131548429c51b2ac3
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/service/cs-logic.cpp
src/framework/service/file-system.cpp
test/test-api-content-screening.cpp
test/test-common.cpp
test/test-common.h
test/test-resource.h

index fe39c47..f8ca02d 100644 (file)
@@ -614,7 +614,17 @@ RawBuffer CsLogic::judgeStatus(const std::string &filepath, csr_cs_action_e acti
 
 RawBuffer CsLogic::getDetected(const std::string &filepath)
 {
-       auto row = this->m_db->getDetectedByNameOnPath(canonicalizePath(filepath, false));
+       std::string target;
+       try {
+               target = canonicalizePath(filepath, true);
+       } catch (const Exception &e) {
+               WARN("Ignore exceptions on file canonicalize/existence check for getting"
+                        " history e.g., detected/ignored. filepath: " << filepath);
+               this->m_db->deleteDetectedByNameOnPath(canonicalizePath(filepath, false));
+               return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+       }
+
+       auto row = this->m_db->getDetectedByNameOnPath(target);
 
        if (row && !row->isIgnored)
                return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
@@ -630,9 +640,15 @@ RawBuffer CsLogic::getDetectedList(const StrSet &_dirSet)
 
        Db::RowShPtrs rows;
        for (const auto &dir : dirSet) {
-               for (auto &row : this->m_db->getDetectedByNameOnDir(dir))
-                       if (!row->isIgnored)
+               for (auto &row : this->m_db->getDetectedByNameOnDir(dir)) {
+                       if (::access(row->targetName.c_str(), R_OK) != 0) {
+                               WARN("Exclude not-accessable malware detected file from the list: " <<
+                                        row->targetName);
+                               this->m_db->deleteDetectedByNameOnPath(row->targetName);
+                       } else if (!row->isIgnored) {
                                rows.emplace_back(std::move(row));
+                       }
+               }
        }
 
        if (rows.empty())
@@ -643,7 +659,17 @@ RawBuffer CsLogic::getDetectedList(const StrSet &_dirSet)
 
 RawBuffer CsLogic::getIgnored(const std::string &filepath)
 {
-       auto row = this->m_db->getDetectedByNameOnPath(canonicalizePath(filepath, false));
+       std::string target;
+       try {
+               target = canonicalizePath(filepath, true);
+       } catch (const Exception &e) {
+               WARN("Ignore exceptions on file canonicalize/existence check for getting"
+                        " history e.g., detected/ignored. filepath: " << filepath);
+               this->m_db->deleteDetectedByNameOnPath(canonicalizePath(filepath, false));
+               return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+       }
+
+       auto row = this->m_db->getDetectedByNameOnPath(target);
 
        if (row && row->isIgnored)
                return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
@@ -659,9 +685,15 @@ RawBuffer CsLogic::getIgnoredList(const StrSet &_dirSet)
 
        Db::RowShPtrs rows;
        for (const auto &dir : dirSet) {
-               for (auto &row : this->m_db->getDetectedByNameOnDir(dir))
-                       if (row->isIgnored)
+               for (auto &row : this->m_db->getDetectedByNameOnDir(dir)) {
+                       if (::access(row->targetName.c_str(), R_OK) != 0) {
+                               WARN("Exclude not-accessable malware detected file from the list: " <<
+                                        row->targetName);
+                               this->m_db->deleteDetectedByNameOnPath(row->targetName);
+                       } else if (row->isIgnored) {
                                rows.emplace_back(std::move(row));
+                       }
+               }
        }
 
        if (rows.empty())
index 0ec478e..29be70e 100644 (file)
@@ -222,7 +222,8 @@ void File::remove() const
        } else {
                DEBUG("remove file: " << this->m_path);
                if (::remove(this->m_path.c_str()) != 0)
-                       ThrowExc(CSR_ERROR_REMOVE_FAILED, "Failed to remove file: " << this->m_path);
+                       ThrowExc(CSR_ERROR_REMOVE_FAILED,
+                                        "Failed to remove file: " << this->m_path << " with errno: " << errno);
        }
 }
 
index a6e7faa..0040c20 100644 (file)
 #include "test-helper.h"
 #include "test-resource.h"
 
+namespace {
+
+void assertMalwareInList(csr_cs_malware_list_h list, size_t count, const std::string &filepath)
+{
+       csr_cs_malware_h malware;
+       for (size_t i = 0; i < count; i++) {
+               ASSERT_SUCCESS(csr_cs_malware_list_get_malware(list, i, &malware));
+               CHECK_IS_NOT_NULL(malware);
+
+               Test::ScopedCstr filepath_cstr;
+               ASSERT_SUCCESS(csr_cs_malware_get_file_name(malware, &filepath_cstr.ptr));
+               if (filepath == filepath_cstr.ptr)
+                       return;
+       }
+
+       BOOST_REQUIRE_MESSAGE(false, "malware on file[" << filepath << " is not exist "
+                                                 "in the list");
+}
+
+void assertMalwareNotInList(csr_cs_malware_list_h list, size_t count, const std::string &filepath)
+{
+       csr_cs_malware_h malware;
+       for (size_t i = 0; i < count; i++) {
+               ASSERT_SUCCESS(csr_cs_malware_list_get_malware(list, i, &malware));
+               CHECK_IS_NOT_NULL(malware);
+
+               Test::ScopedCstr filepath_cstr;
+               ASSERT_SUCCESS(csr_cs_malware_get_file_name(malware, &filepath_cstr.ptr));
+               if (filepath == filepath_cstr.ptr)
+                       BOOST_REQUIRE_MESSAGE(false, "malware on file[" << filepath << " is exist "
+                                                                 "in the list");
+       }
+
+}
+
+} // namespace anonymous
+
 BOOST_AUTO_TEST_SUITE(API_CONTENT_SCREENING)
 
 BOOST_AUTO_TEST_CASE(context_create_destroy)
@@ -966,4 +1003,293 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_invalid_params)
        EXCEPTION_GUARD_END
 }
 
+BOOST_AUTO_TEST_CASE(get_malware_after_file_removed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       csr_cs_malware_h malware_stored;
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       Test::remove_file_assert(TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NULL(malware_stored);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_malwares_after_file_removed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP_IN_DIR_MALWARES, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       const char *dirs[2] = {
+               TEST_DIR_TMP,
+               TEST_DIR_MALWARES
+       };
+
+       csr_cs_malware_list_h malware_list;
+       size_t list_count;
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       Test::remove_file_assert(TEST_FILE_TMP);
+       Test::remove_file_assert(TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareNotInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareNotInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_malware_after_file_changed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       csr_cs_malware_h malware_stored;
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       Test::touch_file_assert(TEST_FILE_TMP);
+
+       malware_stored = nullptr;
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       Test::remove_file(TEST_FILE_TMP);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_malwares_after_file_changed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP_IN_DIR_MALWARES, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       const char *dirs[2] = {
+               TEST_DIR_TMP,
+               TEST_DIR_MALWARES
+       };
+
+       csr_cs_malware_list_h malware_list;
+       size_t list_count;
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       Test::touch_file_assert(TEST_FILE_TMP);
+       Test::touch_file_assert(TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+       Test::remove_file(TEST_FILE_TMP);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_ignored_malware_after_file_removed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       csr_cs_malware_h malware_stored;
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_stored, CSR_CS_ACTION_IGNORE));
+
+       Test::remove_file_assert(TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NULL(malware_stored);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_ignored_malwares_after_file_removed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       csr_cs_malware_h malware_tmp[2];
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware_tmp[0]));
+       CHECK_IS_NOT_NULL(malware_tmp[0]);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP_IN_DIR_MALWARES, &malware_tmp[1]));
+       CHECK_IS_NOT_NULL(malware_tmp[1]);
+
+       const char *dirs[2] = {
+               TEST_DIR_TMP,
+               TEST_DIR_MALWARES
+       };
+
+       csr_cs_malware_list_h malware_list;
+       size_t list_count;
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[0], CSR_CS_ACTION_IGNORE));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[1], CSR_CS_ACTION_IGNORE));
+
+       Test::remove_file_assert(TEST_FILE_TMP);
+       Test::remove_file_assert(TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_get_ignored_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareNotInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareNotInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_ignored_malware_after_file_changed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+       csr_cs_malware_h malware;
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware));
+       CHECK_IS_NOT_NULL(malware);
+
+       csr_cs_malware_h malware_stored;
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_stored, CSR_CS_ACTION_IGNORE));
+
+       Test::touch_file_assert(TEST_FILE_TMP);
+
+       malware_stored = nullptr;
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_TMP, &malware_stored));
+       CHECK_IS_NOT_NULL(malware_stored);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_stored, CSR_CS_ACTION_UNIGNORE));
+
+       Test::remove_file(TEST_FILE_TMP);
+
+       EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_ignored_malwares_after_file_changed)
+{
+       EXCEPTION_GUARD_START
+
+       auto c = Test::Context<csr_cs_context_h>();
+       auto context = c.get();
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP);
+       Test::copy_file_assert(TEST_FILE_HIGH, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       csr_cs_malware_h malware_tmp[2];
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &malware_tmp[0]));
+       CHECK_IS_NOT_NULL(malware_tmp[0]);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP_IN_DIR_MALWARES, &malware_tmp[1]));
+       CHECK_IS_NOT_NULL(malware_tmp[1]);
+
+       const char *dirs[2] = {
+               TEST_DIR_TMP,
+               TEST_DIR_MALWARES
+       };
+
+       csr_cs_malware_list_h malware_list;
+       size_t list_count;
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[0], CSR_CS_ACTION_IGNORE));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[1], CSR_CS_ACTION_IGNORE));
+
+       Test::touch_file_assert(TEST_FILE_TMP);
+       Test::touch_file_assert(TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_get_ignored_malwares(context, dirs, 2, &malware_list, &list_count));
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP);
+       ::assertMalwareInList(malware_list, list_count, TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[0], CSR_CS_ACTION_UNIGNORE));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, malware_tmp[1], CSR_CS_ACTION_UNIGNORE));
+
+       Test::remove_file(TEST_FILE_TMP);
+       Test::remove_file(TEST_FILE_TMP_IN_DIR_MALWARES);
+
+       EXCEPTION_GUARD_END
+}
+
 BOOST_AUTO_TEST_SUITE_END()
index adb44ce..a397a09 100644 (file)
@@ -24,6 +24,7 @@
 #include <iostream>
 #include <fstream>
 #include <functional>
+#include <cerrno>
 #include <unistd.h>
 #include <utime.h>
 #include <sys/types.h>
@@ -309,37 +310,89 @@ void exceptionGuard(const std::function<void()> &f)
        }
 }
 
+void copy_file_assert(const char *src_file, const char *dest_file)
+{
+       try {
+               std::ifstream srce(src_file, std::ios::binary);
+               std::ofstream dest(dest_file, std::ios::binary);
+               dest << srce.rdbuf();
+       } catch (const std::exception &e) {
+               BOOST_REQUIRE_MESSAGE(false,
+                       "Failed to copy file from src[" << src_file <<
+                       "] to dst[" << dest_file << "]: " << e.what());
+       }
+}
+
 void copy_file(const char *src_file, const char *dest_file)
 {
-       std::ifstream srce(src_file, std::ios::binary);
-       std::ofstream dest(dest_file, std::ios::binary);
-       dest << srce.rdbuf();
+       try {
+               std::ifstream srce(src_file, std::ios::binary);
+               std::ofstream dest(dest_file, std::ios::binary);
+               dest << srce.rdbuf();
+       } catch (const std::exception &e) {
+               BOOST_WARN_MESSAGE(false,
+                       "Failed to copy file from src[" << src_file <<
+                       "] to dst[" << dest_file << "]: " << e.what());
+       }
+}
+
+void make_dir_assert(const char *dir)
+{
+       BOOST_REQUIRE_MESSAGE(
+               ::mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0,
+               "Failed to mkdir[" << dir << "] with errno: " << errno);
 }
 
 void make_dir(const char *dir)
 {
-       mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+       BOOST_WARN_MESSAGE(
+               ::mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0,
+               "Failed to mkdir[" << dir << "] with errno: " << errno);
+}
+
+void touch_file_assert(const char *file)
+{
+       struct utimbuf new_times;
+       time_t now = ::time(nullptr);
+
+       new_times.actime = now;
+       new_times.modtime = now;
+
+       BOOST_REQUIRE_MESSAGE(
+               ::utime(file, &new_times) == 0,
+               "utime() to touch file[" << file << "] failed with errno: " << errno);
 }
 
 void touch_file(const char *file)
 {
        struct utimbuf new_times;
-       time_t now = time(nullptr);
+       time_t now = ::time(nullptr);
 
        new_times.actime = now;
        new_times.modtime = now;
 
-       utime(file, &new_times);
+       BOOST_WARN_MESSAGE(
+               ::utime(file, &new_times) == 0,
+               "utime() to touch file[" << file << "] failed with errno: " << errno);
+}
+
+void remove_file_assert(const char *file)
+{
+       BOOST_REQUIRE_MESSAGE(
+               ::unlink(file) == 0,
+               "unlink file[" << file << " failed with errno: " << errno);
 }
 
 void remove_file(const char *file)
 {
-       unlink(file);
+       BOOST_WARN_MESSAGE(
+               ::unlink(file) == 0,
+               "unlink file[" << file << " failed with errno: " << errno);
 }
 
 bool is_file_exist(const char *file)
 {
-       return (access(file, F_OK) != -1);
+       return ::access(file, F_OK) != -1;
 }
 
 bool uninstall_app(const char *pkg_id)
index 8e83223..d49819e 100644 (file)
@@ -183,9 +183,13 @@ void _assert<char *, std::string>(char * const &value,
 void exceptionGuard(const std::function<void()> &);
 
 void make_dir(const char *dir);
+void make_dir_assert(const char *dir);
 void copy_file(const char *src_file, const char *dest_file);
+void copy_file_assert(const char *src_file, const char *dest_file);
 void touch_file(const char *file);
+void touch_file_assert(const char *file);
 void remove_file(const char *file);
+void remove_file_assert(const char *file);
 bool is_file_exist(const char *file);
 bool install_app(const char *app_path, const char *app_type);
 bool uninstall_app(const char *pkg_id);
index 26e6a37..4583bc4 100644 (file)
 #define TEST_DIR_TMP       "/tmp"
 #define TEST_DIR_APPS      "/opt/usr/apps"
 
-#define TEST_FILE_MEDIA    TEST_DIR_MEDIA "/test_malware_file"
-#define TEST_FILE_TMP      TEST_DIR_TMP "/test_malware_file"
-#define TEST_FILE_NO_EXIST TEST_DIR_TMP "/not_existing_file"
+#define TEST_FILE_MEDIA               TEST_DIR_MEDIA "/test_malware_file"
+#define TEST_FILE_TMP_IN_DIR_MALWARES TEST_DIR_MALWARES "/tmp_malware_file"
+#define TEST_FILE_TMP                 TEST_DIR_TMP "/test_malware_file"
+#define TEST_FILE_NO_EXIST            TEST_DIR_TMP "/not_existing_file"
 
 #define TEST_WGT_PKG_ID    "hFhcNcbE6K"
 #define TEST_WGT_TYPE      "wgt"