From 35a80f6fb1a881a95a79d5f38de7e9756aa8cc0c Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 7 May 2020 17:39:12 +0900 Subject: [PATCH] Fix updating shared data directories Even if installer doesn't need to update shared data directories, installer should request registering shared data directories to security-manager. Change-Id: I6ef5d492f7263ac3bfd9acbf06f3f8fe393e1328 Signed-off-by: Sangyoon Jang --- .../filesystem/step_update_storage_directories.cc | 50 ++++++++-------------- .../filesystem/step_update_storage_directories.h | 12 ++---- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/common/step/filesystem/step_update_storage_directories.cc b/src/common/step/filesystem/step_update_storage_directories.cc index e4acb5e..8734168 100644 --- a/src/common/step/filesystem/step_update_storage_directories.cc +++ b/src/common/step/filesystem/step_update_storage_directories.cc @@ -46,46 +46,48 @@ namespace common_installer { namespace filesystem { bool StepUpdateStorageDirectories::UpdatePerUserStorageDirectories() { - if (mode_ == UpdateMode::CREATE) + if (should_create_shared_data_) return ci::CreatePerUserSharedDataDir(context_->pkgid.get()); - else + else if (old_shared_data_exists_ && !should_create_shared_data_) return ci::BackupPerUserSharedDataDir(context_->pkgid.get()); + return true; } bool StepUpdateStorageDirectories::UpdateStorageDirectories() { - if (mode_ == UpdateMode::CREATE) + if (should_create_shared_data_) return ci::CreateSharedDataDir(context_->pkgid.get(), context_->uid.get()); - else + else if (old_shared_data_exists_ && !should_create_shared_data_) return ci::BackupSharedDataDir(context_->pkgid.get(), context_->uid.get()); + return true; } bool StepUpdateStorageDirectories::CleanUpdatePerUserStorageDirectories() { - if (mode_ == UpdateMode::CREATE) - return true; - else + if (old_shared_data_exists_ && !should_create_shared_data_) return ci::RemoveBackupPerUserSharedDataDir(context_->pkgid.get()); + return true; } bool StepUpdateStorageDirectories::CleanUpdateStorageDirectories() { - if (mode_ == UpdateMode::CREATE) - return true; - else + if (old_shared_data_exists_ && !should_create_shared_data_) return ci::RemoveBackupSharedDataDir(context_->pkgid.get(), context_->uid.get()); + return true; } bool StepUpdateStorageDirectories::UndoUpdatePerUserStorageDirectories() { - if (mode_ == UpdateMode::CREATE) + if (!old_shared_data_exists_) return ci::DeletePerUserSharedDataDir(context_->pkgid.get()); - else + else if (old_shared_data_exists_ && !should_create_shared_data_) return ci::RestorePerUserSharedDataDir(context_->pkgid.get()); + return true; } bool StepUpdateStorageDirectories::UndoUpdateStorageDirectories() { - if (mode_ == UpdateMode::CREATE) + if (!old_shared_data_exists_) return ci::DeleteSharedDataDir(context_->pkgid.get(), context_->uid.get()); - else + else if (old_shared_data_exists_ && !should_create_shared_data_) return ci::RestoreSharedDataDir(context_->pkgid.get(), context_->uid.get()); + return true; } Step::Status StepUpdateStorageDirectories::precheck() { @@ -100,25 +102,14 @@ Step::Status StepUpdateStorageDirectories::precheck() { path = bf::path(ci::GetRootAppPath(false, context_->uid.get())) / context_->pkgid.get() / kSharedDataDir; - bool old_shared_data_exists = bf::exists(path); - bool should_create_shared_data = ShouldCreateSharedDataDir( + old_shared_data_exists_ = bf::exists(path); + should_create_shared_data_ = ShouldCreateSharedDataDir( context_->manifest_data.get()); - if ((old_shared_data_exists && should_create_shared_data) || - (!old_shared_data_exists && !should_create_shared_data)) - mode_ = UpdateMode::NONE; - else if (!old_shared_data_exists && should_create_shared_data) - mode_ = UpdateMode::CREATE; - else - mode_ = UpdateMode::DELETE; - return Status::OK; } Step::Status StepUpdateStorageDirectories::process() { - if (mode_ == UpdateMode::NONE) - return Status::OK; - if (context_->request_mode.get() == RequestMode::GLOBAL) { if (!UpdatePerUserStorageDirectories()) return Status::APP_DIR_ERROR; @@ -142,8 +133,6 @@ Step::Status StepUpdateStorageDirectories::clean() { recovery_file->set_cleanup(true); recovery_file->WriteAndCommitFileContent(); } - if (mode_ == UpdateMode::NONE) - return Status::OK; if (context_->request_mode.get() == RequestMode::GLOBAL) { if (!CleanUpdatePerUserStorageDirectories()) @@ -156,9 +145,6 @@ Step::Status StepUpdateStorageDirectories::clean() { } Step::Status StepUpdateStorageDirectories::undo() { - if (mode_ == UpdateMode::NONE) - return Status::OK; - if (context_->request_mode.get() == RequestMode::GLOBAL) { if (!UndoUpdatePerUserStorageDirectories()) return Status::APP_DIR_ERROR; diff --git a/src/common/step/filesystem/step_update_storage_directories.h b/src/common/step/filesystem/step_update_storage_directories.h index bc8a0e6..a7390e2 100644 --- a/src/common/step/filesystem/step_update_storage_directories.h +++ b/src/common/step/filesystem/step_update_storage_directories.h @@ -19,7 +19,8 @@ class StepUpdateStorageDirectories : public common_installer::Step { using Step::Step; explicit StepUpdateStorageDirectories(InstallerContext* context) : - Step(context), mode_(UpdateMode::NONE) {} + Step(context), old_shared_data_exists_(false), + should_create_shared_data_(false) {} Status process() override; Status clean() override; @@ -29,12 +30,6 @@ class StepUpdateStorageDirectories : public common_installer::Step { STEP_NAME(UpdateStorageDirectories) private: - enum class UpdateMode : int { - NONE, - CREATE, - DELETE, - }; - bool UpdatePerUserStorageDirectories(); bool UpdateStorageDirectories(); bool CleanUpdatePerUserStorageDirectories(); @@ -42,7 +37,8 @@ class StepUpdateStorageDirectories : public common_installer::Step { bool UndoUpdatePerUserStorageDirectories(); bool UndoUpdateStorageDirectories(); - UpdateMode mode_; + bool old_shared_data_exists_; + bool should_create_shared_data_; }; } // namespace filesystem -- 2.7.4