Implement StepRemoveGlobalAppSymlinks undo 31/315331/1
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 24 Nov 2023 03:50:14 +0000 (12:50 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Sun, 1 Dec 2024 23:34:25 +0000 (08:34 +0900)
Change-Id: If4554ca988078802974998eee773b448cee266d2
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/filesystem/step_remove_globalapp_symlinks.cc
src/common/step/filesystem/step_remove_globalapp_symlinks.h
src/common/step/filesystem/step_remove_per_user_storage_directories.cc

index 644f20c737d8047efb0f48b947a3567dba15f95f..8baf7d942ad8a04e498773d9293c32275c778b02 100644 (file)
@@ -54,6 +54,30 @@ Step::Status StepRemoveGlobalAppSymlinks::process() {
   return Step::Status::OK;
 }
 
+Step::Status StepRemoveGlobalAppSymlinks::undo() {
+  if (context_->is_readonly_package.get() ||
+      context_->request_mode.get() == RequestMode::USER)
+    return Step::Status::OK;
+
+  PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
+  if (!pkg_query.IsPackageInstalled())
+    return Step::Status::OK;
+
+  RequestType req_type = context_->request_type.get();
+  if (req_type == RequestType::Uninstall ||
+      req_type == RequestType::ReadonlyUpdateUninstall) {
+    std::string package_id = context_->pkgid.get();
+    LOG(INFO) << "Creating globalapp symlinks for all user, package: "
+              << package_id;
+    if (!CreateGlobalAppSymlinksForAllUsers(package_id)) {
+      LOG(ERROR) << "Failed to create globalapp symlinks";
+      return Status::GLOBALSYMLINK_ERROR;
+    }
+  }
+
+  return Status::OK;
+}
+
 }  // namespace filesystem
 }  // namespace common_installer
 
index d870382cd42e426a6e5b4ed757862906c9e6d53c..61e807bf076878a0d874b0a08e1401ef02789114 100644 (file)
@@ -29,7 +29,7 @@ class StepRemoveGlobalAppSymlinks : public common_installer::Step {
 
   Status process() override;
   Status clean() override { return Status::OK; }
-  Status undo() override { return Status::OK; }
+  Status undo() override;
   Status precheck() override { return Status::OK; }
 
   STEP_NAME(RemoveGlobalAppSymlinks)
index 2c60121a3443e3225b30473069cefc4c2e9a93f3..409a833ba18409926a61240d2fd30dd28e6992e5 100644 (file)
@@ -34,26 +34,10 @@ Step::Status StepRemovePerUserStorageDirectories::undo() {
       QueryCertificateAuthorCertificate(
           context_->pkgid.get(), context_->uid.get());
   context_->certificate_info.get().author_id.set(author_id);
-  std::vector<std::unique_ptr<Step>> steps;
-  steps.emplace_back(new StepCreateStorageDirectories(
-      context_, additional_shared_dirs_));
-  steps.emplace_back(new StepCreateGlobalAppSymlinks(context_));
-
-  for (auto& it : steps) {
-    Step::Status result;
-    result = it->precheck();
-    if (result != Step::Status::OK) {
-      LOG(ERROR) << "Fail to execute precheck of " << it->name();
-      return result;
-    }
-
-    result = it->process();
-    if (result != Step::Status::OK) {
-      LOG(ERROR) << "Fail to execute process of " << it->name();
-      return result;
-    }
-  }
-  return Step::Status::OK;
+
+  StepCreateStorageDirectories step(context_, additional_shared_dirs_);
+
+  return step.process();
 }
 
 }  // namespace filesystem