Implement undo of RemovePerUserStorageDirectories 39/280139/1
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 30 Jun 2022 06:16:28 +0000 (15:16 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 24 Aug 2022 08:47:43 +0000 (17:47 +0900)
If the uninstallation is failed after this step,
there is a problem that the user directory remains erased
so recreate the user directories removed by this step

Change-Id: Ic346217ab1cb971645bff44653027e545a430923
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/filesystem/step_remove_per_user_storage_directories.cc
src/common/step/filesystem/step_remove_per_user_storage_directories.h

index 9eba913..1a220a1 100644 (file)
@@ -4,11 +4,16 @@
 
 #include "common/step/filesystem/step_remove_per_user_storage_directories.h"
 
+#include <memory>
 #include <string>
 #include <vector>
 
+#include "common/step/step.h"
+#include "common/step/filesystem/step_create_storage_directories.h"
+#include "common/step/filesystem/step_create_globalapp_symlinks.h"
 #include "common/installer_context.h"
 #include "common/shared_dirs.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 namespace filesystem {
@@ -24,6 +29,32 @@ Step::Status StepRemovePerUserStorageDirectories::process() {
   return Step::Status::OK;
 }
 
+Step::Status StepRemovePerUserStorageDirectories::undo() {
+  std::string author_id =
+      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_));
+  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;
+}
+
 }  // namespace filesystem
 }  // namespace common_installer
 
index 5dcae94..2669d4a 100644 (file)
@@ -30,7 +30,7 @@ class StepRemovePerUserStorageDirectories : 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(RemovePerUserStorageDirectories)