From: Dongeup Ham Date: Wed, 31 Oct 2012 11:41:54 +0000 (+0900) Subject: Implementation for preloaded app and downloaded app. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38b877649556347d2ecbb8e0db67a1ca8e883b7a;p=framework%2Fosp%2Finstaller.git Implementation for preloaded app and downloaded app. Change-Id: I2db52734a79969811a6d0f04d97838b4361ccfe3 --- diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index 7251021..2987372 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -21,21 +21,28 @@ #ifndef _INSTALLER_DEFS_H_ #define _INSTALLER_DEFS_H_ -#define DIR_BIN L"/bin" -#define DIR_INFO L"/info" -#define DIR_RES L"/res" -#define DIR_DATA L"/data" -#define DIR_ICONS L"/icons" -#define DIR_LIB L"/lib" -#define DIR_SETTING L"/setting" -#define DIR_CONTENTS L"/contents" - -#define SLP_DIR_BIN L"/bin" -#define SLP_DIR_RES L"/res" -#define SLP_DIR_DATA L"/data" -#define SLP_APP_PATH L"/opt/apps" - -#define SLP_FONT_PATH L"/opt/share/fonts" +#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/31_(7)" + +#define DIR_BIN L"/bin" +#define DIR_INFO L"/info" +#define DIR_RES L"/res" +#define DIR_DATA L"/data" +#define DIR_ICONS L"/icons" +#define DIR_LIB L"/lib" +#define DIR_SETTING L"/setting" +#define DIR_CONTENTS L"/contents" + +#define SLP_DIR_BIN L"/bin" +#define SLP_DIR_RES L"/res" +#define SLP_DIR_DATA L"/data" +#define SLP_APP_PATH L"/opt/apps" + +#define PATH_OPT_APPS L"/opt/apps" +#define PATH_USR_APPS L"/usr/apps" +#define PATH_OPT_USR L"/opt/usr" +#define PATH_OPT_USR_APPS L"/opt/usr/apps" + +#define SLP_FONT_PATH L"/opt/share/fonts" #define DIR_DESKTOP L"/opt/share/applications/%S.desktop" #define PACKAGE_NAME_PREFIX_ORG L"org.tizen." @@ -58,7 +65,7 @@ #define UIAPP_LOADER_PATH "/usr/lib/osp/osp-ui-app-loader" // UiApp #define SERVICEAPP_LOADER_PATH "/usr/lib/osp/osp-service-app-loader" // ServiceApp #define SYSTEMAPP_LOADER_PATH "/usr/lib/osp/osp-system-service-loader" // System Service -#define IME_PATH "/opt/apps/scim/lib/scim-1.0/1.4.0/Helper" +#define IME_PATH "/opt/apps/scim/lib/scim-1.0/1.4.0/Helper" #define APP_OWNER_ID 5000 #define APP_GROUP_ID 5000 @@ -69,16 +76,15 @@ #define TEST_ARG_COUNT 1 #define COMMAND_ARG_COUNT 3 -#define DIR_OSP_APPLICATIONS_TEMP L"/opt/apps/__@@osp_tmp@@__" +#define DIR_OSP_APPLICATIONS_TEMP L"/opt/usr/apps/__@@osp_tmp@@__" -#define DIR_RO_PACKAGE_SYSTEM_MANIFEST L"/usr/share/packages/%ls.xml" -#define DIR_RW_PACKAGE_SYSTEM_MANIFEST L"/opt/share/packages/%ls.xml" +#define DIR_RO_PACKAGE_SYSTEM_MANIFEST L"/usr/share/packages/%ls.xml" +#define DIR_RW_PACKAGE_SYSTEM_MANIFEST L"/opt/share/packages/%ls.xml" #define DIR_MEMORYCARD_OSP_APPLICATIONS L"/opt/storage/sdcard/apps" #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP L"/opt/storage/sdcard/apps/__@@osp_tmp@@__" #define OSP_INSTALLER "osp-installer" -#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/29" enum InstallationSetStep { diff --git a/src/Installer/DirectoryInstaller.cpp b/src/Installer/DirectoryInstaller.cpp index d891d82..6ca7f1a 100755 --- a/src/Installer/DirectoryInstaller.cpp +++ b/src/Installer/DirectoryInstaller.cpp @@ -77,6 +77,20 @@ DirectoryInstaller::OnInit(void) // remove in /info/*.info files RemoveInfoFiles(); + InstallationContext* pContext = GetContext(); + String installPath = pContext->GetInstallDir(); + + String newInstallPath; + + InstallerUtil::CreateSymlinkForAppId(installPath, newInstallPath); + pContext->SetInstallDir(newInstallPath); + + _PackageInfoImpl *pPackageInfoImpl = null; + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + pPackageInfoImpl->SetAppRootPath(newInstallPath); + + AppLogTag(OSP_INSTALLER, "installation path = [%ls]", newInstallPath.GetPointer()); + return Installer::OnInit(); } diff --git a/src/Installer/Installer.cpp b/src/Installer/Installer.cpp index 89c328c..30f79f2 100755 --- a/src/Installer/Installer.cpp +++ b/src/Installer/Installer.cpp @@ -22,12 +22,15 @@ #include #include +#include +#include #include #include #include "Installer.h" #include "PermissionManager.h" #include "ConfigurationManager.h" +#include "InstallerUtil.h" using namespace Osp::Base; using namespace Osp::Base::Collection; @@ -47,6 +50,28 @@ InstallerError Installer::Construct(InstallationContext* pContext) { __pContext = pContext; + + if (InstallerUtil::IsSymlink(PATH_OPT_APPS) == false) + { + if (File::IsFileExist(PATH_OPT_APPS) == false) + { + Directory::Create(PATH_OPT_APPS, false); + InstallerUtil::ChangeMode(PATH_OPT_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + } + + if (File::IsFileExist(PATH_OPT_USR) == false) + { + Directory::Create(PATH_OPT_USR, false); + InstallerUtil::ChangeMode(PATH_OPT_USR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + if (File::IsFileExist(PATH_OPT_USR_APPS) == false) + { + Directory::Create(PATH_OPT_USR_APPS, false); + InstallerUtil::ChangeMode(PATH_OPT_USR_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + return INSTALLER_ERROR_NONE; } diff --git a/src/Installer/PreloadedInstaller.cpp b/src/Installer/PreloadedInstaller.cpp index 7aee9da..b006c01 100755 --- a/src/Installer/PreloadedInstaller.cpp +++ b/src/Installer/PreloadedInstaller.cpp @@ -20,6 +20,9 @@ */ #include "PreloadedInstaller.h" +#include "InstallerUtil.h" + +using namespace Osp::Base; PreloadedInstaller::PreloadedInstaller(void) { @@ -40,6 +43,61 @@ InstallerError PreloadedInstaller::OnInit(void) { AppLogTag(OSP_INSTALLER, "PreloadedInstaller::OnInit()"); + + InstallationContext* pContext = GetContext(); + String path = pContext->GetInputPath(); + + String appId; + String prefix(PATH_USR_APPS); + prefix += L"/"; + + path.SubString(prefix.GetLength(), APPID_LENGTH, appId); + + String destRootPath(PATH_OPT_USR_APPS); + destRootPath += L"/"; + destRootPath += appId; + + InstallerUtil::Remove(destRootPath); + InstallerUtil::Remove(destRootPath); + + String srcPath; + String destPath; + + // /data + srcPath = path + DIR_DATA; + destPath = destRootPath + DIR_DATA; + InstallerUtil::CopyDirectory(srcPath, destPath); + + // /info + srcPath = path + DIR_INFO; + destPath = destRootPath + DIR_INFO; + InstallerUtil::CopyDirectory(srcPath, destPath); + + // appRoot - signature + + srcPath = path + DIR_BIN; + destPath = destRootPath + DIR_BIN; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_RES; + destPath = destRootPath + DIR_RES; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_LIB; + destPath = destRootPath + DIR_LIB; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_ICONS; + destPath = destRootPath + DIR_ICONS; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_SETTING; + destPath = destRootPath + DIR_SETTING; + InstallerUtil::CreateSymlink(srcPath, destPath); + + // pContext->SetInputPath(destRootPath); + pContext->SetInstallDir(destRootPath); + return DirectoryInstaller::OnInit(); } diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp index 2461095..153e9fe 100755 --- a/src/Manager/InstallerManager.cpp +++ b/src/Manager/InstallerManager.cpp @@ -71,9 +71,11 @@ InstallerManager::GetInstance() } InstallerError -InstallerManager::Construct(const String& path, InstallerType installerType, InstallerOperation operation, RequesterType requesterType, bool hybridService) +InstallerManager::Construct(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService) { InstallerError error = INSTALLER_ERROR_NONE; + InstallerType installerType = INSTALLER_TYPE_INSTALLER; + result r = E_SUCCESS; __pContext = new InstallationContext(); TryReturn(__pContext, INSTALLER_ERROR_MEMORY, "[osp-installer] __pContext is null."); @@ -81,41 +83,29 @@ InstallerManager::Construct(const String& path, InstallerType installerType, Ins error = __pContext->Construct(); TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pContext->Construct() failed."); - __pContext->SetInstallerOperation(operation); - - if (requesterType == REQUESTER_TYPE_PRELOADED) - { - __pContext->SetPreloaded(true); - } - - if (hybridService == true) - { - AppLogTag(OSP_INSTALLER, "Request to install HybridService app!"); - __pContext->SetHybridService(true); - } - - __pInstaller = CreateInstaller(installerType); - TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller is null."); - - if (installerType == INSTALLER_TYPE_DIRECTORY) - { - _PackageInfoImpl *pPackageInfoImpl = null; - - pPackageInfoImpl = __pContext->GetPackageInfoImpl(); - pPackageInfoImpl->SetAppRootPath(path); - - AppLogTag(OSP_INSTALLER, "path = [%ls]", path.GetPointer()); - } - + // 1. operation if (operation == INSTALLER_OPERATION_INSTALL) { - __pContext->SetInputPath(path); - __pContext->SetPackagePath(path); - __pContext->SetInstallDir(path); + FileAttributes attr; + r = File::GetAttributes(path, attr); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed"); + + if (attr.IsDirectory()) + { + installerType = INSTALLER_TYPE_DIRECTORY; + if (path.StartsWith(PATH_USR_APPS, 0) == true) + { + installerType = INSTALLER_TYPE_PRELOADED; + } - FileAttributes attribute; - result r = File::GetAttributes(path, attribute); - TryReturn(!IsFailed(r), INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] path is invalid. path=[%ls]", path.GetPointer()); + __pContext->SetInputPath(path); + __pContext->SetInstallDir(path); + } + else + { + installerType = INSTALLER_TYPE_PACKAGE; + __pContext->SetPackagePath(path); + } // org.tizen.* if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true) @@ -125,11 +115,31 @@ InstallerManager::Construct(const String& path, InstallerType installerType, Ins } else if (operation == INSTALLER_OPERATION_UNINSTALL) { + installerType = INSTALLER_TYPE_INSTALLER; + AppLogTag(OSP_INSTALLER, "operation is INSTALLER_OPERATION_UNINSTALL"); __pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL); __pContext->SetAppId(path); } + __pContext->SetInstallerOperation(operation); + + // 2. requesterType + if (requesterType == REQUESTER_TYPE_PRELOADED) + { + __pContext->SetPreloaded(true); + } + + // 3. hybridService + if (hybridService == true) + { + AppLogTag(OSP_INSTALLER, "Request to install HybridService app!"); + __pContext->SetHybridService(true); + } + + __pInstaller = CreateInstaller(installerType); + TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller is null."); + error = __pInstaller->Construct(__pContext); TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller->Construct() failed"); @@ -307,7 +317,6 @@ InstallerManager::GetContext(void) int InstallerManager::Request(const String& path, InstallerOperation operation, RequesterType requesterType, String& appid, int& errorType, bool hybridService) { - InstallerType type = INSTALLER_TYPE_INSTALLER; InstallationContext* pContext = null; InstallerError error = INSTALLER_ERROR_NONE; InstallerManager* pInstallManager = null; @@ -319,30 +328,10 @@ InstallerManager::Request(const String& path, InstallerOperation operation, Requ AppLogTag(OSP_INSTALLER, "# path = [%ls]", path.GetPointer()); AppLogTag(OSP_INSTALLER, "------------------------------------------"); - if (operation == INSTALLER_OPERATION_INSTALL) - { - FileAttributes attr; - result r = File::GetAttributes(path, attr); - TryCatch(!IsFailed(r), error = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed"); - - if (attr.IsDirectory()) - { - type = INSTALLER_TYPE_DIRECTORY; - } - else - { - type = INSTALLER_TYPE_PACKAGE; - } - } - else if (operation == INSTALLER_OPERATION_UNINSTALL) - { - type = INSTALLER_TYPE_INSTALLER; - } - pInstallManager = InstallerManager::GetInstance(); TryCatch(pInstallManager, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pInstallManager is null."); - error = pInstallManager->Construct(path, type, operation, requesterType, hybridService); + error = pInstallManager->Construct(path, operation, requesterType, hybridService); TryCatch(error == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Construct() failed."); error = pInstallManager->Activate(); diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h index b00f8c6..77eb604 100755 --- a/src/Manager/InstallerManager.h +++ b/src/Manager/InstallerManager.h @@ -38,7 +38,7 @@ class InstallerManager { public: InstallerManager(void); - InstallerError Construct(const Osp::Base::String& path, InstallerType installerType, InstallerOperation op, RequesterType requesterType, bool hybridService = false); + InstallerError Construct(const Osp::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); virtual ~InstallerManager(void); static InstallerManager* GetInstance(void); diff --git a/src/Manager/PermissionManager.cpp b/src/Manager/PermissionManager.cpp index 676f04f..a4dd107 100755 --- a/src/Manager/PermissionManager.cpp +++ b/src/Manager/PermissionManager.cpp @@ -49,105 +49,93 @@ PermissionManager::~PermissionManager(void) { } -bool -PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth) -{ - Directory* pDir = null; - DirEnumerator* pDirEnum = null; - result r = E_SUCCESS; - result res = false; - - pDir = new Directory; // Allocate %Directory instance - TryCatch(pDir, res = false, "[osp-installer] pDir is null"); - - r = pDir->Construct(rootPath); - TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, rootPath=[%ls]", rootPath.GetPointer()); - - pDirEnum = pDir->ReadN(); - TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); - - while (pDirEnum->MoveNext() == E_SUCCESS) - { - DirEntry entry = pDirEnum->GetCurrentDirEntry(); - - String entryName = entry.GetName(); - String entryDir = rootPath; - entryDir += L"/"; - entryDir += entryName; - - if (entryName == L".") - { - InstallerUtil::ChangeOwner(entryDir); - InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); - continue; - } - else if (entryName == L"..") - { - // if (depth != 0) - // { - // ChangeOwner(entryDir); - // } - - continue; - } - - if (entry.IsDirectory() == false) - { - InstallerUtil::ChangeOwner(entryDir); - InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); - } - else - { - ChangeHomeDirectoryOwner(entryDir, depth+1); - InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); - } - } - - delete pDir; - pDir = null; - return true; - -CATCH: - delete pDir; - return false; -} - - -bool -PermissionManager::ApplyHomeDirectoryPolicy(const String& rootPath) -{ - String dataPath; - //char* pDataPath = null; - //int res = -1; - - dataPath = rootPath; - dataPath += DIR_DATA; - - AppLogTag(OSP_INSTALLER, "ApplyHomeDirectoryPolicy [%ls]", dataPath.GetPointer()); - - if (File::IsFileExist(dataPath) == false) - { - result r = E_SUCCESS; - r = Directory::Create(dataPath, false); - TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); - } -// else +//bool +//PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth) +//{ +// Directory* pDir = null; +// DirEnumerator* pDirEnum = null; +// result r = E_SUCCESS; +// result res = false; +// +// pDir = new Directory; // Allocate %Directory instance +// TryCatch(pDir, res = false, "[osp-installer] pDir is null"); +// +// r = pDir->Construct(rootPath); +// TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, rootPath=[%ls]", rootPath.GetPointer()); +// +// pDirEnum = pDir->ReadN(); +// TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); +// +// while (pDirEnum->MoveNext() == E_SUCCESS) // { -// if (File::IsFileExist(dataPath) == true) +// DirEntry entry = pDirEnum->GetCurrentDirEntry(); +// +// String entryName = entry.GetName(); +// String entryDir = rootPath; +// entryDir += L"/"; +// entryDir += entryName; +// +// if (entryName == L".") +// { +// InstallerUtil::ChangeOwner(entryDir); +// InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); +// continue; +// } +// else if (entryName == L"..") +// { +// // if (depth != 0) +// // { +// // ChangeOwner(entryDir); +// // } +// +// continue; +// } +// +// if (entry.IsDirectory() == false) // { -// AppLogTag(OSP_INSTALLER, "ApplyHomeDirectoryPolicy [%ls] is removed.", dataPath.GetPointer()); -// pDataPath = _StringConverter::CopyToCharArrayN(dataPath); -// remove(pDataPath); -// delete[] pDataPath; -// pDataPath = null; +// InstallerUtil::ChangeOwner(entryDir); +// InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); +// } +// else +// { +// ChangeHomeDirectoryOwner(entryDir, depth+1); +// InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); // } // } - - ChangeHomeDirectoryOwner(dataPath, 0); - InstallerUtil::ChangeMode(dataPath, S_IRUSR | S_IWUSR | S_IXUSR); - - return true; -} +// +// delete pDir; +// pDir = null; +// return true; +// +//CATCH: +// delete pDir; +// return false; +//} + +//bool +//PermissionManager::ApplyHomeDirectoryPolicy(const String& rootPath) +//{ +// String dataPath; +// //char* pDataPath = null; +// //int res = -1; +// +// dataPath = rootPath; +// dataPath += DIR_DATA; +// +// AppLogTag(OSP_INSTALLER, "ApplyHomeDirectoryPolicy [%ls]", dataPath.GetPointer()); +// +// if (File::IsFileExist(dataPath) == false) +// { +// result r = E_SUCCESS; +// r = Directory::Create(dataPath, false); +// TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); +// } +// +// ChangeHomeDirectoryOwner(dataPath, 0); +// InstallerUtil::ChangeMode(dataPath, S_IRUSR | S_IWUSR | S_IXUSR); +// +// return true; +//} bool PermissionManager::SetDirectory(InstallationContext* pContext) @@ -166,7 +154,7 @@ PermissionManager::SetDirectory(InstallationContext* pContext) InstallerUtil::ChangeOwner(appRootPath); InstallerUtil::ChangeMode(appRootPath, S_IRUSR | S_IXUSR); - // appRoot/bin(no permission for app) + // appRoot/bin(rx for app) destPath = appRootPath + DIR_BIN; InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); @@ -274,19 +262,8 @@ PermissionManager::SetFile(InstallationContext* pContext) if (pAppInfoImpl) { // set permission(755) to bin file. - // sprintf(destPath, "%ls%ls/%ls", appRootPath.GetPointer(), DIR_BIN, (pAppInfoImpl->GetName()).GetPointer()); - // strcat(destPath, ".exe"); destPath = appRootPath + DIR_BIN + L"/" + pAppInfoImpl->GetName() + L".exe"; InstallerUtil::ChangeMode(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - // res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); -// if (res != 0) -// { -// AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); -// } -// else -// { -// AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); -// } } } diff --git a/src/Manager/PermissionManager.h b/src/Manager/PermissionManager.h index e47e728..402a5ba 100755 --- a/src/Manager/PermissionManager.h +++ b/src/Manager/PermissionManager.h @@ -44,8 +44,8 @@ public: private: // static bool ChangeOwner(const Osp::Base::String& filePath); - static bool ChangeHomeDirectoryOwner(const Osp::Base::String&, int depth); - static bool ApplyHomeDirectoryPolicy(const Osp::Base::String& rootpath); + // static bool ChangeHomeDirectoryOwner(const Osp::Base::String&, int depth); + // static bool ApplyHomeDirectoryPolicy(const Osp::Base::String& rootpath); // static bool ChangeMode(const Osp::Base::String& filePath, int mode); static bool CreateSystemDirectory(InstallationContext* pContext, const Osp::Base::String& rootpath); static bool SetSymLink(InstallationContext* pContext); diff --git a/src/Step/UnpackStep.cpp b/src/Step/UnpackStep.cpp index f79feba..10ee8c5 100755 --- a/src/Step/UnpackStep.cpp +++ b/src/Step/UnpackStep.cpp @@ -27,6 +27,7 @@ #include "InstallationContext.h" #include "UnpackStep.h" +#include "InstallerUtil.h" using namespace Osp::Base; using namespace Osp::Base::Utility; @@ -109,7 +110,6 @@ UnpackStep::GoNextState(void) InstallerError UnpackStep::OnUnzip(void) { - // String tempDir; InstallerError error = INSTALLER_ERROR_NONE; AppLogTag(OSP_INSTALLER, "OnUnzip()"); _PackageInfoImpl *pPackageInfoImpl = null; @@ -179,7 +179,7 @@ UnpackStep::OnUnzip(void) #endif String installPath; - installPath = SLP_APP_PATH; + installPath = PATH_OPT_USR_APPS; installPath += "/"; if (__pContext->GetPackageNameType() == INSTALLER_PREFIX_TYPE_ORG) @@ -188,22 +188,25 @@ UnpackStep::OnUnzip(void) } installPath += __pContext->GetAppId(); - __pContext->SetInstallDir(installPath); if (File::IsFileExist(installPath) == false) { result r = E_SUCCESS; r = Directory::Create(installPath, false); - TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed, installPath=%ls", installPath.GetPointer()); } + String newInstallPath; + InstallerUtil::CreateSymlinkForAppId(installPath, newInstallPath); + __pContext->SetInstallDir(newInstallPath); + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); - pPackageInfoImpl->SetAppRootPath(installPath); + pPackageInfoImpl->SetAppRootPath(newInstallPath); AppLogTag(OSP_INSTALLER, "UnzipTo - START"); FileUnzipper unzipper; unzipper.Construct(__pContext->GetPackagePath()); - unzipper.UnzipTo(installPath); + unzipper.UnzipTo(newInstallPath); AppLogTag(OSP_INSTALLER, "UnzipTo - END"); // GoNextState(); diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index a6ba9e2..325231c 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -116,6 +116,80 @@ InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath) } bool +InstallerUtil::CopyDirectory(const String& srcFilePath, const String& destFilePath) +{ + result r = E_SUCCESS; + + std::unique_ptr pDir(new Directory); + TryReturn(pDir, false, "[osp-installer] pDir is null."); + + r = pDir->Construct(srcFilePath); + TryReturn(!IsFailed(r), false, "[osp-installer] pDir->Construct() failed, srcFilePath=[%ls].", srcFilePath.GetPointer()); + + std::unique_ptr pDirEnum(pDir->ReadN()); + TryReturn(pDirEnum, false, "[osp-installer] pDirEnum is null."); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String srcEntryDir = srcFilePath; + srcEntryDir += L"/"; + srcEntryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + // if file or directory is symbolic link, skip this. + if (InstallerUtil::IsSymlink(srcEntryDir) == true) + { + continue; + } + + String destEntryDir = destFilePath; + destEntryDir += L"/"; + destEntryDir += entryName; + + if (entry.IsDirectory() == false) + { + // file + Directory::Create(destFilePath, true); + InstallerUtil::Copy(srcEntryDir, destEntryDir); + } + else + { + Directory::Create(destEntryDir, true); + CopyDirectory(srcEntryDir, destEntryDir); + } + } + + return true; +} + +bool +InstallerUtil::IsSymlink(const Osp::Base::String& filePath) +{ + int err = -1; + struct stat fileinfo; + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + err = lstat(pFilePath.get(), &fileinfo); + TryReturn(err >= 0, false, "[osp-installer] lstat() failed, filepath=%s", pFilePath.get()); + + if (S_ISLNK(fileinfo.st_mode)) + { + return true; + } + + return false; +} + +bool InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath) { int err = -1; @@ -268,3 +342,35 @@ InstallerUtil::GetCategoryType(char* pCategory) return category; } + +bool +InstallerUtil::CreateSymlinkForAppId(const String& inPath, String& outPath) +{ + if (InstallerUtil::IsSymlink(PATH_OPT_APPS) == true && + inPath.StartsWith(PATH_OPT_USR_APPS, 0) == true) + { + outPath = inPath; + return false; + } + + String appId; + int length = inPath.GetLength(); + inPath.SubString(length - APPID_LENGTH, APPID_LENGTH, appId); + + String newPath; + newPath = PATH_OPT_APPS; + newPath += L"/"; + newPath += appId; + + if (inPath == newPath) + { + outPath = inPath; + return false; + } + + InstallerUtil::CreateSymlink(inPath, newPath); + + outPath = newPath; + + return true; +} diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index 245fcce..5733386 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -42,8 +42,12 @@ public: InstallerUtil(void); virtual ~InstallerUtil(void); + static bool CreateSymlinkForAppId(const Osp::Base::String& inPath, Osp::Base::String& outPath); + static bool Remove(const Osp::Base::String& filePath); static bool Copy(const Osp::Base::String& srcFilePath, const Osp::Base::String& destFilePath); + static bool CopyDirectory(const Osp::Base::String& srcFilePath, const Osp::Base::String& destFilePath); + static bool IsSymlink(const Osp::Base::String& filePath); static bool CreateSymlink(const Osp::Base::String& oldPath, const Osp::Base::String& newPath); static bool ChangeMode(const Osp::Base::String& filePath, int mode);