Revert "Refactor duplicate codes as a function to reuse them" 25/109525/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 10 Jan 2017 08:55:17 +0000 (17:55 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 10 Jan 2017 08:55:21 +0000 (17:55 +0900)
This reverts commit a9899cecfa471b1fdb8bdb611242817d5623b340.

Change-Id: I2ae91cac4bd8f9a6b20880e48960bb0c840df804

plugin/app2sd/server/app2sd_interface.c

index 213a284..40e2cf8 100644 (file)
@@ -46,69 +46,6 @@ static int __app2sd_create_app2sd_directories(uid_t uid, char *mmc_path)
        return APP2EXT_SUCCESS;
 }
 
-static int __app2sd_finalize_device_setup(const char *pkgid,
-       const char *loopback_device, const char *application_path,
-       uid_t uid)
-{
-       char *device_node = NULL;
-       int ret = APP2EXT_SUCCESS;
-
-#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
-       device_node =
-               _app2sd_find_associated_dmcrypt_device_node(pkgid, uid);
-       if (!device_node) {
-               _E("failed to find device node");
-               return APP2EXT_ERROR_FIND_ASSOCIATED_DMCRYPT_DEVICE_NODE;
-       }
-#else
-       device_node = _app2sd_find_associated_device_node(loopback_device);
-       if (NULL == device_node) {
-               _E("failed to find device node");
-               return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
-       }
-#endif
-
-       ret = _app2sd_unmount_app_content(application_path);
-       if (ret) {
-               if (device_node) {
-                       free(device_node);
-                       device_node = NULL;
-               }
-               _E("unable to unmount the app content (%d)", ret);
-               return APP2EXT_ERROR_UNMOUNT;
-       }
-
-#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
-       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
-       if (ret) {
-               if (device_node) {
-                       free(device_node);
-                       device_node = NULL;
-               }
-               _E("close dmcrypt device error(%d)", ret);
-               return ret;
-       }
-#else
-       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
-       if (ret) {
-               if (device_node) {
-                       free(device_node);
-                       device_node = NULL;
-               }
-               _E("unable to detach the loopback encryption setup" \
-                       " for the application");
-               return APP2EXT_ERROR_UNMOUNT;
-       }
-#endif
-
-       if (device_node) {
-               free(device_node);
-               device_node = NULL;
-       }
-
-       return ret;
-}
-
 int app2sd_usr_pre_app_install(const char *pkgid, GList *dir_list, int size, uid_t uid)
 {
        int ret = 0;
@@ -284,6 +221,7 @@ END:
 int app2sd_usr_post_app_install(const char *pkgid,
                app2ext_status install_status, uid_t uid)
 {
+       char *device_name = NULL;
        char *sdpath = NULL;
        char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
@@ -328,13 +266,58 @@ int app2sd_usr_post_app_install(const char *pkgid,
                tzplatform_reset_user();
        }
        free(encoded_id);
+       snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+               application_path);
+
+       /* get the associated device node for SD card applicationer */
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       device_name =
+               _app2sd_find_associated_dmcrypt_device_node(pkgid, uid);
+       if (!device_name)
+               return APP2EXT_ERROR_FIND_ASSOCIATED_DMCRYPT_DEVICE_NODE;
+#else
+       device_name = _app2sd_find_associated_device_node(loopback_device);
+       if (NULL == device_name)
+               return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
+#endif
 
-       ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
-               application_path, uid);
+       ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
-               _E("failed to finalize device setup");
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("unable to unmount the app content (%d)", ret);
+               return APP2EXT_ERROR_UNMOUNT;
+       }
+
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
+       if (ret) {
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("close dmcrypt device error(%d)", ret);
                return ret;
        }
+#else
+       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
+       if (ret) {
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("unable to detach the loopback encryption setup" \
+                       " for the application");
+               return APP2EXT_ERROR_UNMOUNT;
+       }
+#endif
+
+       if (device_name) {
+               free(device_name);
+               device_name = NULL;
+       }
 
        /* take appropriate action based on
         * installation status of application package
@@ -350,8 +333,6 @@ int app2sd_usr_post_app_install(const char *pkgid,
                if (ret)
                        _E("unable to delete info");
 
-               snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
-                       application_path);
                ret = _app2sd_delete_directory(application_mmc_path);
                if (ret)
                        _E("unable to delete the directory (%s)", application_path);
@@ -600,13 +581,24 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
                fclose(fp);
        }
 
-       ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
-               application_path, uid);
+       ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
-               _E("failed to finalize device setup");
-               return ret;
+               _E("unable to unmount the SD application");
+               return APP2EXT_ERROR_UNMOUNT;
        }
 
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
+       if (ret)
+               _E("close dmcrypt device error(%d)", ret);
+#else
+       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
+       if (ret) {
+               _E("unable to remove loopback setup");
+               return APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE;
+       }
+#endif
+
        return ret;
 }
 
@@ -776,13 +768,34 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
+       snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+               application_path);
 
-       ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
-               application_path, uid);
+       /* unmount the loopback encrypted pseudo device from
+        * the application installation path
+        */
+       ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
-               _E("failed to finalize device setup");
-               return ret;
+               _E("unable to unmount the app content (%d)", ret);
+               ret = APP2EXT_ERROR_UNMOUNT;
+               goto END;
        }
+       /* detach the loopback encryption setup for the application */
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
+       if (ret) {
+               _E("close dmcrypt device error(%d)", ret);
+               goto END;
+       }
+#else
+       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
+       if (ret) {
+               _E("unable to Detach the loopback encryption setup" \
+                       " for the application");
+               ret = APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE;
+               goto END;
+       }
+#endif
 
        /* delete the loopback device from the SD card */
        ret = _app2sd_delete_loopback_device(loopback_device);
@@ -793,8 +806,6 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
                goto END;
        }
 
-       snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
-               application_path);
        ret = _app2sd_delete_directory(application_mmc_path);
        if (ret) {
                _E("unable to delete the directory (%s)",
@@ -940,12 +951,20 @@ int app2sd_usr_post_move_installed_app(const char *pkgid,
                tzplatform_reset_user();
        }
 
-       ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
-               application_path, uid);
-       if (ret) {
-               _E("failed to finalize device setup");
-               return ret;
-       }
+       ret = _app2sd_unmount_app_content(application_path);
+       if (ret)
+               _E("unmount error (%d)", ret);
+
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
+       if (ret)
+               _E("close dmcrypt device error(%d)", ret);
+#else
+       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
+       if (ret)
+               _E("unable to detach loopback setup for (%s)",
+                       loopback_device);
+#endif
 
        sync();
        return APP2EXT_SUCCESS;
@@ -1174,6 +1193,7 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char *sdpath = NULL;
+       char *device_name = NULL;
        char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
        int pkgmgr_ret = 0;
@@ -1214,13 +1234,54 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        }
        free(encoded_id);
 
-       ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
-               application_path, uid);
+       /* get the associated device node for SD card applicationer */
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       device_name =
+               _app2sd_find_associated_dmcrypt_device_node(pkgid, uid);
+       if (!device_name) {
+               _E("could not find associated dmcrypt device node" \
+                       " (%s_%d)", pkgid, uid);
+               return APP2EXT_ERROR_FIND_ASSOCIATED_DMCRYPT_DEVICE_NODE;
+       }
+#else
+       device_name = _app2sd_find_associated_device_node(loopback_device);
+       if (NULL == device_name)
+               return APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE;
+#endif
+
+       ret = _app2sd_unmount_app_content(application_path);
        if (ret) {
-               _E("failed to finalize device setup");
-               return ret;
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("unable to unmount the app content (%d)", ret);
+               return APP2EXT_ERROR_UNMOUNT;
        }
 
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+       ret = _app2sd_dmcrypt_close_device(pkgid, uid);
+       if (ret) {
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("close dmcrypt device error(%d)", ret);
+               return APP2EXT_ERROR_CLOSE_DMCRYPT_DEVICE;
+       }
+#else
+       ret = _app2sd_remove_loopback_encryption_setup(loopback_device);
+       if (ret) {
+               if (device_name) {
+                       free(device_name);
+                       device_name = NULL;
+               }
+               _E("unable to detach the loopback encryption " \
+                       "setup for the application");
+               return APP2EXT_ERROR_UNMOUNT;
+       }
+#endif
+
        pkgmgr_ret = pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid,
                INSTALL_EXTERNAL, loopback_device, uid);
        if (pkgmgr_ret < 0) {
@@ -1230,6 +1291,11 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
                return APP2EXT_ERROR_PKGMGR_ERROR;
        }
 
+       if (device_name) {
+               free(device_name);
+               device_name = NULL;
+       }
+
        sync();
        return ret;
 }