Implement StepRestoreWgtSymbolicLink 42/280142/1
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 8 Jul 2022 11:20:42 +0000 (20:20 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 24 Aug 2022 08:50:06 +0000 (17:50 +0900)
If the uninstallation fails with the bin path removed
recover the wgt symbolic link

Change-Id: If1a4fd95be319fded67bd778f21e9abd2fae512a
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/hybrid/hybrid_installer.cc
src/wgt/step/filesystem/step_restore_wgt_symbolic_link.cc [new file with mode: 0644]
src/wgt/step/filesystem/step_restore_wgt_symbolic_link.h [new file with mode: 0644]
src/wgt/wgt_installer.cc

index fd9b5a8..df7495b 100644 (file)
@@ -33,6 +33,7 @@
 #include "wgt/step/encryption/step_remove_encryption_data.h"
 #include "wgt/step/filesystem/step_copy_preview_icons.h"
 #include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
+#include "wgt/step/filesystem/step_restore_wgt_symbolic_link.h"
 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
 #include "wgt/step/filesystem/step_wgt_undo_patch_storage_directories.h"
@@ -128,6 +129,8 @@ void HybridInstaller::UninstallSteps() {
   ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
       "RemovePerUserStorageDirectories",
       wgt::filesystem::HybridAdditionalSharedDirs);
+  AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
+      "RemovePerUserStorageDirectories");
   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
       "RemovePerUserStorageDirectories");
 }
@@ -355,6 +358,8 @@ void HybridInstaller::PartialUninstallSteps() {
   ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
       "RemovePerUserStorageDirectories",
       wgt::filesystem::HybridAdditionalSharedDirs);
+  AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
+      "RemovePerUserStorageDirectories");
   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
       "RemovePerUserStorageDirectories");
 }
diff --git a/src/wgt/step/filesystem/step_restore_wgt_symbolic_link.cc b/src/wgt/step/filesystem/step_restore_wgt_symbolic_link.cc
new file mode 100644 (file)
index 0000000..0cc2e5e
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "wgt/step/filesystem/step_restore_wgt_symbolic_link.h"
+
+#include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace wgt {
+namespace filesystem {
+
+common_installer::Step::Status StepRestoreWgtSymbolicLink::undo() {
+  StepCreateWgtSymbolicLink step(context_);
+
+  Status result = step.precheck();
+  if (result != Status::OK) {
+    LOG(ERROR) << "Fail to execute precheck of CreateWgtSymbolicLink";
+    return result;
+  }
+
+  result = step.process();
+  if (result != Status::OK) {
+    LOG(ERROR) << "Fail to execute process of CreateWgtSymbolicLink";
+    return result;
+  }
+
+  return result;
+}
+
+}  // namespace filesystem
+}  // namespace wgt
diff --git a/src/wgt/step/filesystem/step_restore_wgt_symbolic_link.h b/src/wgt/step/filesystem/step_restore_wgt_symbolic_link.h
new file mode 100644 (file)
index 0000000..f0f141e
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_STEP_FILESYSTEM_STEP_RESTORE_WGT_SYMBOLIC_LINK_H_
+#define WGT_STEP_FILESYSTEM_STEP_RESTORE_WGT_SYMBOLIC_LINK_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <common/installer_context.h>
+#include <common/step/step.h>
+
+namespace wgt {
+namespace filesystem {
+
+/**
+ * \brief Step that create symbolic link to application
+ */
+class StepRestoreWgtSymbolicLink : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status precheck() override { return Status::OK; }
+  Status process() override { return Status::OK; }
+  Status clean() override { return Status::OK; }
+  Status undo() override;
+
+  STEP_NAME(RestoreWgtSymbolicLink)
+};
+
+}  // namespace filesystem
+}  // namespace wgt
+
+#endif  // WGT_STEP_FILESYSTEM_STEP_RESTORE_WGT_SYMBOLIC_LINK_H_
index 30997b7..d79b585 100644 (file)
@@ -26,6 +26,7 @@
 #include "wgt/step/encryption/step_remove_encryption_data.h"
 #include "wgt/step/filesystem/step_copy_preview_icons.h"
 #include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
+#include "wgt/step/filesystem/step_restore_wgt_symbolic_link.h"
 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
@@ -119,6 +120,8 @@ void WgtInstaller::UninstallSteps() {
   ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
       "RemovePerUserStorageDirectories",
       wgt::filesystem::WgtAdditionalSharedDirs);
+  AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
+      "RemovePerUserStorageDirectories");
   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
       "RemovePerUserStorageDirectories");
 }
@@ -361,6 +364,8 @@ void WgtInstaller::PartialUninstallSteps() {
   ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
       "RemovePerUserStorageDirectories",
       wgt::filesystem::WgtAdditionalSharedDirs);
+  AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
+      "RemovePerUserStorageDirectories");
   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
       "RemovePerUserStorageDirectories");
 }