Fix download-fonts-service package for Tizen 3.0
[platform/core/uifw/download-fonts-service.git] / pkgmgr_font / src / font_service_register.c
index 4de31df..3147a7d 100755 (executable)
@@ -28,6 +28,7 @@
 #include <fontconfig/fontconfig.h>
 #include <Elementary.h>
 #include <pkgmgr-info.h>
+#include <pkgmgr_installer_info.h>
 #include "system_settings.h"
 
 
@@ -48,8 +49,8 @@ static const char *PRELOADED_PATH = "/opt/share/fonts/preloaded";
 
 static const char *ELM_PROFILE_CFG = "/opt/home/app/.elementary/config/profile.cfg";
 #define MAX_FILE_LEN 4096
-#define APP_OWNER_ID 5000
-#define APP_GROUP_ID 5000
+#define APP_OWNER_ID 5001
+#define APP_GROUP_ID 100
 
 static int make_dir(const char *path);
 static int symbolic_link(const char *srcpath, const char *destpath);
@@ -94,7 +95,14 @@ static int make_dir(const char *path)
                        return ret;
                }
 
-               ret = chmod (path, 0755);
+               ret = chown(path, getuid(), APP_GROUP_ID);
+               if (ret < 0)
+               {
+                       DEBUG_ERROR("chown is failed %s\n",path);
+                       return ret;
+               }
+
+               ret = chmod(path, 0755);
                if (ret < 0)
                {
                        DEBUG_ERROR("chmod is failed %s\n",path);
@@ -102,13 +110,6 @@ static int make_dir(const char *path)
                        return ret;
                }
        }
-       ret = lsetxattr(path, "security.SMACK64", "_", 1, 0);
-
-       if (ret < 0)
-       {
-               DEBUG_ERROR("lsetxattr is failed %s\n",path);
-               return ret;
-       }
 
        return ret;
 }
@@ -173,14 +174,6 @@ static int symbolic_link(const char *srcpath, const char *destpath)
                                DEBUG_ERROR("symlink is failed \n");
                                goto FAIL;
                        }
-
-                       ret = lsetxattr(destdir, "security.SMACK64", "_", 1, 0);
-
-                       if (ret < 0)
-                       {
-                               DEBUG_ERROR("lsetxattr is failed %s\n",destdir);
-                               goto FAIL;
-                       }
                }
        }
        closedir (d);
@@ -246,14 +239,6 @@ static int move_file(const char *srcpath, const char *destpath)
                                DEBUG_ERROR("symlink is failed \n");
                                goto FAIL;
                        }
-
-                       ret = lsetxattr(destdir, "security.SMACK64", "_", 1, 0);
-
-                       if (ret < 0)
-                       {
-                               DEBUG_ERROR("lsetxattr is failed %s\n",destdir);
-                               goto FAIL;
-                       }
                }
        }
        closedir (d);
@@ -499,8 +484,11 @@ int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *li
        pkgmgrinfo_pkginfo_h handle = NULL;
        const char *app_root_path = NULL;
        const char *dest_path = NULL;
+       uid_t uid = 0;
+
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -560,8 +548,11 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
        pkgmgrinfo_pkginfo_h handle = NULL;
        const char* app_root_path = NULL;
        const char* dest_path = NULL;
+       uid_t uid = 0;
+
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -593,7 +584,7 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
 
        if (access(deletedir, F_OK) == -1)
        {
-               DEBUG_ERROR("dest directory is not exist \n");
+               DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
                goto FAIL;
        }
 
@@ -605,18 +596,16 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
        }
 
        ret = make_dir(PARENT_PATH);
-
        if (ret < 0)
        {
-               DEBUG_ERROR("make current directory is failed \n");
+               DEBUG_ERROR("make current directory(%s) is failed: %s\n", PARENT_PATH, strerror(errno));
                goto FAIL;
        }
 
        ret = make_dir(dest_path);
-
        if (ret < 0)
        {
-               DEBUG_ERROR("make current directory is failed \n");
+               DEBUG_ERROR("make current directory(%s) is failed: %s\n", dest_path, strerror(errno));
                goto FAIL;
        }
 
@@ -643,9 +632,11 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
        FcObjectSet *os = NULL;
        FcPattern *pat = NULL;
        FcFontSet *fs = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
        const char* app_root_path = NULL;
        const char *dest_path = NULL;
        int ret;
+       uid_t uid = 0;
 
        elm_init(0, NULL);
 
@@ -655,10 +646,9 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
                return -1;
        }
 
-       pkgmgrinfo_pkginfo_h handle = NULL;
-
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -752,42 +742,33 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
                                                chmod (ELM_PROFILE_CFG, 0777);
                                        }
 
-                                       ret = lsetxattr(ELM_PROFILE_CFG, "security.SMACK64", "system::homedir", 15, 0);
-                                       if (ret < 0)
-                                       {
-                                               chmod (ELM_PROFILE_CFG, 0777);
-                                       }
-
-                                       DIR *d;
+                                       DIR *d = NULL;
                                        struct dirent *e;
 
-                                       d = opendir (elm_profile_path);
+                                       if (elm_profile_path)
+                                               d = opendir (elm_profile_path);
 
-                                       while ((e = readdir (d)))
+                                       if (d)
                                        {
-                                               if (e->d_name[0] != '.' &&  (strstr(e->d_name, ".cfg") != 0 || strstr(e->d_name, ".CFG") != 0))
+                                               while ((e = readdir (d)))
                                                {
-                                                       char file_full_path[100];
-
-                                                       sprintf(file_full_path, "%s/%s", elm_profile_path, e->d_name);
-
-                                                       ret = chown(file_full_path, APP_OWNER_ID, APP_GROUP_ID);
-                                                       if (ret < 0)
+                                                       if (e->d_name[0] != '.' &&  (strstr(e->d_name, ".cfg") != 0 || strstr(e->d_name, ".CFG") != 0))
                                                        {
-                                                               DEBUG_LOG("chown is failed %s", file_full_path);
-                                                               chmod (file_full_path, 0777);
-                                                       }
+                                                               char file_full_path[100];
 
-                                                       ret = lsetxattr(file_full_path, "security.SMACK64", "system::homedir", 15, 0);
-                                                       if (ret < 0)
-                                                       {
-                                                               DEBUG_LOG("chsmack is failed %s", file_full_path);
-                                                               chmod (file_full_path, 0777);
+                                                               sprintf(file_full_path, "%s/%s", elm_profile_path, e->d_name);
+
+                                                               ret = chown(file_full_path, APP_OWNER_ID, APP_GROUP_ID);
+                                                               if (ret < 0)
+                                                               {
+                                                                       DEBUG_LOG("chown is failed %s", file_full_path);
+                                                                       chmod (file_full_path, 0777);
+                                                               }
                                                        }
                                                }
-                                       }
 
-                                       closedir (d);
+                                               closedir (d);
+                                       }
 
                                        free(default_font_name);
                                        free(elm_profile_path);
@@ -800,7 +781,7 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
 
        if (access(deletedir, F_OK) == -1)
        {
-               DEBUG_ERROR("dest directory(%s) is not exist \n", deletedir);
+               DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
                goto FAIL;
        }