Fix download-fonts-service package for Tizen 3.0
[platform/core/uifw/download-fonts-service.git] / pkgmgr_font / src / font_service_register.c
1 /*
2  * Copyright 2013 Samsung Electronics Co., Ltd
3  *
4  *
5  * Contact: Minsu Seo <minsu15.seo@samsung.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/xattr.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <dirent.h>
26 #include <glib.h>
27 #include <dlog.h>
28 #include <fontconfig/fontconfig.h>
29 #include <Elementary.h>
30 #include <pkgmgr-info.h>
31 #include <pkgmgr_installer_info.h>
32 #include "system_settings.h"
33
34
35 #define FONT_SERVICE_TAG                "FONT_SERVICE"
36 #define DEBUG_LOG(frmt, args...)                \
37         do { SLOG(LOG_DEBUG,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
38         __func__, ##args);} while (0)
39 #define DEBUG_WARNING(frmt, args...)            \
40         do { SLOG(LOG_WARN,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
41         __func__, ##args);} while (0)
42 #define DEBUG_ERROR(frmt, args...)              \
43         do { SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
44         __func__, ##args);} while (0)
45
46 static const char *PARENT_PATH = "/opt/share/fonts";
47 static const char *DOWNLOAD_PATH = "/opt/share/fonts/download";
48 static const char *PRELOADED_PATH = "/opt/share/fonts/preloaded";
49
50 static const char *ELM_PROFILE_CFG = "/opt/home/app/.elementary/config/profile.cfg";
51 #define MAX_FILE_LEN 4096
52 #define APP_OWNER_ID 5001
53 #define APP_GROUP_ID 100
54
55 static int make_dir(const char *path);
56 static int symbolic_link(const char *srcpath, const char *destpath);
57 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle);
58 static int do_uninstall(const char *deletedir);
59 static int move_file(const char *srcpath, const char *destpath);
60 static const char* check_preloaded(const char *app_root_path);
61 #ifdef CHECK_FAMILY_NAME
62 static int check_family_name(const char *srcpath);
63 #endif
64
65 static const char* check_preloaded(const char *app_root_path)
66 {
67         char tpk_path[MAX_FILE_LEN];
68         char wgt_path[MAX_FILE_LEN];
69
70         sprintf(tpk_path, "%s/preloaded", app_root_path);
71         sprintf(wgt_path, "%s/res/wgt/preloaded", app_root_path);
72
73         if ((access(tpk_path, F_OK) == 0) || (access(wgt_path, F_OK) == 0))
74         {
75                 return PRELOADED_PATH;
76         }
77
78         return DOWNLOAD_PATH;
79 }
80
81 static int make_dir(const char *path)
82 {
83         int ret = 0;
84
85         if (access(path, F_OK) == 0)
86         {
87                 return ret;
88         }
89         else
90         {
91                 ret = mkdir(path, 0755);
92                 if (ret < 0)
93                 {
94                         DEBUG_ERROR("make current directory %s is failed \n",path);
95                         return ret;
96                 }
97
98                 ret = chown(path, getuid(), APP_GROUP_ID);
99                 if (ret < 0)
100                 {
101                         DEBUG_ERROR("chown is failed %s\n",path);
102                         return ret;
103                 }
104
105                 ret = chmod(path, 0755);
106                 if (ret < 0)
107                 {
108                         DEBUG_ERROR("chmod is failed %s\n",path);
109                         rmdir(path);
110                         return ret;
111                 }
112         }
113
114         return ret;
115 }
116
117 static int symbolic_link(const char *srcpath, const char *destpath)
118 {
119         DIR *d;
120         struct dirent *e;
121         int ret = 0;
122
123         d = opendir(srcpath);
124         while ((e = readdir (d)))
125         {
126                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
127                 {
128                         char srcdir[MAX_FILE_LEN];
129                         char destdir[MAX_FILE_LEN];
130                         struct stat       statb;
131
132                         if (strlen (srcpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
133                         {
134                                 DEBUG_ERROR("srcdir length is not available \n");
135                                 goto FAIL;
136                         }
137
138                         if (strlen (destpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
139                         {
140                                 DEBUG_ERROR("destdir length is not available \n");
141                                 goto FAIL;
142                         }
143
144                         sprintf(srcdir,"%s/%s",srcpath,(char *) e->d_name);
145                         sprintf(destdir,"%s/%s",destpath,(char *) e->d_name);
146                         if (stat (srcdir, &statb) == -1)
147                         {
148                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
149                                 goto FAIL;
150                         }
151
152                         if (S_ISDIR (statb.st_mode))
153                         {
154                                 if (make_dir(destdir)<0)
155                                 {
156                                         DEBUG_ERROR("make current directory %s is failed \n",destdir);
157                                         goto FAIL;
158                                 }
159                                 ret = symbolic_link(srcdir,destdir);
160                                 if (ret < 0)
161                                 {
162                                         DEBUG_ERROR("symlink is failed \n");
163                                         goto FAIL;
164                                 }
165                                 continue;
166                         }
167                         DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
168                         DEBUG_LOG("destdir =%s\n",(char *) destdir);
169                         DEBUG_LOG("file name =%s\n",(char *) e->d_name);
170
171                         ret = symlink((const char *)srcdir,(const char *)destdir);
172                         if (ret < 0)
173                         {
174                                 DEBUG_ERROR("symlink is failed \n");
175                                 goto FAIL;
176                         }
177                 }
178         }
179         closedir (d);
180         return ret;
181
182 FAIL:
183         closedir (d);
184         return -1;
185 }
186
187
188 static int move_file(const char *srcpath, const char *destpath)
189 {
190         DIR *d;
191         struct dirent *e;
192         int ret = 0;
193
194         d = opendir (srcpath);
195         while ((e = readdir (d)))
196         {
197                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
198                 {
199                         char srcdir[MAX_FILE_LEN];
200                         char destdir[MAX_FILE_LEN];
201                         struct stat       statb;
202
203                         if (strlen (srcpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
204                         {
205                                 DEBUG_ERROR("srcdir length is not available \n");
206                                 goto FAIL;
207                         }
208
209                         if (strlen (destpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
210                         {
211                                 DEBUG_ERROR("destdir length is not available \n");
212                                 goto FAIL;
213                         }
214
215                         sprintf(srcdir,"%s/%s",srcpath,(char *) e->d_name);
216                         sprintf(destdir,"%s/%s",destpath,(char *) e->d_name);
217                         if (stat (srcdir, &statb) == -1)
218                         {
219                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
220                                 goto FAIL;
221                         }
222
223                         if (S_ISDIR (statb.st_mode))
224                         {
225                                 if (make_dir(destdir)<0)
226                                 {
227                                         DEBUG_ERROR("make current directory %s is failed \n",destdir);
228                                         goto FAIL;
229                                 }
230                                 continue;
231                         }
232                         DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
233                         DEBUG_LOG("destdir =%s\n",(char *) destdir);
234                         DEBUG_LOG("file name =%s\n",(char *) e->d_name);
235
236                         ret = rename((const char *)srcdir,(const char *)destdir);
237                         if (ret < 0)
238                         {
239                                 DEBUG_ERROR("symlink is failed \n");
240                                 goto FAIL;
241                         }
242                 }
243         }
244         closedir (d);
245         return ret;
246
247 FAIL:
248         closedir (d);
249         return -1;
250 }
251
252 #ifdef CHECK_FAMILY_NAME
253 static int check_family_name(const char *srcpath)
254 {
255         FcObjectSet *os = NULL;
256         FcFontSet* fs = NULL;
257         FcPattern* pat = NULL;
258         FcConfig* font_config = NULL;
259         bool is_only_one_family = false;
260
261         font_config = FcInitLoadConfigAndFonts();
262
263         if(font_config == NULL) {
264                 DEBUG_ERROR("Failed: FcInitLoadConfigAndFonts");
265                 return -1;
266         }
267
268         pat = FcPatternCreate();
269
270         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
271
272         if (os) {
273                 fs = FcFontList(font_config, pat, os);
274                 FcObjectSetDestroy(os);
275                 os = NULL;
276         }
277
278         if (pat) {
279                 FcPatternDestroy(pat);
280                 pat = NULL;
281         }
282
283         if (fs)
284         {
285                 int j;
286                 char* only_one_family = NULL;
287
288                 for (j = 0; j < fs->nfont; j++)
289                 {
290                         FcChar8 *family = NULL;
291                         FcChar8 *file = NULL;
292
293                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
294                         {
295                                 int font_path_len = strlen(srcpath);
296
297                                         /* always shown for src path */
298                                         if (strncmp((const char*)file, srcpath, font_path_len) == 0)
299                                         {
300                                                                 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch)
301                                                                 {
302                                                                         DEBUG_ERROR("Family name is invalid");
303                                                                         continue;
304                                                                 }
305                                                                 //DEBUG_ERROR("-------- FOUND FONT - family = %s", (char *)family);
306
307                                                                 // first found family name
308                                                                 if (only_one_family == NULL  && strlen((char *)family) > 0)
309                                                                 {
310                                                                         is_only_one_family = true;
311                                                                         only_one_family = (char *)family;
312                                                                         //DEBUG_ERROR("--------First FOUND FONT - family = %s", only_one_family);
313                                                                 }
314                                                                 else if (only_one_family != NULL  && strlen((char *)family) > 0)// after first
315                                                                 {
316                                                                                 if (strcmp(only_one_family,  (char *)family) != 0)
317                                                                                 {
318                                                                                         DEBUG_ERROR("Not supported various font famliy. only one font famliy. %s %s", only_one_family, (char *)family);
319                                                                                         is_only_one_family = false;
320                                                                                         break;
321                                                                                 }
322                                                                 }
323                                                                 else
324                                                                 {
325                                                                         DEBUG_ERROR("invalid fonts");
326                                                                         break;
327                                                                 }
328                                         }
329                         }
330                 }
331
332                 FcFontSetDestroy(fs);
333                 fs = NULL;
334         }
335
336         FcConfigDestroy(font_config);
337         font_config = NULL;
338
339         if (is_only_one_family == false)
340         {
341                 //DEBUG_ERROR("Not supported various font famliy. only one font famliy");
342                 return -1;
343         }
344
345         return 0;
346 }
347 #endif
348
349 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle)
350 {
351         char destdir[MAX_FILE_LEN];
352         char path[MAX_FILE_LEN];
353         char *type = NULL;
354         int ret = 0;
355
356         if (strlen (parent) + strlen (appid) + 2 >= MAX_FILE_LEN )
357         {
358                 DEBUG_ERROR("appid length is not available \n");
359                 return -1;
360         }
361
362         sprintf(destdir,"%s/%s",parent,appid);
363         ret = make_dir(destdir);
364         if (ret < 0)
365         {
366                 DEBUG_ERROR("make current directory %s is failed \n", destdir);
367                 goto FAIL;
368         }
369
370         if (strlen (rootpath) + 2 >= MAX_FILE_LEN )
371         {
372                 DEBUG_ERROR("rootpath length is not available \n");
373                 goto FAIL;
374         }
375
376         ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
377         if (ret < 0)
378         {
379                 DEBUG_ERROR("pkgmgrinfo_pkginfo_get_type is failed\n");
380                 goto FAIL;
381         }
382
383         sprintf(path,"%s/shared/res", rootpath);
384
385         if (!strcmp(type,"wgt"))
386         {
387                 char srcpath[MAX_FILE_LEN];
388                 sprintf(srcpath,"%s/res/wgt/shared/res", rootpath);
389                 ret = move_file(srcpath, path);
390         }
391
392         if (ret < 0)
393         {
394                 DEBUG_ERROR("move_file is failed\n");
395                 goto FAIL;
396         }
397
398         ret = symbolic_link(path, destdir);
399
400         if (ret < 0)
401         {
402                 DEBUG_ERROR("install is failed \n", destdir);
403                 goto FAIL;
404         }
405
406 #ifdef CHECK_FAMILY_NAME
407         ret = check_family_name(destdir);
408
409         if (ret < 0)
410         {
411                 DEBUG_ERROR("Invaid font files\n");
412                 goto FAIL;
413         }
414 #endif
415
416         return ret;
417
418 FAIL:
419         do_uninstall(destdir);
420         return -1;
421 }
422
423
424 static int do_uninstall(const char *deletedir)
425 {
426         DIR     *d;
427         struct dirent *e;
428
429         d = opendir(deletedir);
430         while((e = readdir (d)))
431         {
432                 if (e->d_name[0] != '.')
433                 {
434                         char destfile[MAX_FILE_LEN];
435                         struct stat       statb;
436
437                         if (strlen (deletedir) + strlen ((char *) e->d_name) + 2 >= MAX_FILE_LEN )
438                         {
439                                 DEBUG_ERROR("destfile length is not available \n");
440                                 goto FAIL;
441                         }
442
443                         sprintf(destfile,"%s/%s",deletedir,(char *) e->d_name);
444                         if (lstat (destfile, &statb) == -1)
445                         {
446                                 DEBUG_ERROR("lstat %s is failed \n",destfile);
447                                 goto FAIL;
448                         }
449
450                         if (S_ISDIR (statb.st_mode))
451                         {
452                                 if (do_uninstall(destfile)<0)
453                                         goto FAIL;
454                         }
455                         else if (unlink(destfile) < 0)
456                         {
457                                 DEBUG_ERROR("unlink is failed %s\n",destfile);
458                                 goto FAIL;
459                         }
460                         DEBUG_LOG("destfile =%s\n",destfile);
461                 }
462         }
463
464         closedir (d);
465
466         if (rmdir(deletedir) < 0)
467         {
468                 DEBUG_ERROR("rmdir is failed \n");
469                 return -1;
470         }
471
472         DEBUG_LOG("rmdir =%s\n",deletedir);
473         return 0;
474
475 FAIL:
476         closedir (d);
477         return -1;
478 }
479
480
481 int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
482 {
483         int ret;
484         pkgmgrinfo_pkginfo_h handle = NULL;
485         const char *app_root_path = NULL;
486         const char *dest_path = NULL;
487         uid_t uid = 0;
488
489         pkgmgr_installer_info_get_target_uid(&uid);
490         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
491
492         if (ret < 0)
493         {
494                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
495                 return -1;
496         }
497
498         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
499         if (ret < 0)
500         {
501                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
502                 goto FAIL;
503         }
504
505         if (appid == NULL)
506         {
507                 DEBUG_ERROR("appid is NULL \n");
508                 goto FAIL;
509         }
510
511         ret = make_dir(PARENT_PATH);
512
513         if (ret < 0)
514         {
515                 DEBUG_ERROR("make current directory is failed \n");
516                 goto FAIL;
517         }
518
519         dest_path = check_preloaded(app_root_path);
520
521         if (make_dir(dest_path)<0)
522         {
523                 DEBUG_ERROR("make current directory is failed \n");
524                 return -1;
525         }
526
527         ret = do_install(dest_path,appid, app_root_path, handle);
528         if (ret < 0)
529         {
530                 DEBUG_ERROR("font install is failed \n");
531                 goto FAIL;
532         }
533
534         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
535
536         return ret;
537
538 FAIL:
539         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
540         return -1;
541 }
542
543
544 int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
545 {
546         char deletedir[MAX_FILE_LEN];
547         int ret = 0;
548         pkgmgrinfo_pkginfo_h handle = NULL;
549         const char* app_root_path = NULL;
550         const char* dest_path = NULL;
551         uid_t uid = 0;
552
553         pkgmgr_installer_info_get_target_uid(&uid);
554         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
555
556         if (ret < 0)
557         {
558                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
559                 return -1;
560         }
561
562         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
563         if (ret < 0)
564         {
565                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
566                 goto FAIL;
567         }
568
569         if (appid == NULL)
570         {
571                 DEBUG_ERROR("appid is NULL \n");
572                 goto FAIL;
573         }
574
575         dest_path = check_preloaded(app_root_path);
576
577         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
578         {
579                 DEBUG_ERROR("appid length is not available \n");
580                 goto FAIL;
581         }
582
583         sprintf(deletedir,"%s/%s", dest_path, appid);
584
585         if (access(deletedir, F_OK) == -1)
586         {
587                 DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
588                 goto FAIL;
589         }
590
591         ret = do_uninstall(deletedir);
592         if (ret < 0)
593         {
594                 DEBUG_ERROR("do_uninstall is failed \n");
595                 goto FAIL;
596         }
597
598         ret = make_dir(PARENT_PATH);
599         if (ret < 0)
600         {
601                 DEBUG_ERROR("make current directory(%s) is failed: %s\n", PARENT_PATH, strerror(errno));
602                 goto FAIL;
603         }
604
605         ret = make_dir(dest_path);
606         if (ret < 0)
607         {
608                 DEBUG_ERROR("make current directory(%s) is failed: %s\n", dest_path, strerror(errno));
609                 goto FAIL;
610         }
611
612         ret = do_install(dest_path, appid, app_root_path, handle);
613         if (ret < 0)
614         {
615                 DEBUG_ERROR("do_install is failed \n");
616                 goto FAIL;
617         }
618
619         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
620         return ret;
621
622 FAIL:
623         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
624         return -1;
625 }
626
627
628
629 int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
630 {
631         char deletedir[MAX_FILE_LEN];
632         FcObjectSet *os = NULL;
633         FcPattern *pat = NULL;
634         FcFontSet *fs = NULL;
635         pkgmgrinfo_pkginfo_h handle = NULL;
636         const char* app_root_path = NULL;
637         const char *dest_path = NULL;
638         int ret;
639         uid_t uid = 0;
640
641         elm_init(0, NULL);
642
643         if (appid == NULL)
644         {
645                 DEBUG_ERROR("appid is NULL \n");
646                 return -1;
647         }
648
649         pkgmgr_installer_info_get_target_uid(&uid);
650         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
651
652         if (ret < 0)
653         {
654                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
655                 return -1;
656         }
657
658         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
659         if (ret < 0)
660         {
661                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
662                 goto FAIL;
663         }
664
665         dest_path = check_preloaded(app_root_path);
666
667         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
668         {
669                 DEBUG_ERROR("appid length is not available \n");
670                 goto FAIL;
671         }
672
673         sprintf(deletedir,"%s/%s", dest_path, appid);
674
675         //check if current using font is same with uninstall font
676         int deletedir_len = strlen(deletedir);
677
678         pat = FcPatternCreate();
679         if (pat == NULL)
680         {
681                 DEBUG_ERROR("FcPatternCreate is NULL \n");
682                 goto FAIL;
683         }
684
685         char *current_font_name = NULL;
686         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &current_font_name);
687         if (ret < 0)
688         {
689                 DEBUG_ERROR("Get current font is failed \n");
690                 goto FAIL;
691         }
692
693         DEBUG_LOG("current_font_name =%s\n",current_font_name);
694
695         FcInitLoadConfigAndFonts();
696         FcPatternAddString (pat, FC_FAMILY,(FcChar8*)current_font_name);
697         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
698         fs = FcFontList(NULL, pat, os);
699
700         FcPatternDestroy(pat);
701         free(current_font_name);
702
703         if (fs)
704         {
705                 int j;
706                 for (j = 0; j < fs->nfont; j++)
707                 {
708                         FcChar8 *file = NULL;
709                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
710                         {
711                                 DEBUG_LOG("file =%s\n",file);
712                                 if (strncmp((const char*)file , deletedir , deletedir_len) == 0 )
713                                 {
714                                         DEBUG_LOG("change to default font\n");
715                                         char *default_font_name = NULL;
716
717                                         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, &default_font_name);
718                                         if (ret < 0)
719                                         {
720                                                 DEBUG_ERROR("Get default font is failed \n");
721                                                 goto FAIL;
722                                         }
723
724                                         DEBUG_LOG("default_font_name = %s \n",default_font_name);
725                                         setenv("HOME", "/opt/home/app", 1);
726
727                                         ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, default_font_name);
728                                         if (ret < 0)
729                                         {
730                                                 DEBUG_ERROR("Set default font is failed ret=%d \n",ret);
731                                                 free(default_font_name);
732                                                 break;
733                                         }
734
735                                         char *elm_profile_path = (char*)elm_config_profile_dir_get(elm_config_profile_get(), EINA_TRUE);
736
737                                         setenv("HOME", "/root", 1);
738
739                                         ret = chown(ELM_PROFILE_CFG, APP_OWNER_ID, APP_GROUP_ID);
740                                         if (ret < 0)
741                                         {
742                                                 chmod (ELM_PROFILE_CFG, 0777);
743                                         }
744
745                                         DIR *d = NULL;
746                                         struct dirent *e;
747
748                                         if (elm_profile_path)
749                                                 d = opendir (elm_profile_path);
750
751                                         if (d)
752                                         {
753                                                 while ((e = readdir (d)))
754                                                 {
755                                                         if (e->d_name[0] != '.' &&  (strstr(e->d_name, ".cfg") != 0 || strstr(e->d_name, ".CFG") != 0))
756                                                         {
757                                                                 char file_full_path[100];
758
759                                                                 sprintf(file_full_path, "%s/%s", elm_profile_path, e->d_name);
760
761                                                                 ret = chown(file_full_path, APP_OWNER_ID, APP_GROUP_ID);
762                                                                 if (ret < 0)
763                                                                 {
764                                                                         DEBUG_LOG("chown is failed %s", file_full_path);
765                                                                         chmod (file_full_path, 0777);
766                                                                 }
767                                                         }
768                                                 }
769
770                                                 closedir (d);
771                                         }
772
773                                         free(default_font_name);
774                                         free(elm_profile_path);
775                                         DEBUG_LOG("success change to default font\n");
776                                         break;
777                                 }
778                         }
779                 }
780         }
781
782         if (access(deletedir, F_OK) == -1)
783         {
784                 DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
785                 goto FAIL;
786         }
787
788         elm_shutdown();
789         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
790
791         return do_uninstall(deletedir);
792
793 FAIL:
794         elm_shutdown();
795         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
796
797         return -1;
798 }
799
800 #if USE_META_DATA
801 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
802 {
803         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
804 }
805
806 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
807 {
808         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
809 }
810
811 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
812 {
813         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
814 }
815 #endif
816
817 int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
818 {
819         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
820 }
821
822 int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
823 {
824         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
825 }
826
827 int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
828 {
829         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
830 }
831
832
833 /* End of a file */