tool: hal-compatibility-checker: Fix --skip-if-result-exist to work 03/313203/1
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 20 Jun 2024 03:55:32 +0000 (12:55 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 20 Jun 2024 05:16:17 +0000 (14:16 +0900)
To prevent checking repeatedly for every booting, the option skips
checking if there was result file.

Change-Id: If55a3a59c12765591e33c5c2899028af86452907
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
tools/hal-compatibility-checker/main.c

index 679913c13899f8cb1967c5fac3a5c8e1123a5f59..bb89e2266011bc5f1c9e6c4cb160cf41177d15ca 100644 (file)
@@ -28,8 +28,9 @@
 #include <dlog/dlog.h>
 #include <hal-common.h>
 
-#define DEFAULT_PLATFORM_MANIFEST_DIR          "/etc/hal"
+#define DEFAULT_PLATFORM_MANIFEST_DIR                  "/etc/hal"
 #define DEFAULT_HAL_INFO_INI                           "/hal/etc/hal-info.ini"
+#define DEFAULT_HAL_BACKEND_COMPATIBILITY_PATH         "/opt/etc/hal/.hal-backend-compatibility"
 
 #define HCC_BUF_MAX            (256)
 #define BOLD(STR)      "\e[1m"STR"\e[m"
@@ -87,11 +88,9 @@ static int get_tizen_hal_version(int *major, int *minor)
        return found ? 0 : -EINVAL;
 }
 
-// check result is exist, return true on exist.
-static bool result_exist(const char *dir)
+static bool result_exist(const char *path)
 {
-       // check result exists based on the directory 'dir'.
-       return false;
+       return (access(path, F_OK) == 0);
 }
 
 static void show_help(void)
@@ -106,9 +105,9 @@ static void show_help(void)
                "\t-h, --help\n"
                "\t\tshow this help.\n"
                "\n"
-               "\t--skip-if-result-exist[=DIRECTORY]\n"
+               "\t--skip-if-result-exist[=FILE]\n"
                "\t\tskip compatibility check if there exists a result of compatibility.\n"
-               "\t\tif DIRECTORY is given, locate a result based on the given DIRECTORY.\n"
+               "\t\tif FILE is given, locate a result based on the given FILE.\n"
                "\n"
                "\t--reset\n"
                "\t\tremove the existing result file.\n"
@@ -122,7 +121,7 @@ int main(int argc, char *argv[])
        int index;
        bool skip_if_result_exist = false;
        bool reset_file = false;
-       const char *skip_if_result_exist_dir = NULL;
+       const char *skip_if_result_exist_path = NULL;
        const char *platform_manifest_dir = NULL;
 
        for (;;) {
@@ -139,7 +138,7 @@ int main(int argc, char *argv[])
                        switch (index) {
                        case OPT_SKIP_IF_RESULT_EXIST:
                                skip_if_result_exist = true;
-                               skip_if_result_exist_dir = optarg;
+                               skip_if_result_exist_path = optarg ? : DEFAULT_HAL_BACKEND_COMPATIBILITY_PATH;
                                break;
                        case OPT_RESET:
                                reset_file = true;
@@ -160,13 +159,14 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       if (skip_if_result_exist && result_exist(skip_if_result_exist_dir)) {
-               printf("hal-compatibility-checker: skip checking\n");
+       if (reset_file) {
+               unlink(DEFAULT_HAL_BACKEND_COMPATIBILITY_PATH);
                return 0;
        }
 
-       if (reset_file) {
-               unlink("/opt/etc/hal/.hal-backend-compatibility");
+       if (skip_if_result_exist && result_exist(skip_if_result_exist_path)) {
+               dlog_print(DLOG_DEBUG, LOG_TAG_HAL_COMPATIBILITY_CHECKER,
+                       "hal-compatibility-checker: skip checking\n");
                return 0;
        }