From: Sangyoon Jang Date: Thu, 21 Nov 2019 08:27:20 +0000 (+0900) Subject: Fix StepRecoverStorageDirectories X-Git-Tag: accepted/tizen/5.5/unified/20200105.221114~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cf9b7d6c83a31b5e52c73e0d798311143966788;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Fix StepRecoverStorageDirectories Recover when shared data directory updated. Change-Id: Id72db565a8f6668f10990e128d78d4a6f48e50f0 Signed-off-by: Sangyoon Jang --- diff --git a/src/common/step/filesystem/step_recover_storage_directories.cc b/src/common/step/filesystem/step_recover_storage_directories.cc index 852ccd4..fdd324a 100644 --- a/src/common/step/filesystem/step_recover_storage_directories.cc +++ b/src/common/step/filesystem/step_recover_storage_directories.cc @@ -8,17 +8,36 @@ #include #include +#include + #include "common/paths.h" +#include "common/privileges.h" +#include "common/shared_dirs.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" +#include "common/utils/user_util.h" + +namespace bf = boost::filesystem; +namespace ci = common_installer; namespace { const char kDataLocation[] = "data"; const char kSharedResLocation[] = "shared"; -} // namespace +bool ShouldCreateSharedDataDir(manifest_x* manifest) { + if (ci::ShouldSupportLegacySharedDataDir(manifest->api_version)) + return true; -namespace bf = boost::filesystem; + for (auto& priv : GListRange(manifest->privileges)) { + if (!strcmp(priv->value, ci::privileges::kPrivForSharedData)) + return true; + } + + return false; +} + +} // namespace namespace common_installer { namespace filesystem { @@ -43,8 +62,6 @@ bool StepRecoverStorageDirectories::MoveAppStorage( } Step::Status StepRecoverStorageDirectories::RecoveryUpdate() { - if (context_->request_mode.get() == RequestMode::GLOBAL) - return Status::OK; if (!context_->GetPkgPath().empty()) { bf::path backup_path = common_installer::GetBackupPathForPackagePath( context_->GetPkgPath()); @@ -52,6 +69,33 @@ Step::Status StepRecoverStorageDirectories::RecoveryUpdate() { MoveAppStorage(context_->GetPkgPath(), backup_path, kDataLocation); MoveAppStorage(context_->GetPkgPath(), backup_path, kSharedResLocation); } + + manifest_x* manifest = context_->manifest_data.get(); + if (!manifest) { + LOG(WARNING) << "Cannot find manifest data. " + "Some directories may not be recovered."; + return Status::OK; + } + + if (ShouldCreateSharedDataDir(manifest)) { + if (context_->request_mode.get() == RequestMode::GLOBAL) { + if (!ci::RestorePerUserSharedDataDir(context_->pkgid.get())) + return Status::APP_DIR_ERROR; + } else { + if (!ci::RestoreSharedDataDir(context_->pkgid.get(), + context_->uid.get())) + return Status::APP_DIR_ERROR; + } + } else { + if (context_->request_mode.get() == RequestMode::GLOBAL) { + if (!ci::DeletePerUserSharedDataDir(context_->pkgid.get())) + return Status::APP_DIR_ERROR; + } else { + if (!ci::DeleteSharedDataDir(context_->pkgid.get(), + context_->uid.get())) + return Status::APP_DIR_ERROR; + } + } } return Status::OK; }