add prelaod-rw installation to preload installation tool. 12/99012/4 accepted/tizen/3.0/common/20161125.101804 accepted/tizen/3.0/ivi/20161125.081944 accepted/tizen/3.0/mobile/20161125.081649 accepted/tizen/3.0/tv/20161125.081805 accepted/tizen/3.0/wearable/20161125.081908 submit/tizen_3.0/20161124.130849
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 21 Nov 2016 12:02:31 +0000 (21:02 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Thu, 24 Nov 2016 13:01:25 +0000 (05:01 -0800)
Change-Id: I29a56bc8aa3fb66cb14831317d9a7e21761ef23c
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/install_preload_pkg.c

index ea797ca..bd8ddb0 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <unistd.h>
 #define WGT_BACKEND_CMD "/usr/bin/wgt-backend"
 #define TPK_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk")
 #define WGT_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-wgt")
+#define TPK_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-tpk")
+#define WGT_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
 
-static int _install_preload_pkg(const char *backend, const char *directory)
+static int _install_preload_pkg(const char *backend, const char *directory,
+               bool readonly)
 {
        DIR *dir;
        struct dirent file_info, *result;
@@ -86,7 +90,8 @@ static int _install_preload_pkg(const char *backend, const char *directory)
                pid_t pid = fork();
                if (pid == 0) {
                        execl(backend, backend, "-i", file_path,
-                               "--preload", (char *)NULL);
+                               readonly? "--preload":"--preload-rw",
+                               (char *)NULL);
                } else if (pid < 0) {
                        _E("failed to fork and execute %s!", backend);
                        closedir(dir);
@@ -99,13 +104,16 @@ static int _install_preload_pkg(const char *backend, const char *directory)
                }
 
                /* remove a file after installation */
-               ret = remove(file_path);
-               if (ret < 0) {
-                       _E("Failed to remove the file [%s] because [%s]",
-                               file_path, strerror_r(errno, err_buf,
-                               sizeof(err_buf)));
-                       closedir(dir);
-                       return -1;
+               /* keep rw packages for factory-reset */
+               if (readonly) {
+                       ret = remove(file_path);
+                       if (ret < 0) {
+                               _E("Failed to remove the file [%s] because [%s]",
+                                       file_path, strerror_r(errno, err_buf,
+                                       sizeof(err_buf)));
+                               closedir(dir);
+                               return -1;
+                       }
                }
        }
 
@@ -134,10 +142,16 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR) < 0)
+       if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true) < 0)
+               goto error;
+
+       if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true) < 0)
+               goto error;
+
+       if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false) < 0)
                goto error;
 
-       if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR) < 0)
+       if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false) < 0)
                goto error;
 
        return 0;