From: Soyoung Kim Date: Thu, 22 Nov 2012 02:27:15 +0000 (+0900) Subject: arrangement of directory creation. X-Git-Tag: submit/trunk/20121205.083813~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=908de059d18e3f04cc67ef6fb1c8c22c1aaddbb0;p=platform%2Fframework%2Fweb%2Fwrt-installer.git arrangement of directory creation. [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] creation of private storage directory move to file manifacture task from task_private_storage. [SCMRequest] N/A Change-Id: I11ce837f3b45d78e8abeafe1ade4e1545ed2f7d8 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 665095d..9cfd43e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -71,7 +71,6 @@ SET(INSTALLER_SOURCES ${INSTALLER_JOBS}/widget_install/task_ace_check.cpp ${INSTALLER_JOBS}/widget_install/task_manifest_file.cpp ${INSTALLER_JOBS}/widget_install/task_certify.cpp - ${INSTALLER_JOBS}/widget_install/task_private_storage.cpp ${INSTALLER_JOBS}/widget_install/task_prepare_files.cpp ${INSTALLER_JOBS}/widget_install/task_recovery.cpp ${INSTALLER_JOBS}/widget_install/task_install_ospsvc.cpp diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index ef7fbe4..bd81286 100644 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -60,7 +60,6 @@ #include #include #include -#include #include #include #include @@ -192,8 +191,6 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, AddTask(new TaskFileManipulation(m_installerContext)); // TODO: Update progress information for this task - AddTask(new TaskPrivateStorage(m_installerContext)); - //This is sort of quick solution, because ACE verdicts are based upon //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate //task. diff --git a/src/jobs/widget_install/task_file_manipulation.cpp b/src/jobs/widget_install/task_file_manipulation.cpp index 2bd896b..2a1400d 100644 --- a/src/jobs/widget_install/task_file_manipulation.cpp +++ b/src/jobs/widget_install/task_file_manipulation.cpp @@ -30,6 +30,13 @@ #include #include +#define WEBAPP_DEFAULT_UID 5000 +#define WEBAPP_DEFAULT_GID 5000 + +namespace { +const mode_t PRIVATE_STORAGE_MODE = 0700; +} + using namespace WrtDB; namespace Jobs { @@ -39,6 +46,7 @@ TaskFileManipulation::TaskFileManipulation(InstallerContext& context) : m_context(context) { AddStep(&TaskFileManipulation::StepCreateDirs); + AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir); AddStep(&TaskFileManipulation::StepRenamePath); AddAbortStep(&TaskFileManipulation::StepAbortRenamePath); @@ -59,11 +67,6 @@ void TaskFileManipulation::StepCreateDirs() WrtUtilMakeDir(widgetPath); - if (m_context.job->getInstallerStruct().m_preload) { - std::string privateDir = m_context.locations->getBasePrivateDir(); - WrtUtilMakeDir(privateDir); - } - // If package type is widget with osp service, we don't need to make bin // and src directory if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) { @@ -79,6 +82,48 @@ void TaskFileManipulation::StepCreateDirs() "Widget Directory Created"); } +void TaskFileManipulation::StepCreatePrivateStorageDir() +{ + std::string storagePath = m_context.locations->getPrivateStorageDir(); + + if (euidaccess(storagePath.c_str(), F_OK) != 0) { + if(!WrtUtilMakeDir(storagePath, PRIVATE_STORAGE_MODE)){ + LogError("Failed to create directory for private storage"); + ThrowMsg(Exceptions::InternalError, + "Failed to create directory for private storage"); + } + // '5000' is default uid, gid for applications. + // So installed applications should be launched as process of uid '5000'. + // the process can access private directory 'data' of itself. + if(chown(storagePath.c_str(), + WEBAPP_DEFAULT_UID, + WEBAPP_DEFAULT_GID) != 0) + { + ThrowMsg(Exceptions::InternalError, + "Chown to invaild user"); + } + } else if (euidaccess(storagePath.c_str(), W_OK | R_OK | X_OK) == 0) { + LogInfo("Private storage already exists."); + // Even if private directory already is created, private dircetory + // should change owner. + if(chown(storagePath.c_str(), + WEBAPP_DEFAULT_UID, + WEBAPP_DEFAULT_GID) != 0) + { + ThrowMsg(Exceptions::InternalError, + "Chown to invaild user"); + } + if(chmod(storagePath.c_str(), PRIVATE_STORAGE_MODE) != 0) { + ThrowMsg(Exceptions::InternalError, + "chmod to 0700"); + } + + } else { + ThrowMsg(Exceptions::InternalError, + "No access to private storage."); + } +} + void TaskFileManipulation::StepRenamePath() { std::string instDir; diff --git a/src/jobs/widget_install/task_file_manipulation.h b/src/jobs/widget_install/task_file_manipulation.h index 162dbbf..429b0fb 100644 --- a/src/jobs/widget_install/task_file_manipulation.h +++ b/src/jobs/widget_install/task_file_manipulation.h @@ -36,6 +36,7 @@ class TaskFileManipulation : void StepCreateDirs(); void StepRenamePath(); + void StepCreatePrivateStorageDir(); void StepAbortRenamePath(); diff --git a/src/jobs/widget_install/task_private_storage.cpp b/src/jobs/widget_install/task_private_storage.cpp deleted file mode 100644 index 853db0a..0000000 --- a/src/jobs/widget_install/task_private_storage.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file installer_task_private_storage.cpp - * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) - * @version 1.0 - * @brief Implementation file for installer task private storage. - */ -#include "task_private_storage.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#define WEBAPP_DEFAULT_UID 5000 -#define WEBAPP_DEFAULT_GID 5000 - -namespace { -const mode_t PRIVATE_STORAGE_MODE = 0700; -} - -namespace Jobs { -namespace WidgetInstall { -TaskPrivateStorage::TaskPrivateStorage(InstallerContext& context) : - DPL::TaskDecl(this), - m_context(context) -{ - AddStep(&TaskPrivateStorage::StepCreateDirectory); -} - -void TaskPrivateStorage::StepCreateDirectory() -{ - using namespace WrtDB; - - LogInfo("Step: Creating private storage directory."); - - m_context.installStep = - InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE; - - std::ostringstream widgetDataPath; - DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; - if(!pkgname.IsNull()) { - widgetDataPath << m_context.locations->getBasePrivateDir() << "/"; - } else { - ThrowMsg(Exceptions::InternalError, "No Package name exists."); - } - - if (euidaccess(widgetDataPath.str().c_str(), W_OK | X_OK) != 0) { - ThrowMsg(Exceptions::InternalError, DPL::GetErrnoString()); - } - - std::ostringstream storagePath; - storagePath << widgetDataPath.str().c_str() - << GlobalConfig::GetWidgetPrivateStoragePath(); - - if (euidaccess(storagePath.str().c_str(), F_OK) != 0) { - if(!WrtUtilMakeDir(storagePath.str(), PRIVATE_STORAGE_MODE)){ - LogError("Failed to create directory for private storage"); - ThrowMsg(Exceptions::InternalError, - "Failed to create directory for private storage"); - } - // '5000' is default uid, gid for applications. - // So installed applications should be launched as process of uid '5000'. - // the process can access private directory 'data' of itself. - if(chown(storagePath.str().c_str(), - WEBAPP_DEFAULT_UID, - WEBAPP_DEFAULT_GID) != 0) - { - ThrowMsg(Exceptions::InternalError, - "Chown to invaild user"); - } - } else if (euidaccess(storagePath.str().c_str(), W_OK | R_OK | X_OK) == 0) { - LogInfo("Private storage already exists."); - // Even if private directory already is created, private dircetory - // should change owner. - if(chown(storagePath.str().c_str(), - WEBAPP_DEFAULT_UID, - WEBAPP_DEFAULT_GID) != 0) - { - ThrowMsg(Exceptions::InternalError, - "Chown to invaild user"); - } - if(chmod(storagePath.str().c_str(), PRIVATE_STORAGE_MODE) != 0) { - ThrowMsg(Exceptions::InternalError, - "chmod to 0700"); - } - - } else { - ThrowMsg(Exceptions::InternalError, - "No access to private storage."); - } - - m_context.job->UpdateProgress( - InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE, - "Private storage created." - ); -} -} //namespace WidgetInstall -} //namespace Jobs diff --git a/src/jobs/widget_install/task_private_storage.h b/src/jobs/widget_install/task_private_storage.h deleted file mode 100644 index e919f6b..0000000 --- a/src/jobs/widget_install/task_private_storage.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file task_private_storage.h - * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) - * @version 1.0 - * @brief Header file for installer task private storage. - */ -#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_PRIVATESTORAGE_H -#define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_PRIVATESTORAGE_H - -#include - -class InstallerContext; - -namespace Jobs { -namespace WidgetInstall { -class TaskPrivateStorage : public DPL::TaskDecl -{ - public: - explicit TaskPrivateStorage(InstallerContext& context); - - private: - void StepCreateDirectory(); - - private: - InstallerContext& m_context; -}; -} //namespace WidgetInstall -} //namespace Jobs - -#endif diff --git a/src/jobs/widget_install/task_recovery.cpp b/src/jobs/widget_install/task_recovery.cpp index 1b922db..bd844ae 100644 --- a/src/jobs/widget_install/task_recovery.cpp +++ b/src/jobs/widget_install/task_recovery.cpp @@ -72,10 +72,6 @@ void TaskRecovery::StepCreateCheckFile() m_context.installInfo = infoPath.str(); LogDebug("Create file : " << m_context.installInfo); - m_context.job->UpdateProgress( - InstallerContext::INSTALL_LINK_DEPENDS_DIRECTORY, - "depends directory linked." - ); } else { ThrowMsg(Exceptions::InternalError, "Fail to create file for recovery."); } diff --git a/src/jobs/widget_install/widget_install_context.h b/src/jobs/widget_install/widget_install_context.h index 4fa010b..cc3e668 100755 --- a/src/jobs/widget_install/widget_install_context.h +++ b/src/jobs/widget_install/widget_install_context.h @@ -65,8 +65,6 @@ struct InstallerContext INSTALL_BACKUP_EXEC, /* For Update */ INSTALL_NEW_DB_INSERT, /* For Update */ - INSTALL_CREATE_PRIVATE_STORAGE, - INSTALL_LINK_DEPENDS_DIRECTORY, INSTALL_ACE_PREPARE, INSTALL_ACE_CHECK, INSTALL_SMACK_ENABLE, diff --git a/src/jobs/widget_uninstall/task_remove_files.cpp b/src/jobs/widget_uninstall/task_remove_files.cpp index d258d0c..1bc1984 100644 --- a/src/jobs/widget_uninstall/task_remove_files.cpp +++ b/src/jobs/widget_uninstall/task_remove_files.cpp @@ -62,7 +62,7 @@ void TaskRemoveFiles::StepRemoveInstallationDirectory() if(!WrtUtilRemove(widgetDir)){ LogWarning("Removing widget installation directory failed"); } - std::string dataDir = m_context.locations->getBasePrivateDir(); + std::string dataDir = m_context.locations->getUserDataRootDir(); if(!WrtUtilRemove(dataDir)){ LogWarning(dataDir + " is already removed"); } diff --git a/src/misc/widget_location.cpp b/src/misc/widget_location.cpp index 3686afc..31b5d17 100644 --- a/src/misc/widget_location.cpp +++ b/src/misc/widget_location.cpp @@ -147,6 +147,18 @@ std::string WidgetLocation::getBackupExecFile() const return getBackupBinaryDir() + "/" + m_pkgname; } +std::string WidgetLocation::getUserDataRootDir() const +{ + return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) + + "/" + m_pkgname; +} + +std::string WidgetLocation::getPrivateStorageDir() const +{ + return getUserDataRootDir() + "/" + + WrtDB::GlobalConfig::GetWidgetPrivateStoragePath(); +} + std::string WidgetLocation::getTemporaryPackageDir() const { return m_temp->getTempPath(); @@ -210,12 +222,6 @@ void WidgetLocation::registerExternalLocation(const std::string & file) m_externals.push_back(file); } -std::string WidgetLocation::getBasePrivateDir() const -{ - return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) + - "/" + m_pkgname; -} - WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const { return m_externals; diff --git a/src/misc/widget_location.h b/src/misc/widget_location.h index 64408f9..3d4801c 100644 --- a/src/misc/widget_location.h +++ b/src/misc/widget_location.h @@ -36,6 +36,7 @@ * * /opt/apps/[package_name] * \_____________ /data + * \_____________ /data/share * \_____________ /bin * \_____________ /bin/[id_of_installed_package] * \_____________ /res/wgt/ @@ -111,7 +112,8 @@ public: std::string getBackupSourceDir() const; // /opt/apps/[package]/backup/res/wgt std::string getBackupBinaryDir() const; // /opt/apps/[package]/backup/bin std::string getBackupExecFile() const; // /opt/apps/[package]/backup/bin/[package] - std::string getBasePrivateDir() const; // /opt/apps + std::string getUserDataRootDir() const; // /opt/usr/apps/[package] + std::string getPrivateStorageDir() const; // /opt/usr/apps/[package]/data // Temporary paths /**