Modify the logic to support the virtual root
[platform/framework/native/installer.git] / src / Step / UninstallStep.cpp
index 236ddec..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;
@@ -126,19 +125,32 @@ UninstallStep::OnStateGetPackageInfo(void)
        std::unique_ptr< _PackageInfoImpl > pPackageInfoImpl(new (std::nothrow) _PackageInfoImpl());
        TryReturn(pPackageInfoImpl, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageInfoImpl is null.");
 
-       AppLog("packageId = %ls", packageId.GetPointer());
-       pPackageInfoImpl->Construct(packageId);
+       AppLog("package = %ls", packageId.GetPointer());
 
-       __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
-       if (__pContext->__rootPath.StartsWith(PATH_USR_APPS, 0) == true)
+       result r = pPackageInfoImpl->Construct(packageId);
+       TryReturn(r == E_SUCCESS, INSTALLER_ERROR_INTERNAL_STATE, "pPackageInfoImpl->Construct(%ls) failed.", packageId.GetPointer());
+
+//     bool isUninstallable = pPackageInfoImpl->IsUninstallable();
+//     if (isUninstallable == false)
+//     {
+//             __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 rwXmlPath;
+       rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer());
+       if (File::IsFileExist(rwXmlPath) == false)
        {
+               AppLog("This is a preload app = [%ls]", rwXmlPath.GetPointer());
                __pContext->__isPreloaded = true;
        }
 
+       __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
+
        if (__pContext->__isHybridService == true)
        {
                AppLog("Uninstallation for HybridService");
-               __state = STATE_DELETE_DIR;
+               __state = STATE_TERMINATE_APP;
                return error;
        }
 
@@ -183,7 +195,7 @@ UninstallStep::OnStateGetPackageInfo(void)
        }
        delete pList;
 
-       __state = STATE_DELETE_DIR;
+       __state = STATE_TERMINATE_APP;
 
        return error;
 }
@@ -203,6 +215,8 @@ UninstallStep::OnStateTerminateApp(void)
 {
        InstallerError error = INSTALLER_ERROR_NONE;
 
+       InstallerUtil::TerminateApps(__pContext->__packageId);
+
        GoNextState();
        return error;
 }
@@ -220,6 +234,7 @@ InstallerError
 UninstallStep::OnStateRemoveDir(void)
 {
        InstallerError error = INSTALLER_ERROR_NONE;
+       bool res = true;
 
        String rootPath;
        rootPath = __pContext->__rootPath;
@@ -231,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());
@@ -244,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)