Modify the logic to support the virtual root
[platform/framework/native/installer.git] / src / Step / UninstallStep.cpp
index 6b98ff9..b5d5a48 100755 (executable)
 #include <FIoDirectory.h>
 #include <FIo_FileImpl.h>
 #include <FBase_StringConverter.h>
-#include <FAppPkg_PackageManagerImpl.h>
 #include <FAppPkg_PackageInfoImpl.h>
-#include <FAppPkg_PackageAppInfoImpl.h>
 
 #include "InstallationContext.h"
 #include "UninstallStep.h"
 #include "InstallerUtil.h"
+#include "CompatibilityManager.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -137,25 +136,21 @@ UninstallStep::OnStateGetPackageInfo(void)
 //             __pContext->__additionalErrorString = L"Thrown when the application cannot be uninstalled because the application was preloaded.";
 //     }
 //     TryReturn(isUninstallable == true, INSTALLER_ERROR_PACKAGE_INVALID, "preload app cannot be uninstalled.");
-       String filePath = PATH_USR_APPS;
-       filePath += L"/";
-       filePath += __pContext->__packageId;
-       if (File::IsFileExist(filePath) == true)
+
+       String rwXmlPath;
+       rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer());
+       if (File::IsFileExist(rwXmlPath) == false)
        {
-               AppLog("This is a preload app=[%ls]", filePath.GetPointer());
+               AppLog("This is a preload app = [%ls]", rwXmlPath.GetPointer());
                __pContext->__isPreloaded = true;
        }
 
        __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
-//     if (__pContext->__rootPath.StartsWith(PATH_USR_APPS, 0) == true)
-//     {
-//             __pContext->__isPreloaded = true;
-//     }
 
        if (__pContext->__isHybridService == true)
        {
                AppLog("Uninstallation for HybridService");
-               __state = STATE_DELETE_DIR;
+               __state = STATE_TERMINATE_APP;
                return error;
        }
 
@@ -200,7 +195,7 @@ UninstallStep::OnStateGetPackageInfo(void)
        }
        delete pList;
 
-       __state = STATE_DELETE_DIR;
+       __state = STATE_TERMINATE_APP;
 
        return error;
 }
@@ -220,6 +215,8 @@ UninstallStep::OnStateTerminateApp(void)
 {
        InstallerError error = INSTALLER_ERROR_NONE;
 
+       InstallerUtil::TerminateApps(__pContext->__packageId);
+
        GoNextState();
        return error;
 }
@@ -237,6 +234,7 @@ InstallerError
 UninstallStep::OnStateRemoveDir(void)
 {
        InstallerError error = INSTALLER_ERROR_NONE;
+       bool res = true;
 
        String rootPath;
        rootPath = __pContext->__rootPath;
@@ -248,7 +246,7 @@ UninstallStep::OnStateRemoveDir(void)
        result r = GetLastResult();
        if (r == E_SUCCESS && ospCompat == true)
        {
-               if (_FileImpl::FinalizeDataCaging(rootPath) == false)
+               if (CompatibilityManager::FinalizeDataCaging(rootPath) == false)
                {
                        AppLog("[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls",
                                        rootPath.GetPointer());
@@ -261,6 +259,15 @@ UninstallStep::OnStateRemoveDir(void)
                return INSTALLER_ERROR_UNMOUNT_FAILED;
        }
 
+       CompatibilityManager::CleanDirectories(rootPath, __pContext->__packageId);
+
+       String virtualRoot = rootPath + DIR_VIRTUAL_ROOT;
+       if (File::IsFileExist(virtualRoot) == true)
+       {
+               res = CompatibilityManager::FinalizeVirtualRoot(rootPath, __pContext->__packageId);
+               TryReturn(res == true, INSTALLER_ERROR_UNMOUNT_FAILED, "CompatibilityManager::FinalizeVirtualRoot(%ls) failed.", rootPath.GetPointer());
+       }
+
        AppLog("Directory::Remove - START");
 
        if (__pContext->__isHybridService == true)