From 99180354594554b67ce13c215e7a4c73a87b94ec Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 3 Feb 2016 21:23:01 +0900 Subject: [PATCH] apply the concept of TPK insatllation as 'preload' And, modify the way of preload decision. Requires: https://review.tizen.org/gerrit/#/c/58866 Change-Id: I90a698a721ac58a132862eba7f6e960686b9d152 Signed-off-by: jongmyeongko --- src/common/installer_context.cc | 3 +- src/common/installer_context.h | 5 +++ src/common/pkgmgr_interface.cc | 6 +++ src/common/pkgmgr_interface.h | 7 ++++ src/common/request.cc | 5 ++- src/common/request.h | 2 +- src/common/step/step_configure.cc | 8 +++- src/common/step/step_configure.h | 1 + src/common/step/step_delta_patch.cc | 11 +++--- src/pkg_install_manifest/pkg_install_manifest.cc | 11 ++++-- src/pkgdir_tool/pkgdir_tool.cc | 47 ++++++------------------ 11 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/common/installer_context.cc b/src/common/installer_context.cc index 50554b8..340196b 100644 --- a/src/common/installer_context.cc +++ b/src/common/installer_context.cc @@ -35,7 +35,8 @@ InstallerContext::InstallerContext() old_manifest_data(nullptr), uid(getuid()), backend_data(nullptr), - privilege_level(PrivilegeLevel::UNTRUSTED) {} + privilege_level(PrivilegeLevel::UNTRUSTED), + is_preload_request(false) {} InstallerContext::~InstallerContext() { if (manifest_data.get()) diff --git a/src/common/installer_context.h b/src/common/installer_context.h index 5bf43ba..521009c 100644 --- a/src/common/installer_context.h +++ b/src/common/installer_context.h @@ -267,6 +267,11 @@ class InstallerContext { * \brief installation mode (ONLINE / OFFLINE) */ Property installation_mode; + + /** + * \brief preload request received from pkgmgr_installer + */ + Property is_preload_request; }; } // namespace common_installer diff --git a/src/common/pkgmgr_interface.cc b/src/common/pkgmgr_interface.cc index ea7a2bc..942acbb 100644 --- a/src/common/pkgmgr_interface.cc +++ b/src/common/pkgmgr_interface.cc @@ -124,4 +124,10 @@ bool PkgMgrInterface::GetIsTepMove() { return (pkgmgr_installer_get_tep_move_type(pi_) == 1)?true:false; } +bool PkgMgrInterface::GetIsPreloadRequest() { + return (pkgmgr_installer_get_is_preload(pi_) == 1)? + true:(install_mode_ == InstallationMode::OFFLINE)? + true:false; +} + } // namespace common_installer diff --git a/src/common/pkgmgr_interface.h b/src/common/pkgmgr_interface.h index d65c558..90d3891 100644 --- a/src/common/pkgmgr_interface.h +++ b/src/common/pkgmgr_interface.h @@ -71,6 +71,13 @@ class PkgMgrInterface { bool GetIsTepMove(); /** + * Returns True if the request is for preload. Otherwise, return false + * + * \return True if the request is for preload. Otherwise, return false + */ + bool GetIsPreloadRequest(); + + /** * Get Raw pointer to pkgmgr_installer object * NOTE: It should not be used (PkgMgrInterface can destroy it * diff --git a/src/common/request.cc b/src/common/request.cc index 6934077..1b4a022 100644 --- a/src/common/request.cc +++ b/src/common/request.cc @@ -14,9 +14,10 @@ RequestMode GetRequestMode() { RequestMode::GLOBAL : RequestMode::USER; } -const char *GetRootAppPath() { +const char *GetRootAppPath(bool is_preload) { return GetRequestMode() == RequestMode::USER ? - tzplatform_getenv(TZ_USER_APP) : tzplatform_getenv(TZ_SYS_RW_APP); + tzplatform_getenv(TZ_USER_APP) : is_preload ? + tzplatform_getenv(TZ_SYS_RO_APP) :tzplatform_getenv(TZ_SYS_RW_APP); } } // namespace common_installer diff --git a/src/common/request.h b/src/common/request.h index a5df38e..20632cc 100644 --- a/src/common/request.h +++ b/src/common/request.h @@ -39,7 +39,7 @@ RequestMode GetRequestMode(); * * \return root application path (eg. $HOME/apps_rw/) */ -const char *GetRootAppPath(); +const char *GetRootAppPath(bool is_preload); } // namespace common_installer diff --git a/src/common/step/step_configure.cc b/src/common/step/step_configure.cc index 25f113f..d606328 100644 --- a/src/common/step/step_configure.cc +++ b/src/common/step/step_configure.cc @@ -32,6 +32,7 @@ Step::Status StepConfigure::process() { SetupRequestMode(); SetupRequestType(); SetupFileCreationMask(); + SetupIsPreloadRequest(); if (!SetupRootAppDirectory()) return Status::CONFIG_ERROR; @@ -160,7 +161,8 @@ Step::Status StepConfigure::clean() { bool StepConfigure::SetupRootAppDirectory() { if (context_->root_application_path.get().empty()) { - std::string root_app_path = GetRootAppPath(); + std::string root_app_path = + GetRootAppPath(context_->is_preload_request.get()); if (root_app_path.empty()) return false; @@ -206,5 +208,9 @@ void StepConfigure::SetupFileCreationMask() { << " to " << std::oct << new_mask; } +void StepConfigure::SetupIsPreloadRequest() { + context_->is_preload_request.set(pkgmgr_->GetIsPreloadRequest()); +} + } // namespace configuration } // namespace common_installer diff --git a/src/common/step/step_configure.h b/src/common/step/step_configure.h index 059924c..58e832c 100644 --- a/src/common/step/step_configure.h +++ b/src/common/step/step_configure.h @@ -64,6 +64,7 @@ class StepConfigure : public Step { void SetupRequestMode(); void SetupRequestType(); void SetupFileCreationMask(); + void SetupIsPreloadRequest(); PkgMgrPtr pkgmgr_; diff --git a/src/common/step/step_delta_patch.cc b/src/common/step/step_delta_patch.cc index a4c6e76..cf8a5a6 100644 --- a/src/common/step/step_delta_patch.cc +++ b/src/common/step/step_delta_patch.cc @@ -80,10 +80,10 @@ bool ApplyDeletedFiles(const delta::DeltaInfo& info, const bf::path& app_dir) { } bool ApplyModifiedFiles(const delta::DeltaInfo& info, const bf::path& app_dir, - const bf::path& patch_dir) { + const bf::path& patch_dir, bool is_preload) { for (auto& relative : info.modified()) { bf::path temp_file = ci::GenerateTemporaryPath( - bf::path(ci::GetRootAppPath()) / "tmp_file"); + bf::path(ci::GetRootAppPath(is_preload)) / "tmp_file"); bf::path patch_file = patch_dir / relative; bf::path input = app_dir / relative; if (!bf::is_regular_file(input)) { @@ -163,10 +163,10 @@ bool ApplyAddedFiles(const delta::DeltaInfo& info, const bf::path& app_dir, } bool ApplyPatch(const delta::DeltaInfo& info, const bf::path& app_dir, - const bf::path& patch_dir) { + const bf::path& patch_dir, bool is_preload) { if (!ApplyDeletedFiles(info, app_dir)) return false; - if (!ApplyModifiedFiles(info, app_dir, patch_dir)) + if (!ApplyModifiedFiles(info, app_dir, patch_dir, is_preload)) return false; if (!ApplyAddedFiles(info, app_dir, patch_dir)) return false; @@ -245,7 +245,8 @@ Step::Status StepDeltaPatch::process() { } // apply changes mentioned in delta - if (!ApplyPatch(*delta_info, context_->unpacked_dir_path.get(), patch_dir_)) + if (!ApplyPatch(*delta_info, context_->unpacked_dir_path.get(), patch_dir_, + context_->is_preload_request.get())) return Status::DELTA_ERROR; bs::error_code error; diff --git a/src/pkg_install_manifest/pkg_install_manifest.cc b/src/pkg_install_manifest/pkg_install_manifest.cc index 57e4391..c14233f 100644 --- a/src/pkg_install_manifest/pkg_install_manifest.cc +++ b/src/pkg_install_manifest/pkg_install_manifest.cc @@ -26,11 +26,15 @@ namespace { const char kBackendDirectoryPath[] = "/etc/package-manager/backend/"; int InstallManifestOffline(const std::string& pkgid, - const std::string& type) { + const std::string& type, + const std::string& preload) { bf::path backend_path(kBackendDirectoryPath); backend_path /= type; ci::Subprocess backend(backend_path.string()); - backend.Run("-y", pkgid.c_str()); + if (preload == "true") + backend.Run("-y", pkgid.c_str(), "--preload"); + else + backend.Run("-y", pkgid.c_str()); return backend.Wait(); } @@ -71,5 +75,6 @@ int main(int argc, char** argv) { if (type.empty()) type = "tpk"; - return InstallManifestOffline(package_info->package(), type); + return InstallManifestOffline(package_info->package(), type, + package_info->preload()); } diff --git a/src/pkgdir_tool/pkgdir_tool.cc b/src/pkgdir_tool/pkgdir_tool.cc index 23466e5..b335523 100644 --- a/src/pkgdir_tool/pkgdir_tool.cc +++ b/src/pkgdir_tool/pkgdir_tool.cc @@ -36,15 +36,10 @@ namespace ci = common_installer; namespace { -enum class Action { - CREATE, - COPY_OR_CREATE -}; - -const std::vector> kEntries = { - {"/", Action::CREATE}, - {"cache/", Action::CREATE}, - {"data/", Action::COPY_OR_CREATE} // compatibility -> copy data/ dir for tpk +const std::vector kEntries = { + {"/"}, + {"cache/"}, + {"data/"} }; const char kSkelAppDir[] = "/etc/skel/apps_rw"; @@ -137,30 +132,12 @@ bool CreateDirectories(const bf::path& app_dir, const std::string& pkgid, } bs::error_code error; - for (auto& pair : kEntries) { - bf::path subpath = base_dir / pair.first; - switch (pair.second) { - case Action::COPY_OR_CREATE: { - bf::path global_directory = - bf::path(tzplatform_getenv(TZ_SYS_RW_APP)) / pkgid / pair.first; - if (bf::exists(global_directory)) { - if (!ci::CopyDir(global_directory, subpath)) { - LOG(ERROR) << "Failed to copy directory: " << global_directory; - return false; - } - break; - } - } - case Action::CREATE: { - bf::create_directories(subpath, error); - if (error) { - LOG(ERROR) << "Failed to create directory: " << subpath; - return false; - } - break; - } - default: - assert(false); + for (auto& entry : kEntries) { + bf::path subpath = base_dir / entry; + bf::create_directories(subpath, error); + if (error) { + LOG(ERROR) << "Failed to create directory: " << subpath; + return false; } if (!SetPackageDirectoryOwnerAndPermissions(subpath, uid, gid)) @@ -216,8 +193,8 @@ bool CreateSkelDirectories(const std::string& pkgid) { } // TODO(jungh.yeon) : this is hotfix. - for (auto& pair : kEntries) { - bf::path subpath = path / pair.first; + for (auto& entry : kEntries) { + bf::path subpath = path / entry; bf::create_directories(subpath, error); std::string label = "User::Pkg::" + pkgid; if (error) { -- 2.7.4