fix coding styles and change keyword 'entry' to more readable one. 15/61315/7
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 7 Mar 2016 08:48:48 +0000 (17:48 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 14 Mar 2016 06:28:50 +0000 (15:28 +0900)
Change-Id: I7603251b6fce3881aec3ad379e6e565e956ce283
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
CMakeLists.txt
src/delta.c
src/delta.h
src/install_preload_tpk.c
src/pkg_clearcache.c
src/pkg_cmd.c
src/pkg_getsize.c
src/pkg_info.c
src/pkg_initdb.c

index 44cef0b018ef76801f53ed3c487a4b71a3071467..bb688e6cb9039e2ca272ecdb1116859c4181dfd6 100644 (file)
@@ -37,7 +37,7 @@ ENDFOREACH(flag)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -pie" )
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE")
 SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE")
index dba2a2708fc83ae9ec1996728634a8dd8dd9c8ba..a71a212186de7ddc19380a4e5f64636442e69490 100644 (file)
 #include <sys/wait.h>
 #include "delta.h"
 
-static GList * __list_directory(const char * dir_name, const char * tpk_path, GList * list);
-static int __compare_files(char * path1, char * path2);
-static void __print_to_file(charmsg);
-static void __free_g_list(GList * list);
+static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list);
+static int __compare_files(char *path1, char *path2);
+static void __print_to_file(char *msg);
+static void __free_g_list(GList *list);
 
-static void __free_g_list(GList * list)
+static void __free_g_list(GList *list)
 {
-       GList * iter = NULL;
-       for (iter = list; iter != NULL; iter = iter->next)
-       {
+       GList *iter = NULL;
+
+       for (iter = list; iter != NULL; iter = iter->next) {
                if (iter->data)
                        free(iter->data);
        }
        g_list_free(list);
+
        return;
 }
 
-static GList * __list_directory (const char * dir_name, const char * tpk_path, GList * list)
+static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list)
 {
-        DIR *dir = NULL;
-        struct dirent entry, *result;
-        int flag = 0;
-        char path[PATH_MAX] = {0, };
-        char rel_path_old_tpk_file[PATH_MAX] = {0, };
-        char *file_path = NULL;
-        char buf[BUF_SIZE] = {0};
-
-        dir = opendir(dir_name);
-        if (!dir)
-        {
-                if (strerror_r(errno, buf, sizeof(buf)) == 0) {
-                        printf ("Cannot open directory '%s': %s\n", dir_name, buf);
-                }
-                exit (EXIT_FAILURE);
-        }
-        while (1)
-        {
-                const char * d_name = NULL;
-                int ret = 0;
-                ret = readdir_r(dir, &entry, &result); /* "Readdir" gets subsequent entries from "d". */
-                if (ret != 0 || result == NULL)/* There are no more entries in this directory, so break out of the while loop. */
-                {
-                        flag++;
-                        break;
-                }
-                d_name = entry.d_name;
-                if (!(entry.d_type & DT_DIR))
-                {
-                        snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name);
-                        strncpy(path, rel_path_old_tpk_file+strlen(tpk_path), strlen(rel_path_old_tpk_file));
-                        file_path = strndup(path, sizeof(path));
-                        list = g_list_append(list, file_path);
-                        memset(path, 0, PATH_MAX);
-                        memset(rel_path_old_tpk_file, 0, PATH_MAX);
-
-                }
-
-                if (entry.d_type & DT_DIR)                      /* Check that the directory is not "d" or d's parent. */
-                {
-                        if (strcmp(d_name, "..") != 0 && strcmp (d_name, ".") != 0)
-                        {
-                                int path_length;
-                                path_length = snprintf (path, PATH_MAX, "%s/%s", dir_name, d_name);
-                                if (path_length >= PATH_MAX)
-                                {
-                                        printf("Path length has got too long.\n");
-                                        exit(EXIT_FAILURE);
-                                }
-                                list = __list_directory (path, tpk_path, list);
-                                memset(path, 0, PATH_MAX);/* Recursively call "list_dir" with the new path. */
-                        }
-                }
-        }
-        if(flag == 1)
-        {
-                snprintf (rel_path_old_tpk_file, PATH_MAX, "%s/", dir_name);
-                strncpy(path, rel_path_old_tpk_file+strlen(tpk_path), strlen(rel_path_old_tpk_file));
-                file_path = strndup(path, sizeof(path));
-                list = g_list_prepend(list, file_path);
-                memset(path, 0, PATH_MAX);
-                memset(rel_path_old_tpk_file, 0, PATH_MAX);
-        }
-        if (closedir(dir))
-        {
-                if (strerror_r(errno, buf, sizeof(buf)) == 0) {
-                        printf("Could not close '%s': %s\n", dir_name, buf);
-                }
-                exit(EXIT_FAILURE);
-        }
-        return list;
+       DIR *dir = NULL;
+       struct dirent file_info;
+       struct dirent *result;
+       int flag = 0;
+       char path[PATH_MAX] = {0, };
+       char rel_path_old_tpk_file[PATH_MAX] = {0, };
+       char *file_path = NULL;
+       char buf[BUF_SIZE] = {0};
+       const char *d_name = NULL;
+       int ret = 0;
+       int path_length;
+
+       dir = opendir(dir_name);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       printf("Cannot open directory '%s': %s\n", dir_name, buf);
+               exit(EXIT_FAILURE);
+       }
+
+       while (1) {
+               ret = readdir_r(dir, &file_info, &result);
+               if (ret != 0 || result == NULL) {
+                       flag++;
+                       break;
+               }
+
+               d_name = file_info.d_name;
+               if (!(file_info.d_type & DT_DIR)) {
+                       snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name);
+                       strncpy(path, rel_path_old_tpk_file + strlen(tpk_path),
+                                       strlen(rel_path_old_tpk_file));
+                       file_path = strndup(path, sizeof(path));
+                       list = g_list_append(list, file_path);
+                       memset(path, 0, PATH_MAX);
+                       memset(rel_path_old_tpk_file, 0, PATH_MAX);
+               }
+
+               if (file_info.d_type & DT_DIR) {
+                       if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) {
+                               path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name);
+                               if (path_length >= PATH_MAX) {
+                                       printf("Path length has got too long.\n");
+                                       exit(EXIT_FAILURE);
+                               }
+                               list = __list_directory(path, tpk_path, list);
+                               memset(path, 0, PATH_MAX);
+                       }
+               }
+       }
+
+       if (flag == 1) {
+               snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/", dir_name);
+               strncpy(path, rel_path_old_tpk_file+strlen(tpk_path),
+                               strlen(rel_path_old_tpk_file));
+               file_path = strndup(path, sizeof(path));
+               list = g_list_prepend(list, file_path);
+       }
+
+       if (closedir(dir)) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       printf("Could not close '%s': %s\n", dir_name, buf);
+               exit(EXIT_FAILURE);
+       }
+
+       return list;
 }
 
-static char * __create_md5Hash(char * file_name)
+static char *__create_md5Hash(char *file_name)
 {
-       FILE *inFile = fopen (file_name, "rb");
+       FILE *inFile = fopen(file_name, "rb");
        unsigned char data[1024] = {0, };
        int bytes = 0;
 
@@ -143,14 +138,12 @@ static char * __create_md5Hash(char * file_name)
                return 0;
        }
 
-       while ((bytes = fread(data, 1, 1024, inFile)) != 0) {
+       while ((bytes = fread(data, 1, 1024, inFile)) != 0)
                g_checksum_update(checksum, (const guchar *)data, bytes);
-       }
 
        checksum_val = (char *)g_checksum_get_string(checksum);
-       if (checksum_val) {
+       if (checksum_val)
                return_val = strdup(checksum_val);
-       }
 
        g_checksum_free(checksum);
        fclose(inFile);
@@ -158,190 +151,204 @@ static char * __create_md5Hash(char * file_name)
        return return_val;
 }
 
-static int __compare_files(char * old_file, char * new_file)
+static int __compare_files(char *old_file, char *new_file)
 {
        char *md5_old_file = NULL;
        char *md5_new_file = NULL;
+
        md5_old_file = __create_md5Hash(old_file);
-       if(md5_old_file == NULL)
-       {
-               printf("md5checksum failed for %s.\n", old_file );
+       if (md5_old_file == NULL) {
+               printf("md5checksum failed for %s.\n", old_file);
                exit(EXIT_FAILURE);
        }
+
        md5_new_file = __create_md5Hash(new_file);
-       if(md5_new_file == NULL)
-       {
-                printf("md5checksum failed for %s.\n", new_file );
+       if (md5_new_file == NULL) {
+                printf("md5checksum failed for %s.\n", new_file);
                 exit(EXIT_FAILURE);
        }
-       if(strcmp(md5_old_file, md5_new_file) == 0)
-       {
+
+       if (strcmp(md5_old_file, md5_new_file) == 0) {
                free(md5_old_file);
                free(md5_new_file);
                return 0;
-       }
-       else
-       {
+       } else {
                free(md5_old_file);
                free(md5_new_file);
                return 1;
        }
 }
 
-static void __print_to_file(charmsg)
+static void __print_to_file(char *msg)
 {
         FILE *fp;
+
         fp = fopen(DIFF_FILE, "a");
-        if (fp == NULL)
-        {
+
+        if (fp == NULL) {
                 printf("Cannot open %s for writing ", DIFF_FILE);
                 exit(1);
         }
+
         fprintf(fp, "%s \n", msg);
         memset(msg, 0, MAX_MESSAGE_LEN);
         fclose(fp);
 }
 
-void __create_diff_file(char * old_tpk_path, char * new_tpk_path)
+void __create_diff_file(char *old_tpk_path, char *new_tpk_path)
 {
-        char rel_path_old_tpk_file[PATH_MAX] = {0, }, rel_path_new_tpk_file[PATH_MAX] = {0, };
-        GList *list_dir_old_tpk = NULL, *list_dir_new_tpk = NULL, *iterator_old_tpk = NULL, *iterator_new_tpk = NULL, *next_iterator_old_tpk = NULL, *next_iterator_new_tpk = NULL;
-        int ret = -1;
-
-        list_dir_old_tpk = __list_directory (old_tpk_path, old_tpk_path, list_dir_old_tpk);
-        list_dir_new_tpk = __list_directory (new_tpk_path, new_tpk_path, list_dir_new_tpk);
-        if(list_dir_old_tpk == NULL)
-        {
-                printf("Could Not read %s\n", old_tpk_path);
-                return;
-        }
+       char rel_path_old_tpk_file[PATH_MAX] = {0, };
+       char rel_path_new_tpk_file[PATH_MAX] = {0, };
+       GList *list_dir_old_tpk = NULL;
+       GList *list_dir_new_tpk = NULL;
+       GList *iterator_old_tpk = NULL;
+       GList *iterator_new_tpk = NULL;
+       GList *next_iterator_old_tpk = NULL;
+       GList *next_iterator_new_tpk = NULL;
+       int ret = -1;
 
-        if(list_dir_new_tpk == NULL)
-        {
-                printf("Could Not read %s\n", new_tpk_path);
-                return;
-        }
+       list_dir_old_tpk = __list_directory(old_tpk_path, old_tpk_path, list_dir_old_tpk);
+       list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk);
+       if (list_dir_old_tpk == NULL) {
+               printf("Could Not read %s\n", old_tpk_path);
+               return;
+       }
 
-        iterator_old_tpk = list_dir_old_tpk;
-        iterator_new_tpk = list_dir_new_tpk;
+       if (list_dir_new_tpk == NULL) {
+               printf("Could Not read %s\n", new_tpk_path);
+               return;
+       }
+
+       iterator_old_tpk = list_dir_old_tpk;
+       iterator_new_tpk = list_dir_new_tpk;
 
-       while(iterator_old_tpk != NULL)
-       {
+       while (iterator_old_tpk != NULL) {
                next_iterator_old_tpk = iterator_old_tpk->next;
 
                iterator_new_tpk = list_dir_new_tpk;
-               while(iterator_new_tpk != NULL)
-                {
+               while (iterator_new_tpk != NULL) {
                        next_iterator_new_tpk = iterator_new_tpk->next;
 
-                        if(strcmp((char *)iterator_old_tpk->data, (char *)iterator_new_tpk->data) == 0)
-                        {
-                                snprintf(rel_path_old_tpk_file, PATH_MAX,"%s%s", old_tpk_path,(char *)iterator_old_tpk->data);
-                                snprintf(rel_path_new_tpk_file, PATH_MAX,"%s%s", new_tpk_path,(char *)iterator_new_tpk->data);
-                                ret = 0;
-                                if(rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1] != '/')
-                                {
-                                        ret = __compare_files(rel_path_old_tpk_file, rel_path_new_tpk_file);
-                                        if (ret == 1)
-                                        {
-                                                snprintf(message, MAX_MESSAGE_LEN, "Files %s and %s differ", rel_path_old_tpk_file, rel_path_new_tpk_file);
-                                                __print_to_file(message);
-                                        }
-                                }
-                                list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk);
-                                list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk, iterator_old_tpk);
-                                iterator_new_tpk = next_iterator_new_tpk;
-                                iterator_old_tpk = next_iterator_old_tpk;
-                                break;
-                        }
-                        iterator_new_tpk = next_iterator_new_tpk;
-                }
-                iterator_old_tpk = next_iterator_old_tpk;
-        }
+                       if (strcmp((char *)iterator_old_tpk->data,
+                                       (char *)iterator_new_tpk->data) == 0) {
+                               snprintf(rel_path_old_tpk_file, PATH_MAX, "%s%s", old_tpk_path,
+                                               (char *)iterator_old_tpk->data);
+                               snprintf(rel_path_new_tpk_file, PATH_MAX, "%s%s", new_tpk_path,
+                                               (char *)iterator_new_tpk->data);
+                               ret = 0;
+                               if (rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1]
+                                               != '/') {
+                                       ret = __compare_files(rel_path_old_tpk_file,
+                                                       rel_path_new_tpk_file);
+                                       if (ret == 1) {
+                                               snprintf(message, MAX_MESSAGE_LEN,
+                                                               "Files %s and %s differ",
+                                                               rel_path_old_tpk_file,
+                                                               rel_path_new_tpk_file);
+                                               __print_to_file(message);
+                                       }
+                               }
+                               list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+                                               iterator_new_tpk);
+                               list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk,
+                                               iterator_old_tpk);
+                               iterator_new_tpk = next_iterator_new_tpk;
+                               iterator_old_tpk = next_iterator_old_tpk;
+                               break;
+                       }
+                       iterator_new_tpk = next_iterator_new_tpk;
+               }
+               iterator_old_tpk = next_iterator_old_tpk;
+       }
 
-       //find if new file or new directory
+       /* find if new file or new directory */
        iterator_old_tpk = list_dir_old_tpk;
-       while(iterator_old_tpk != NULL)
-       {
+       while (iterator_old_tpk != NULL) {
                iterator_new_tpk = iterator_old_tpk->next;
-               while(iterator_new_tpk != NULL)
-               {
+               while (iterator_new_tpk != NULL) {
                        next_iterator_new_tpk = iterator_new_tpk->next;
                        if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
-                               list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk);
+                               list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+                                               iterator_new_tpk);
                        iterator_new_tpk = next_iterator_new_tpk;
                }
                iterator_old_tpk = iterator_old_tpk->next;
        }
 
        iterator_old_tpk = list_dir_new_tpk;
-       while(iterator_old_tpk != NULL)
-       {
+       while (iterator_old_tpk != NULL) {
                iterator_new_tpk = iterator_old_tpk->next;
-               while(iterator_new_tpk != NULL)
-               {
+               while (iterator_new_tpk != NULL) {
                        next_iterator_new_tpk = iterator_new_tpk->next;
                        if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
-                               list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk);
+                               list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+                                               iterator_new_tpk);
                        iterator_new_tpk = next_iterator_new_tpk;
                }
                iterator_old_tpk = iterator_old_tpk->next;
        }
 
        iterator_old_tpk = list_dir_old_tpk;
-       while(iterator_old_tpk != NULL)
-       {
-               snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path, (char *)iterator_old_tpk->data);
+       while (iterator_old_tpk != NULL) {
+               snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path,
+                               (char *)iterator_old_tpk->data);
                __print_to_file(message);
                iterator_old_tpk = iterator_old_tpk->next;
        }
+
        iterator_new_tpk = list_dir_new_tpk;
-       while(iterator_new_tpk != NULL)
-       {
-               snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path, (char *)iterator_new_tpk->data);
+       while (iterator_new_tpk != NULL) {
+               snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path,
+                               (char *)iterator_new_tpk->data);
                __print_to_file(message);
                iterator_new_tpk = iterator_new_tpk->next;
        }
 
-       /*to free GSList*/
+       /* to free GSList */
        __free_g_list(list_dir_old_tpk);
        __free_g_list(list_dir_new_tpk);
 }
 
 int __xsystem(const char *argv[])
 {
-     int status = 0;
-     pid_t pid;
-     pid = fork();
-     switch (pid) {
-     case -1:
-             perror("fork failed");
-             return -1;
-     case 0:
-             /* child */
-             if (execvp(argv[0], (char *const *)argv) < 0) {
-                                char buf[BUF_SIZE] = {0};
-                                if (strerror_r(errno, buf, sizeof(buf)) == 0) {
-                                        fprintf(stderr, "execvp failed %d....%s\n", errno, buf);    /*Don't use d_msg_app2sd */
-                                }
-             }
-             _exit(-1);
-     default:
-             /* parent */
-             break;
-     }
-     if (waitpid(pid, &status, 0) == -1) {
-             perror("waitpid failed");
-             return -1;
-     }
-     if (WIFSIGNALED(status)) {
-             perror("signal");
-             return -1;
-     }
-     if (!WIFEXITED(status)) {
-             /* shouldn't happen */
-             perror("should not happen");
-             return -1;
-     }
-     return WEXITSTATUS(status);
+       char buf[BUF_SIZE] = {0};
+       int status = 0;
+       pid_t pid;
+
+       pid = fork();
+
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               if (execvp(argv[0], (char *const *)argv) < 0) {
+                       if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                               fprintf(stderr, "execvp failed %d....%s\n", errno, buf);
+               }
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+
+       return WEXITSTATUS(status);
 }
+
index 699a937371a8e4ccbae8d47bcd14098f6dc479ff..4d1d171c80f6aa9a08ef6aa2bf679460a4c86f6f 100644 (file)
 #ifndef DELTA_H_
 #define DELTA_H_
 
-#define DIFF_FILE                      "/opt/usr/temp_delta/difffile.txt"
-#define TEMP_DELTA_REPO                "/opt/usr/temp_delta/"
-#define UNZIPFILE                      "_FILES"
-#define MAX_MESSAGE_LEN 1024
-#define BUF_SIZE 1024
+#define DIFF_FILE              "/opt/usr/temp_delta/difffile.txt"
+#define TEMP_DELTA_REPO                "/opt/usr/temp_delta/"
+#define UNZIPFILE              "_FILES"
+#define MAX_MESSAGE_LEN        1024
+#define BUF_SIZE       1024
 char message[MAX_MESSAGE_LEN];
 
-void __create_diff_file(char * old_tpk_path, char * new_tpk_path);
+void __create_diff_file(char *old_tpk_path, char *new_tpk_path);
 int __xsystem(const char *argv[]);
 
 #endif /* DELTA_H_ */
index e9d7e7be1cce11a48fd588129066df9e42c5a126..3694f6be6c63d86938d2af3e848a8977bba6bf8d 100644 (file)
@@ -78,7 +78,7 @@ static int _install_preload_tpk(uid_t uid, const char *directory)
                                return -1;
                        }
                        execl(BACKEND_CMD, BACKEND_CMD, "-i", buf, "--preload",
-                             (char*)NULL);
+                             (char *)NULL);
                } else if (pid < 0) {
                        _E("failed to fork and execute %s!", BACKEND_CMD);
                        closedir(dir);
index ee8e593a90909e85c7c619aa10382d27c0b8de30..14181e2efe05b536a21c7a5df2e54c30d6e243bf 100644 (file)
@@ -119,12 +119,12 @@ static int __clear_cache_dir(const char *pkgid)
        int ret = 0;
        char dirname[PATH_MAX] = {0,};
 
-       if(pkgid == NULL) {
+       if (pkgid == NULL) {
                LOGE("pkgid is NULL\n");
                return -1;
        }
 
-       // cache internal
+       /* cache internal */
        snprintf(dirname, sizeof(dirname), "%s/%s%s",
                        INTERNAL_CACHE_PATH_PREFIX, pkgid, CACHE_PATH_POSTFIX);
 
@@ -132,7 +132,7 @@ static int __clear_cache_dir(const char *pkgid)
        if (ret < 0)
                LOGE("Failed to clear internal cache dir.");
 
-       // shared/cache internal
+       /* shared/cache internal */
        snprintf(dirname, sizeof(dirname), "%s/%s%s",
                        INTERNAL_CACHE_PATH_PREFIX, pkgid, SHARED_PATH_POSTFIX);
 
@@ -158,7 +158,7 @@ static int __clear_all_cache_dir_cb(const pkgmgrinfo_pkginfo_h handle,
        }
 
        res = __clear_cache_dir(pkgid);
-       if (res != 0) { // error flag
+       if (res != 0) {
                LOGE("Failed to clear cache dir of %s", pkgid);
                --(*err_cnt);
                return 0;
index 154035389eeda1db3eebab83e3e3e6ba4fa60c10..1966d964f295f6d14487143cb20d62f0f81287b7 100644 (file)
@@ -158,7 +158,7 @@ static void __error_no_to_string(int errnumber, char **errstr)
        if (errstr == NULL)
                return;
        switch (errnumber) {
-        case PKGCMD_ERRCODE_UNZIP_ERROR:
+       case PKGCMD_ERRCODE_UNZIP_ERROR:
                *errstr = PKGCMD_ERRCODE_UNZIP_ERROR_STR;
                break;
        case PKGCMD_ERRCODE_SECURITY_ERROR:
@@ -249,10 +249,9 @@ static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
                data.result = ret_val;
 
                ret_result = strstr((char *)val, delims);
-               if (ret_result){
+               if (ret_result)
                        printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n",
                                           req_id, pkg_type, pkgid, key, ret_val, ret_result);
-               }
                else
                        printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n",
                                           req_id, pkg_type, pkgid, key, ret_val);
@@ -262,9 +261,8 @@ static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
                           req_id, pkg_type, pkgid, key, val);
 
        if (strncmp(key, "end", strlen("end")) == 0) {
-               if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){
+               if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0)
                        data.result = PKGCMD_ERRCODE_ERROR;
-               }
                g_main_loop_quit(main_loop);
        }
 
@@ -370,11 +368,12 @@ static int __is_app_installed(char *pkgid, uid_t uid)
        else
                ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
 
-       if(ret < 0) {
+       if (ret < 0) {
                printf("package is not in pkgmgr_info DB\n");
                return -1;
-       } else
+       } else {
                pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
 
        return 0;
 }
@@ -439,7 +438,7 @@ static void __print_usage()
 
 }
 
-static int __pkgmgr_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+static int __pkgmgr_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
 {
        int ret = -1;
        char *pkgid = NULL;
@@ -473,7 +472,8 @@ static int __pkgmgr_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
                return ret;
        }
 
-       printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version);
+       printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n",
+                       for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version);
        return ret;
 }
 
@@ -484,14 +484,16 @@ static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
        pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
 
        ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
-       }
-  if (uid_info->uid != GLOBAL_USER)
-         ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL);
-  else
-         ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, NULL, NULL, NULL);
-       if (ret < 0){
+
+       if (uid_info->uid != GLOBAL_USER)
+               ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE,
+                               (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL);
+       else
+               ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE,
+                               (pkgmgr_client *)user_data, NULL, pkgid, NULL, NULL, NULL);
+       if (ret < 0) {
                printf("pkgmgr_client_request_service Failed\n");
                return -1;
        }
@@ -511,7 +513,7 @@ static int __process_request(uid_t uid)
        char pkg_new[PATH_MAX] = {0, };
        bool blacklist;
 
-#if !GLIB_CHECK_VERSION(2,35,0)
+#if !GLIB_CHECK_VERSION(2, 35, 0)
        g_type_init();
 #endif
        switch (data.request) {
@@ -533,19 +535,16 @@ static int __process_request(uid_t uid)
                if (data.tep_path[0] != '\0')
                        pkgmgr_client_set_tep_path(pc, data.tep_path, data.tep_move);
 
-               if (data.des_path[0] == '\0') {
-                       ret =
-                               pkgmgr_client_usr_install(pc, data.pkg_type, NULL,
-                                               data.pkg_path, NULL, PM_QUIET,
-                                               __return_cb, pc, uid);
-               } else {
-                       ret =
-                               pkgmgr_client_usr_install(pc, data.pkg_type,
-                                               data.des_path, data.pkg_path,
-                                               NULL, PM_QUIET, __return_cb, pc, uid);
+               if (data.des_path[0] == '\0')
+                       ret = pkgmgr_client_usr_install(pc, data.pkg_type, NULL,
+                                       data.pkg_path, NULL, PM_QUIET,
+                                       __return_cb, pc, uid);
+               else
+                       ret = pkgmgr_client_usr_install(pc, data.pkg_type,
+                                       data.des_path, data.pkg_path,
+                                       NULL, PM_QUIET, __return_cb, pc, uid);
 
-               }
-               if (ret < 0){
+               if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
                                data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND;
@@ -556,15 +555,17 @@ static int __process_request(uid_t uid)
                break;
        case CREATE_DELTA:
                printf("CREATE_DELTA\n");
-               if (data.pkg_old[0] == '\0' || data.pkg_new[0] == '\0' ) {
+               if (data.pkg_old[0] == '\0' || data.pkg_new[0] == '\0') {
                        printf("tpk pkg missing\n");
                        break;
                }
-               if(data.delta_pkg[0] == '\0') {
+               if (data.delta_pkg[0] == '\0') {
                        snprintf(data.resolved_path_delta_pkg, PATH_MAX, "/tmp/delta_pkg");
                        printf("output file will be /tmp/delta_pkg.delta\n");
                }
-               const char *unzip_argv[] = {"sh", "/etc/package-manager/pkgmgr-unzip-tpk.sh", "-a", data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", data.resolved_path_delta_pkg, NULL};
+               const char *unzip_argv[] = {"sh", "/etc/package-manager/pkgmgr-unzip-tpk.sh", "-a",
+                               data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p",
+                               data.resolved_path_delta_pkg, NULL};
                ret = __xsystem(unzip_argv);
                if (ret != 0) {
                        printf("unzip is fail .\n");
@@ -586,11 +587,13 @@ static int __process_request(uid_t uid)
                }
                ptr_new_tpk++;
 
-               snprintf(pkg_old, PATH_MAX,"%s%s%s", TEMP_DELTA_REPO, ptr_old_tpk, UNZIPFILE);
-               snprintf(pkg_new, PATH_MAX,"%s%s%s", TEMP_DELTA_REPO, ptr_new_tpk, UNZIPFILE);
+               snprintf(pkg_old, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO, ptr_old_tpk, UNZIPFILE);
+               snprintf(pkg_new, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO, ptr_new_tpk, UNZIPFILE);
                __create_diff_file(pkg_old, pkg_new);
 
-               const char *delta_argv[] = {"sh", "/etc/package-manager/pkgmgr-create-delta.sh", "-a", data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", data.resolved_path_delta_pkg, NULL};
+               const char *delta_argv[] = {"sh", "/etc/package-manager/pkgmgr-create-delta.sh", "-a",
+                               data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p",
+                               data.resolved_path_delta_pkg, NULL};
                ret = __xsystem(delta_argv);
                if (ret != 0) {
                        printf("create delta script fail .\n");
@@ -612,17 +615,16 @@ static int __process_request(uid_t uid)
                        data.result = PKGCMD_ERRCODE_ERROR;
                        break;
                }
-//if global
+
                ret = __is_app_installed(data.pkgid, uid);
                if (ret == -1) {
                        printf("package is not installed\n");
                        break;
                }
 
-               ret =
-                   pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid,
-                                           PM_QUIET, __return_cb, NULL,uid);
-               if (ret < 0){
+               ret = pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid,
+                               PM_QUIET, __return_cb, NULL, uid);
+               if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
                                data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND;
@@ -648,7 +650,7 @@ static int __process_request(uid_t uid)
                }
 
                ret = pkgmgr_client_usr_reinstall(pc, data.pkg_type, data.pkgid, NULL, PM_QUIET, __return_cb, pc, uid);
-               if (ret < 0){
+               if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
                                data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND;
@@ -678,7 +680,7 @@ static int __process_request(uid_t uid)
                        break;
                }
                ret = pkgmgr_client_usr_clear_user_data(pc, data.pkg_type,
-                                                   data.pkgid, PM_QUIET, uid);
+                               data.pkgid, PM_QUIET, uid);
                if (ret < 0)
                        break;
                ret = data.result;
@@ -700,7 +702,7 @@ static int __process_request(uid_t uid)
                        break;
                }
 
-               if (strcmp(data.pkg_type, "app") == 0 ) {
+               if (strcmp(data.pkg_type, "app") == 0) {
                        if (data.global)
                                /* enable global app for this user only */
                                ret = pkgmgr_client_activate_global_app_for_uid(pc, data.pkgid, __app_return_cb, getuid());
@@ -742,7 +744,7 @@ static int __process_request(uid_t uid)
                        break;
                }
 
-               if (strcmp(data.pkg_type, "app") == 0 ) {
+               if (strcmp(data.pkg_type, "app") == 0) {
                        if (data.global)
                                /* disable global app for this user only*/
                                ret = pkgmgr_client_deactivate_global_app_for_uid(pc, data.pkgid, __app_return_cb, getuid());
@@ -840,7 +842,7 @@ static int __process_request(uid_t uid)
 
                if (data.request == KILLAPP_REQ) {
                        ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
-                       if (ret < 0){
+                       if (ret < 0) {
                                data.result = PKGCMD_ERRCODE_ERROR;
                                break;
                        }
@@ -851,7 +853,7 @@ static int __process_request(uid_t uid)
 
                } else if (data.request == CHECKAPP_REQ) {
                        ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
-                       if (ret < 0){
+                       if (ret < 0) {
                                data.result = PKGCMD_ERRCODE_ERROR;
                                break;
                        }
@@ -867,35 +869,39 @@ static int __process_request(uid_t uid)
        case LIST_REQ:
                if (data.pkg_type[0] == '\0') {
                        ret = 0;
-                       if (uid != GLOBAL_USER) {
+                       if (uid != GLOBAL_USER)
                                ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_cb, NULL, uid);
-                       } else {
+                       else
                                ret = pkgmgrinfo_pkginfo_get_list(__pkgmgr_list_cb, NULL);
-                               }
-                               if (ret == -1)
-                                       printf("no packages found\n");
-                               break;
+
+                       if (ret == -1)
+                               printf("no packages found\n");
+                       break;
                } else {
                        pkgmgrinfo_pkginfo_filter_h handle;
+
                        ret = pkgmgrinfo_pkginfo_filter_create(&handle);
                        if (ret == -1) {
                                printf("Failed to get package filter handle\n");
                                break;
                        }
+
                        ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type);
                        if (ret == -1) {
                                printf("Failed to add package type filter\n");
                                pkgmgrinfo_pkginfo_filter_destroy(handle);
                                break;
                        }
-                       if (uid != GLOBAL_USER) {
+
+                       if (uid != GLOBAL_USER)
                                ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL, uid);
-                       } else {
+                       else
                                ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL);
-                       }
-                               if (ret != PMINFO_R_OK)
-                                       printf("no package filter list\n");
-                                       pkgmgrinfo_pkginfo_filter_destroy(handle);
+
+                       if (ret != PMINFO_R_OK)
+                               printf("no package filter list\n");
+
+                       pkgmgrinfo_pkginfo_filter_destroy(handle);
                        break;
                }
 
@@ -905,7 +911,8 @@ static int __process_request(uid_t uid)
                break;
 
        case CSC_REQ:
-               ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, data.des_path, NULL, (void *)data.pkg_path);
+               ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid,
+                               data.des_path, NULL, (void *)data.pkg_path);
                if (ret < 0)
                        data.result = PKGCMD_ERRCODE_ERROR;
                break;
@@ -929,8 +936,9 @@ static int __process_request(uid_t uid)
                        ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, (void *)pc, uid);
                        break;
                }
-               ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
-               if (ret < 0){
+               ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type,
+                               pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
+               if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
                        break;
                }
@@ -951,12 +959,14 @@ static int __process_request(uid_t uid)
                        ret = -1;
                        break;
                }
+
                pc = pkgmgr_client_new(PC_REQUEST);
                if (pc == NULL) {
                        printf("PkgMgr Client Creation Failed\n");
                        data.result = PKGCMD_ERRCODE_ERROR;
                        break;
                }
+
                ret = pkgmgr_client_usr_add_blacklist(pc, data.pkgid, uid);
                if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
@@ -973,12 +983,14 @@ static int __process_request(uid_t uid)
                        ret = -1;
                        break;
                }
+
                pc = pkgmgr_client_new(PC_REQUEST);
                if (pc == NULL) {
                        printf("PkgMgr Client Creation Failed\n");
                        data.result = PKGCMD_ERRCODE_ERROR;
                        break;
                }
+
                ret = pkgmgr_client_usr_remove_blacklist(pc, data.pkgid, uid);
                if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
@@ -995,12 +1007,14 @@ static int __process_request(uid_t uid)
                        ret = -1;
                        break;
                }
+
                pc = pkgmgr_client_new(PC_REQUEST);
                if (pc == NULL) {
                        printf("PkgMgr Client Creation Failed\n");
                        data.result = PKGCMD_ERRCODE_ERROR;
                        break;
                }
+
                ret = pkgmgr_client_usr_check_blacklist(pc, data.pkgid, &blacklist, uid);
                if (ret < 0) {
                        data.result = PKGCMD_ERRCODE_ERROR;
@@ -1011,6 +1025,7 @@ static int __process_request(uid_t uid)
                        printf("%s is blacklisted\n", data.pkgid);
                else
                        printf("%s is not blacklisted\n", data.pkgid);
+
                ret = data.result;
                break;
 
@@ -1039,7 +1054,6 @@ int main(int argc, char *argv[])
        struct timeval tv;
        bool is_root_cmd = false;
 
-
        if (argc == 1)
                __print_usage();
 
@@ -1061,7 +1075,7 @@ int main(int argc, char *argv[])
        memset(data.tep_path, '\0', PATH_MAX);
        memset(data.tep_move, '\0', PKG_NAME_STRING_LEN_MAX);
 
-       data.global = 0; //By default pkg_cmd will manage for the current user
+       data.global = 0; /* By default pkg_cmd will manage for the current user */
        data.result = 0;
        data.type = -1;
        while (1) {
@@ -1156,9 +1170,9 @@ int main(int argc, char *argv[])
                case 'X':  /* old_tpk */
                        data.request = CREATE_DELTA;
                        is_root_cmd = true;
-                       if (optarg) {
+                       if (optarg)
                                strncpy(data.pkg_old, optarg, PATH_MAX - 1);
-                       }
+
                        if (realpath(data.pkg_old, data.resolved_path_pkg_old) == NULL) {
                                printf("failed to set realpath\n");
                                return -1;
@@ -1167,9 +1181,9 @@ int main(int argc, char *argv[])
                        break;
 
                case 'Y':  /* new_tpk */
-                       if (optarg) {
+                       if (optarg)
                                strncpy(data.pkg_new, optarg, PATH_MAX - 1);
-                       }
+
                        if (realpath(data.pkg_new, data.resolved_path_pkg_new) == NULL) {
                                printf("failed to set realpath\n");
                                return -1;
@@ -1178,15 +1192,15 @@ int main(int argc, char *argv[])
                        break;
 
                case 'Z':  /* delta_tpk */
-                       if (optarg) {
+                       if (optarg)
                                strncpy(data.delta_pkg, optarg, PATH_MAX - 1);
-                       }
+
                        printf("delta_pkg is %s\n", data.delta_pkg);
                        if (realpath(data.delta_pkg, data.resolved_path_delta_pkg) == NULL) {
                                printf("failed to set realpath\n");
                                return -1;
                        }
-                       printf("delta_pkg abs path is %s\n",data.resolved_path_delta_pkg);
+                       printf("delta_pkg abs path is %s\n", data.resolved_path_delta_pkg);
                        break;
                case 'd':  /* descriptor path */
                        if (optarg)
@@ -1214,7 +1228,8 @@ int main(int argc, char *argv[])
 
                case 'M':  /*tep move*/
                        if (optarg)
-                               strncpy(data.tep_move, (atoi(optarg) == 1)?"tep_move":"tep_copy", PKG_NAME_STRING_LEN_MAX - 1);
+                               strncpy(data.tep_move, (atoi(optarg) == 1) ? "tep_move" : "tep_copy",
+                                               PKG_NAME_STRING_LEN_MAX - 1);
                        break;
 
                case 't':  /* package type */
@@ -1271,19 +1286,21 @@ int main(int argc, char *argv[])
 
                }
        }
+
        uid_t uid = getuid();
-       if(!is_root_cmd && uid == OWNER_ROOT) {
+       if (!is_root_cmd && uid == OWNER_ROOT) {
                printf("Current User is Root! : Only regular users are allowed\n");
                return -1;
        }
-       if(data.global == 1) {
+
+       if (data.global == 1)
                uid = GLOBAL_USER;
-       }
+
        ret = __process_request(uid);
        if ((ret < 0) && (data.result == 0)) {
-                printf("Undefined error(%d)", ret);
+               printf("Undefined error(%d)", ret);
                data.result = PKGCMD_ERRCODE_UNDEFINED_ERROR;
-        }
+       }
 
        if (ret != 0) {
                __error_no_to_string(data.result, &errstr);
index 879b6748217ae6ae62d2c69165fb8fa55549acb2..d27a32de8a132239e7caa655335c314ed8971e0c 100644 (file)
 #undef LOG_TAG
 #ifndef LOG_TAG
 #define LOG_TAG "PKGMGR_GETSIZE"
-#endif                         /* LOG_TAG */
+#endif  /* LOG_TAG */
 
 #define MAX_PKG_BUF_LEN                        1024
-#define BLOCK_SIZE                     4096 /*in bytes*/
-#define MAX_PATH_LENGTH                512
-#define MAX_LONGLONG_LENGTH    32
-#define MAX_SIZE_INFO_SIZE             128
+#define BLOCK_SIZE                     4096 /*in bytes*/
+#define MAX_PATH_LENGTH                        512
+#define MAX_LONGLONG_LENGTH            32
+#define MAX_SIZE_INFO_SIZE             128
 
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
@@ -58,8 +58,7 @@
 #define APP_BASE_EXTERNAL_PATH ""
 #endif
 
-typedef enum
-{
+typedef enum {
        STORAGE_TYPE_INTERNAL,
        STORAGE_TYPE_EXTERNAL,
        STORAGE_TYPE_MAX = 255,
@@ -70,9 +69,8 @@ long long __stat_size(struct stat *s)
        long long blksize = s->st_blksize;
        long long size = (long long)s->st_blocks * 512;
 
-       if (blksize) {
+       if (blksize)
                size = (size + blksize - 1) & (~(blksize - 1));
-       }
 
        return size;
 }
@@ -85,12 +83,12 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
        int ret;
        DIR *dir;
        struct dirent *dent;
-       const char *entry;
+       const char *file_info;
 
        if (include_itself) {
                ret = fstat(dfd, &st);
                if (ret < 0) {
-                       ERR("fstat() failed, entry: ., errno: %d (%s)", errno,
+                       ERR("fstat() failed, file_info: ., errno: %d (%s)", errno,
                                        strerror(errno));
                        return -1;
                }
@@ -105,30 +103,30 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
        }
 
        while ((dent = readdir(dir))) {
-               entry = dent->d_name;
-               if (entry[0] == '.') {
-                       if (entry[1] == '\0')
+               file_info = dent->d_name;
+               if (file_info[0] == '.') {
+                       if (file_info[1] == '\0')
                                continue;
-                       if ((entry[1] == '.') && (entry[2] == '\0'))
+                       if ((file_info[1] == '.') && (file_info[2] == '\0'))
                                continue;
                }
 
                if (dent->d_type == DT_DIR) {
-                       subfd = openat(dfd, entry, O_RDONLY | O_DIRECTORY);
+                       subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY);
                        if (subfd < 0) {
-                               ERR("openat() failed, entry:%s, errno: %d(%s)",
-                                               entry, errno, strerror(errno));
+                               ERR("openat() failed, file_info:%s, errno: %d(%s)",
+                                               file_info, errno, strerror(errno));
                                goto error;
                        }
 
-                       DBG("traverse entry: %s", entry);
+                       DBG("traverse file_info: %s", file_info);
                        size += __calculate_directory_size(subfd, true);
                        close(subfd);
                } else {
-                       ret = fstatat(dfd, entry, &st, AT_SYMLINK_NOFOLLOW);
+                       ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
                        if (ret < 0) {
-                               ERR("fstatat() failed, entry:%s, errno: %d(%s)",
-                                               entry, errno, strerror(errno));
+                               ERR("fstatat() failed, file_info:%s, errno: %d(%s)",
+                                               file_info, errno, strerror(errno));
                                goto error;
                        }
                        size += __stat_size(&st);
@@ -167,7 +165,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
                                app_root_dir, errno, strerror(errno));
                goto error;
        }
-       *app_size += __stat_size(&st); // shared directory
+       *app_size += __stat_size(&st);  /* shared directory */
        DBG("app_size: %lld", *app_size);
 
        DBG("traverse path: %s/shared/data", app_root_dir);
@@ -175,8 +173,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
        subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY);
        if (subfd >= 0) {
                size = __calculate_directory_size(subfd, true);
-               if (size < 0)
-               {
+               if (size < 0) {
                        ERR("Calculating shared/data directory failed.");
                        goto error;
                }
@@ -184,7 +181,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
                DBG("data_size: %lld", *data_size);
                close(subfd);
        } else if (subfd < 0 && errno != ENOENT) {
-               ERR("openat() failed, entry: data, errno: %d (%s)",
+               ERR("openat() failed, file_info: data, errno: %d (%s)",
                                errno, strerror(errno));
                goto error;
        }
@@ -202,7 +199,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
                DBG("data_size: %lld", *data_size);
                close(subfd);
        } else if (subfd < 0 && errno != ENOENT) {
-               DBG("openat() failed, entry: trusted, errno: %d (%s)",
+               DBG("openat() failed, file_info: trusted, errno: %d (%s)",
                                errno, strerror(errno));
                goto error;
        }
@@ -220,7 +217,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
                DBG("app_size: %lld", *app_size);
                close(subfd);
        } else if (subfd < 0 && errno != ENOENT) {
-               ERR("openat() failed, entry: res, errno: %d (%s)",
+               ERR("openat() failed, file_info: res, errno: %d (%s)",
                                errno, strerror(errno));
                goto error;
        }
@@ -238,7 +235,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
                DBG("data_size: %lld", *data_size);
                close(subfd);
        } else if (subfd < 0 && errno != ENOENT) {
-               ERR("openat() failed, entry: data, errno: %d (%s)",
+               ERR("openat() failed, file_info: data, errno: %d (%s)",
                                errno, strerror(errno));
                goto error;
        }
@@ -391,22 +388,22 @@ static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info)
 
        snprintf(size_info_str, MAX_SIZE_INFO_SIZE, "%lld",
                        pkg_size_info->data_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
        snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
                        "%lld", pkg_size_info->cache_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
        snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
                        "%lld", pkg_size_info->app_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
        snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
                        "%lld", pkg_size_info->ext_data_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
        snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
                        "%lld", pkg_size_info->ext_cache_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
        snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
                        "%lld", pkg_size_info->ext_app_size);
-       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1);
+       strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
 
        DBG("size_info_str: %s", size_info_str);
 
@@ -560,10 +557,10 @@ int main(int argc, char *argv[])
        pkgmgr_installer *pi;
        pkg_size_info_t info = {0, };
 
-       // argv has bellowed meaning
-       // argv[1] = pkgid
-       // argv[2] = get type
-       // argv[4] = req_key
+       /* argv has bellowed meaning */
+       /* argv[1] = pkgid */
+       /* argv[2] = get type */
+       /* argv[4] = req_key */
 
        if (argv[1] == NULL) {
                ERR("pkgid is NULL");
index a57fd669c255a74aa3870d03fc86b6bfbd01c859..d7f42f5a01e8937e48a76faf3f7b0545d07ce80b 100644 (file)
@@ -54,7 +54,7 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid);
 static int __del_certinfo_from_db(char *pkgid);
 static int __get_integer_input_data(void);
 char *__get_string_input_data(void);
-static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data);
+static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data);
 static int __app_category_list_cb(const char *category_name, void *user_data);
 static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data);
 static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data);
@@ -82,119 +82,102 @@ static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *us
        int installed_time = -1;
 
        ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get pkg type\n");
-       }
        if (type)
                printf("Type: %s\n", type);
 
        ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get version\n");
-       }
        if (version)
                printf("Version: %s\n", version);
 
        ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get install location\n");
-       }
        printf("Install Location: %d\n", location);
 
        ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get icon\n");
-       }
        if (icon)
                printf("Icon: %s\n", icon);
 
        ret = pkgmgrinfo_pkginfo_get_label(handle, &label);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get label\n");
-       }
        if (label)
                printf("Label: %s\n", label);
 
        ret = pkgmgrinfo_pkginfo_get_description(handle, &desc);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get description\n");
-       }
        if (desc)
                printf("Description: %s\n", desc);
 
        ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get author name\n");
-       }
        if (author_name)
                printf("Author Name: %s\n", author_name);
 
        ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get author email\n");
-       }
        if (author_email)
                printf("Author Email: %s\n", author_email);
 
        ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get author href\n");
-       }
        if (author_href)
                printf("Author Href: %s\n", author_href);
 
        ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get root_path\n");
-       }
-       if (author_href)
+       if (root_path)
                printf("root_path : %s\n", root_path);
 
        ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get mainappid\n");
-       }
-       if (author_href)
+       if (mainappid)
                printf("mainappid : %s\n", mainappid);
 
        ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get install time\n");
-       }
        printf("Install time: %d\n", installed_time);
 
        ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get removable\n");
-       }
        else
                printf("Removable: %d\n", removable);
 
        ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get preload\n");
-       }
        else
                printf("Preload: %d\n", preload);
 
        ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get readonly\n");
-       }
        else
                printf("Readonly: %d\n", readonly);
 
        ret = pkgmgrinfo_pkginfo_is_update(handle, &update);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get update\n");
-       }
        else
                printf("update: %d\n", update);
 
        ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get system\n");
-       }
        else
                printf("system: %d\n", system);
 }
@@ -206,14 +189,12 @@ int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
        int ret = -1;
 
        ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get appid\n");
-       }
 
        ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get package\n");
-       }
        printf("apptype [%s]\t appid [%s]\n", apptype, appid);
 
        return 0;
@@ -245,11 +226,13 @@ char *__get_string_input_data(void)
                printf("Malloc Failed\n");
                return NULL;
        }
-       if (fgets(data,1024,stdin) == NULL){
+
+       if (fgets(data, 1024, stdin) == NULL) {
                printf("Buffer overflow!!! try again\n");
                exit(-1);
        }
        data[strlen(data) - 1] = '\0';
+
        return data;
 }
 
@@ -319,8 +302,10 @@ static void __print_arg_filter_usage()
 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
 {
        char *appid = NULL;
+
        pkgmgrinfo_appinfo_get_appid(handle, &appid);
        printf("appid : %s\n", appid);
+
        return 0;
 }
 
@@ -332,7 +317,7 @@ static int __add_metadata_filter()
        char *value = NULL;
 
        ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
-       if (ret != PMINFO_R_OK){
+       if (ret != PMINFO_R_OK) {
                printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n");
                return ret;
        }
@@ -345,13 +330,13 @@ static int __add_metadata_filter()
        printf("filter condition : key=[%s], value=[%s]\n", key, value);
 
        ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value);
-       if (ret != PMINFO_R_OK){
+       if (ret != PMINFO_R_OK) {
                printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
                goto err;
        }
 
        ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL);
-       if (ret != PMINFO_R_OK){
+       if (ret != PMINFO_R_OK) {
                printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
                goto err;
        }
@@ -377,13 +362,14 @@ static int __add_app_filter(uid_t uid)
        int val = -1;
        int count = 0;
        pkgmgrinfo_appinfo_filter_h handle;
+
        ret = pkgmgrinfo_appinfo_filter_create(&handle);
        if (ret > 0) {
                printf("appinfo filter handle create failed\n");
                return -1;
        }
-       while (choice != 0 && choice != 1)
-       {
+
+       while (choice != 0 && choice != 1) {
                printf("Enter Choice\n");
                printf("0  --> Finalize filter and get count of apps\n");
                printf("1  --> Finalize filter and get list of apps\n");
@@ -659,8 +645,8 @@ static int __add_pkg_filter(uid_t uid)
                printf("pkginfo filter handle create failed\n");
                return -1;
        }
-       while (choice != 0 && choice !=1)
-       {
+
+       while (choice != 0 && choice != 1) {
                printf("Enter Choice\n");
                printf("0  --> Finalize filter and get count of packages\n");
                printf("1  --> Finalize filter and get list of packages\n");
@@ -1083,18 +1069,20 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid)
        int i = 0;
        const char *value = NULL;
        pkgmgrinfo_certinfo_h handle = NULL;
+
        ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
        if (ret < 0) {
                printf("pkgmgrinfo_pkginfo_create_certinfo failed\n");
                return -1;
        }
+
        ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid);
        if (ret < 0) {
                printf("pkgmgrinfo_pkginfo_load_certinfo failed\n");
                return -1;
        }
-       while (choice != 10)
-       {
+
+       while (choice != 10) {
                printf("Enter the choice to get\n");
                printf("0 --> to get all cert values\n");
                printf("1 --> author root certificate\n");
@@ -1110,8 +1098,7 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid)
                choice = __get_integer_input_data();
                switch (choice) {
                case 0:
-                       for (i = 0; i < 9; i++)
-                       {
+                       for (i = 0; i < 9; i++) {
                                pkgmgrinfo_pkginfo_get_cert_value(handle, i, &value);
                                if (value)
                                        printf("cert type[%d] value = %s\n", i, value);
@@ -1162,9 +1149,8 @@ static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_
                ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result);
        else
                ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result);
-       if (ret != PMINFO_R_OK) {
+       if (ret != PMINFO_R_OK)
                return -1;
-       }
 
        printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
        printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result);
@@ -1184,9 +1170,8 @@ static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_
                ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result);
        else
                ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result);
-       if (ret != PMINFO_R_OK) {
+       if (ret != PMINFO_R_OK)
                return -1;
-       }
 
        printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
        printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result);
@@ -1203,13 +1188,14 @@ static int __set_certinfo_in_db(char *pkgid, uid_t uid)
        int choice = -1;
        char *value = NULL;
        pkgmgr_instcertinfo_h handle = NULL;
+
        ret = pkgmgr_installer_create_certinfo_set_handle(&handle);
        if (ret < 0) {
                printf("pkgmgr_installer_create_certinfo_set_handle failed\n");
                return -1;
        }
-       while (choice != 0)
-       {
+
+       while (choice != 0) {
                printf("Enter the choice you want to set\n");
                printf("0 --> to set data in DB\n");
                printf("1 --> author root certificate\n");
@@ -1421,70 +1407,63 @@ static int __remove_manifest_from_db(char *manifest, uid_t uid)
 
 int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
 {
+       int ret = -1;
        char *appid;
        char *data = NULL;
-       if (user_data) {
-               data = (char *)user_data;
-       }
-       int ret = -1;
        char *exec = NULL;
        char *icon = NULL;
        char *label = NULL;
-       pkgmgrinfo_app_component component = 0;
        char *apptype = NULL;
+       char *package = NULL;
        bool nodisplay = 0;
        bool multiple = 0;
        bool taskmanage = 0;
-       pkgmgrinfo_app_hwacceleration hwacceleration;
-       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
-       char *package = NULL;
+       pkgmgrinfo_app_component component = 0;
+       pkgmgrinfo_app_hwacceleration hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
+
+       if (user_data)
+               data = (char *)user_data;
 
        ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get appid\n");
-       }
        if (appid)
                printf("Appid: %s\n", appid);
 
        ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get package\n");
-       }
        if (package)
                printf("Package: %s\n", package);
 
        ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get exec\n");
-       }
        if (exec)
                printf("Exec: %s\n", exec);
 
        ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get icon\n");
-       }
        if (icon)
                printf("Icon: %s\n", icon);
 
        ret = pkgmgrinfo_appinfo_get_label(handle, &label);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get label\n");
-       }
        if (label)
                printf("Label: %s\n", label);
 
        ret = pkgmgrinfo_appinfo_get_component(handle, &component);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get component\n");
-       }
 
        ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get apptype\n");
-       }
        if (apptype)
                printf("Apptype: %s\n", apptype);
 
@@ -1492,57 +1471,51 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
                printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" :
                                "widgetapp");
                ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get multiple\n");
-               } else {
+               else
                        printf("Multiple: %d\n", multiple);
-               }
 
                ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get nodisplay\n");
-               } else {
+               else
                        printf("Nodisplay: %d \n", nodisplay);
-               }
 
                ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get taskmanage\n");
-               } else {
+               else
                        printf("Taskmanage: %d\n", taskmanage);
-               }
 
                ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get hwacceleration\n");
-               } else {
+               else
                        printf("hw-acceleration: %d\n", hwacceleration);
-               }
 
                ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get screenreader\n");
-               } else {
+               else
                        printf("screenreader: %d\n", screenreader);
-               }
-
        }
+
        if (component == PMINFO_SVC_APP) {
                printf("component: svcapp\n");
                ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get onboot\n");
-               } else {
+               else
                        printf("Onboot: %d\n", onboot);
-               }
 
                ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("Failed to get autorestart\n");
-               } else {
+               else
                        printf("Autorestart: %d \n", autorestart);
-               }
        }
+
        if (data)
                printf("user_data : %s\n\n", data);
 
@@ -1550,38 +1523,36 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
 }
 
 
-static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
 {
-       char *test_data = "test data";
        int ret = -1;
+       int installed_time = -1;
+       char *test_data = "test data";
        char *pkgid;
        char *pkg_type;
        char *pkg_version;
        bool preload = 0;
-       int installed_time = -1;
 
        pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
        ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
-       }
+
        ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_get_type() failed\n");
-       }
+
        ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_get_version() failed\n");
-       }
+
        ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_is_preload() failed\n");
-       }
+
        ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
-       if(ret < 0) {
+       if (ret < 0)
                printf("pkgmgrinfo_pkginfo_get_installed_time() failed\n");
-       }
-
 
        printf("---------------------------------------\n");
        printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type,
@@ -1590,25 +1561,23 @@ static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
        if (uid_info->uid != GLOBAL_USER) {
                printf("**List of Ui-Apps**\n");
                ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid_info->uid);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgr_get_info_app() failed\n");
-               }
+
                printf("**List of Svc-Apps**\n");
                ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid_info->uid);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgr_get_info_app() failed\n");
-               }
        } else {
                printf("**List of Ui-Apps**\n");
                ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgr_get_info_app() failed\n");
-               }
+
                printf("**List of Svc-Apps**\n");
                ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgr_get_info_app() failed\n");
-               }
        }
        printf("---------------------------------------\n");
 
@@ -1618,6 +1587,7 @@ static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
 static int __get_pkg_list(uid_t uid)
 {
        int ret = -1;
+
        if (uid != GLOBAL_USER)
                ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid);
        else
@@ -1626,13 +1596,15 @@ static int __get_pkg_list(uid_t uid)
                printf("pkgmgrinfo_pkginfo_get_list() failed\n");
                return -1;
        }
+
        return 0;
 }
 
 static int __get_installed_app_list(uid_t uid)
 {
        int ret = -1;
-       if(uid != GLOBAL_USER)
+
+       if (uid != GLOBAL_USER)
                ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL);
        else
                ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL);
@@ -1640,6 +1612,7 @@ static int __get_installed_app_list(uid_t uid)
                printf("pkgmgrinfo_appinfo_get_installed_list() failed\n");
                return -1;
        }
+
        return 0;
 }
 
@@ -1676,18 +1649,22 @@ static int __get_app_category_list(char *appid)
 {
        int ret = -1;
        pkgmgrinfo_appinfo_h handle;
+
        ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
        if (ret < 0) {
                printf("Failed to get handle\n");
                return -1;
        }
+
        ret = pkgmgrinfo_appinfo_foreach_category(handle, __app_category_list_cb, NULL);
        if (ret < 0) {
                printf("pkgmgrinfo_appinfo_foreach_category() failed\n");
                pkgmgrinfo_appinfo_destroy_appinfo(handle);
                return -1;
        }
+
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
        return 0;
 }
 
@@ -1695,18 +1672,22 @@ static int __get_app_metadata_list(char *appid)
 {
        int ret = -1;
        pkgmgrinfo_appinfo_h handle;
+
        ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
        if (ret < 0) {
                printf("Failed to get handle\n");
                return -1;
        }
+
        ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL);
        if (ret < 0) {
                printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n");
                pkgmgrinfo_appinfo_destroy_appinfo(handle);
                return -1;
        }
+
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
        return 0;
 }
 
@@ -1714,38 +1695,45 @@ static int __get_app_control_list(char *appid)
 {
        int ret = -1;
        pkgmgrinfo_appinfo_h handle;
+
        ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
        if (ret < 0) {
                printf("Failed to get handle\n");
                return -1;
        }
+
        ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL);
        if (ret < 0) {
                printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n");
                pkgmgrinfo_appinfo_destroy_appinfo(handle);
                return -1;
        }
+
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
        return 0;
 }
 
 static int __set_app_enabled(char *appid, bool enabled)
 {
        int ret = -1;
+
        ret = pkgmgrinfo_appinfo_set_state_enabled(appid, enabled);
        if (ret < 0) {
                printf("Failed to get handle\n");
                return -1;
        }
+
        return 0;
 }
 
 static int __get_app_list(char *pkgid, uid_t uid)
 {
-       pkgmgrinfo_pkginfo_h handle;
        int ret = -1;
        char *test_data = "test data";
-       if(uid != GLOBAL_USER)
+       pkgmgrinfo_pkginfo_h handle;
+
+       if (uid != GLOBAL_USER)
                ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
        else
                ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
@@ -1753,40 +1741,41 @@ static int __get_app_list(char *pkgid, uid_t uid)
                printf("Failed to get handle\n");
                return -1;
        }
+
        if (uid != GLOBAL_USER) {
                printf("List of Ui-Apps\n\n");
                ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgrinfo_appinfo_get_list() failed\n");
-               }
+
                printf("List of Svc-Apps\n\n");
                ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgrinfo_appinfo_get_list() failed\n");
-               }
        } else {
                printf("List of Ui-Apps\n\n");
                ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgrinfo_appinfo_get_list() failed\n");
-               }
+
                printf("List of Svc-Apps\n\n");
                ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
-               if (ret < 0) {
+               if (ret < 0)
                        printf("pkgmgrinfo_appinfo_get_list() failed\n");
-               }
        }
+
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
        return 0;
 }
 
 static int __get_pkg_info(char *pkgid, uid_t uid)
 {
-       pkgmgrinfo_pkginfo_h handle;
        int ret = -1;
+       pkgmgrinfo_pkginfo_h handle;
 
        printf("Get Pkg Info Called [%s]\n", pkgid);
-       if(uid != GLOBAL_USER)
+       if (uid != GLOBAL_USER)
                ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
        else
                ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
@@ -1798,30 +1787,32 @@ static int __get_pkg_info(char *pkgid, uid_t uid)
        __get_pkgmgrinfo_pkginfo(handle, NULL);
 
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
        return 0;
 }
 
 static int __get_app_info(char *appid)
 {
-       printf("Get App Info Called [%s]\n", appid);
+       int ret = -1;
        char *exec = NULL;
        char *app_id = NULL;
        char *apptype = NULL;
        char *icon = NULL;
        char *label = NULL;
        char *package = NULL;
-       pkgmgrinfo_app_component component = 0;
        bool nodisplay = 0;
        bool multiple = 0;
        bool taskmanage = 0;
-       pkgmgrinfo_app_hwacceleration hwacceleration;
-       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
        bool enabled = 0;
        bool preload = 0;
        pkgmgrinfo_appinfo_h handle;
-       int ret = -1;
+       pkgmgrinfo_app_component component = 0;
+       pkgmgrinfo_app_hwacceleration hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
+
+       printf("Get App Info Called [%s]\n", appid);
 
        ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
        if (ret < 0) {
@@ -1830,72 +1821,68 @@ static int __get_app_info(char *appid)
        }
 
        ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get package\n");
-       }
 
        ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get exec\n");
-       }
 
        ret = pkgmgrinfo_appinfo_get_label(handle, &label);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get label\n");
-       }
+
        ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get icon\n");
-       }
 
        ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get exec\n");
-       }
+
        ret = pkgmgrinfo_appinfo_get_component(handle, &component);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get component\n");
-       }
+
        ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get apptype\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get nodisplay\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get multiple\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get taskmanage\n");
-       }
+
        ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get hwacceleration\n");
-       }
+
        ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get screenreader\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get onboot\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get autorestart\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get enabled\n");
-       }
+
        ret = pkgmgrinfo_appinfo_is_preload(handle, &preload);
-       if (ret < 0) {
+       if (ret < 0)
                printf("Failed to get preload\n");
-       }
 
        if (app_id)
                printf("Appid: %s\n", app_id);
@@ -1905,6 +1892,7 @@ static int __get_app_info(char *appid)
 
        if (exec)
                printf("Exec: %s\n", exec);
+
        if (apptype)
                printf("Apptype: %s\n", apptype);
 
@@ -1940,22 +1928,25 @@ static int __get_app_info(char *appid)
        printf("Preload: %d\n", preload);
 
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
-       return 0;
 
+       return 0;
 }
 
 static int __check_manifest_validation(char *manifest)
 {
        int ret = 0;
+
        if (manifest == NULL) {
                printf("Manifest file is NULL\n");
                return -1;
        }
+
        ret = pkgmgr_parser_check_manifest_validation(manifest);
        if (ret < 0) {
                printf("check manifest validation failed\n");
                return -1;
        }
+
        return 0;
 }
 
@@ -2015,16 +2006,16 @@ int main(int argc, char *argv[])
                        ret = -1;
                        goto end;
                }
-       }else if (argc == 4) {
+       } else if (argc == 4) {
                if (strcmp(argv[1], "--setappenabled") == 0) {
-                       ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true);
+                       ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0") == 0) ? false : true);
                        if (ret == -1) {
                                printf("set app enabled failed\n");
                                goto end;
                        }
                        goto end;
-               } else if(strcmp(argv[1], "--setpkgenabled") == 0) {
-                       ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true);
+               } else if (strcmp(argv[1], "--setpkgenabled") == 0) {
+                       ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0") == 0) ? false : true);
                        if (ret == -1) {
                                printf("set pkg enabled failed\n");
                                goto end;
@@ -2151,7 +2142,6 @@ int main(int argc, char *argv[])
                __print_usage();
 
 end:
-
        gettimeofday(&tv, NULL);
        endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
 
index 1dfcb8e739bb5bb28143e43d76e7702df5f3e231..558f7c31b4dba0a1c702c45ff9215e0cf5a2d693 100644 (file)
 #ifdef _E
 #undef _E
 #endif
-#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", \
+               __FUNCTION__, __LINE__, ##arg);
 
 #ifdef _D
 #undef _D
 #endif
-#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", \
+               __FUNCTION__, __LINE__, ##arg);
 
 #define PKGINSTALLMANIFEST_CMD "/usr/bin/pkg-install-manifest"
 
@@ -62,7 +64,7 @@ static int _is_global(uid_t uid)
 static int _initdb_load_directory(uid_t uid, const char *directory)
 {
        DIR *dir;
-       struct dirent entry, *result;
+       struct dirent file_info, *result;
        int ret;
        char buf[BUFSZE];
 
@@ -75,13 +77,13 @@ static int _initdb_load_directory(uid_t uid, const char *directory)
 
        _D("Loading manifest files from %s", directory);
 
-       for (ret = readdir_r(dir, &entry, &result);
+       for (ret = readdir_r(dir, &file_info, &result);
                        ret == 0 && result != NULL;
-                       ret = readdir_r(dir, &entry, &result)) {
-               if (entry.d_name[0] == '.')
+                       ret = readdir_r(dir, &file_info, &result)) {
+               if (file_info.d_name[0] == '.')
                        continue;
 
-               snprintf(buf, sizeof(buf), "%s/%s", directory, entry.d_name);
+               snprintf(buf, sizeof(buf), "%s/%s", directory, file_info.d_name);
                _D("manifest file %s", buf);
 
                pid_t pid = fork();
@@ -93,7 +95,7 @@ static int _initdb_load_directory(uid_t uid, const char *directory)
                        }
 
                        execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf,
-                             (char*)NULL);
+                             (char *)NULL);
                } else if (pid < 0) {
                        _E("failed to fork and execute %s!", PKGINSTALLMANIFEST_CMD);
                        closedir(dir);