Add ZipInterface and MountBase class for exandability 46/235346/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 4 Jun 2020 04:42:30 +0000 (13:42 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 4 Jun 2020 06:13:26 +0000 (15:13 +0900)
Inherits MountBase and implementing CreateZipInterface which returns
IZipInterface enables using other zip interface instead of TZip.

Change-Id: Ie33b9e0b18c2a5d677fa8634f1a25d34dc3ee1e6
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/mount_base.h [new file with mode: 0644]
src/common/step/mount/step_mount_install.cc
src/common/step/mount/step_mount_install.h
src/common/step/mount/step_mount_recover.cc
src/common/step/mount/step_mount_recover.h
src/common/step/mount/step_mount_unpacked.cc
src/common/step/mount/step_mount_unpacked.h
src/common/step/mount/step_mount_update.cc
src/common/step/mount/step_mount_update.h
src/common/tzip_interface.h
src/common/zip_interface.h [new file with mode: 0644]

diff --git a/src/common/mount_base.h b/src/common/mount_base.h
new file mode 100644 (file)
index 0000000..0df04dd
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_MOUNT_BASE_H_
+#define COMMON_MOUNT_BASE_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include "common/step/step.h"
+#include "common/zip_interface.h"
+
+namespace common_installer {
+
+/**
+ * \brief Interface class for all mount related classes.
+ */
+class MountBase {
+ public:
+  virtual ~MountBase() = default;
+
+ protected:
+  virtual std::unique_ptr<IZipInterface> CreateZipInterface(
+      const boost::filesystem::path& mount_path) = 0;
+
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_MOUNT_BASE_H_
index f055df66a4dea21136fb59538a53b30c40cbf899..74d48ffe4799cd20c943ce24c91fb4290c19c1b1 100644 (file)
@@ -12,6 +12,7 @@
 #include "common/paths.h"
 #include "common/request.h"
 #include "common/tzip_interface.h"
+#include "common/zip_interface.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
@@ -21,8 +22,8 @@ namespace common_installer {
 namespace mount {
 
 Step::Status StepMountInstall::process() {
-  TzipInterface tzip_unpack(context_->unpacked_dir_path.get());
-  if (!tzip_unpack.UnmountZip()) {
+  auto zip_unpack = CreateZipInterface(context_->unpacked_dir_path.get());
+  if (!zip_unpack->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package from temporary path";
     return Status::APP_DIR_ERROR;
   }
@@ -46,8 +47,8 @@ Step::Status StepMountInstall::process() {
       strdup(zip_destination_path.c_str());
 
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.MountZip(zip_destination_path)) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
     return Status::APP_DIR_ERROR;
   }
@@ -58,8 +59,8 @@ Step::Status StepMountInstall::process() {
 
 Step::Status StepMountInstall::UmountPackagePath() {
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.UnmountZip()) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
     return Status::APP_DIR_ERROR;
   }
@@ -115,5 +116,12 @@ Step::Status StepMountInstall::precheck() {
   return Step::Status::OK;
 }
 
+std::unique_ptr<IZipInterface> StepMountInstall::CreateZipInterface(
+    const boost::filesystem::path& mount_path) {
+  std::unique_ptr<IZipInterface> zip_interface(
+      new TzipInterface(mount_path));
+  return zip_interface;
+}
+
 }  // namespace mount
 }  // namespace common_installer
index f8561beeb2a308923fc9ea8628b66d21214d4a57..2a2242f601201353e252f2c6699f2ef6fa713a0c 100644 (file)
@@ -8,6 +8,7 @@
 #include <manifest_parser/utils/logging.h>
 
 #include "common/installer_context.h"
+#include "common/mount_base.h"
 #include "common/step/step.h"
 
 namespace common_installer {
@@ -26,19 +27,22 @@ namespace mount {
  * * TZ_SYS_RW/$PKGID (/usr/apps/$PKGID)
  * * TZ_SER_APPS/$PKGID  (/{HOME}/apps_rw/$PKGID)
  */
-class StepMountInstall : public Step {
+class StepMountInstall : public MountBase, public Step {
  public:
   using Step::Step;
+  using MountBase::MountBase;
 
   Status process() override;
-  Status clean() { return Status::OK; }
+  Status clean() override { return Status::OK; }
   Status undo() override;
   Status precheck() override;
 
  protected:
+  std::unique_ptr<IZipInterface> CreateZipInterface(
+      const boost::filesystem::path& mount_path) override;
   Status UmountPackagePath();
 
-  STEP_NAME(MountInstall)
+  STEP_NAME(MountInstall);
 };
 
 }  // namespace mount
index 036c3ff1d495b9272f1b833d50570441b31608d0..a753b69ff61505bd71eb5146d98d20061b5881fe 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "common/paths.h"
 #include "common/tzip_interface.h"
+#include "common/zip_interface.h"
 
 namespace bf = boost::filesystem;
 
@@ -25,8 +26,8 @@ Step::Status StepMountRecover::RecoveryMountUpdate() {
     manifest->zip_mount_file = strdup(zip_destination_path.c_str());
 
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.MountZip(zip_destination_path)) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
     return Status::APP_DIR_ERROR;
   }
@@ -66,8 +67,8 @@ Step::Status StepMountRecover::undo() {
 
 Step::Status StepMountRecover::UmountPackagePath() {
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.UnmountZip()) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
     return Status::APP_DIR_ERROR;
   }
@@ -75,5 +76,12 @@ Step::Status StepMountRecover::UmountPackagePath() {
   return Status::OK;
 }
 
+std::unique_ptr<IZipInterface> StepMountRecover::CreateZipInterface(
+    const boost::filesystem::path& mount_path) {
+  std::unique_ptr<IZipInterface> zip_interface(
+      new TzipInterface(mount_path));
+  return zip_interface;
+}
+
 }  // namespace mount
 }  // namespace common_installer
index 76c5595de2523cd11920cf39da173d34d303546a..d74f04367c1c2ee1bbca5b38caec6718cc683ad7 100644 (file)
@@ -8,6 +8,7 @@
 #include <manifest_parser/utils/logging.h>
 
 #include "common/installer_context.h"
+#include "common/mount_base.h"
 #include "common/step/recovery/step_recovery.h"
 
 namespace common_installer {
@@ -16,8 +17,9 @@ namespace mount {
 /**
  * \brief Responsible for mounting package zip in recovery mode
  */
-class StepMountRecover : public recovery::StepRecovery {
+class StepMountRecover : public MountBase, public recovery::StepRecovery {
  public:
+  using MountBase::MountBase;
   using StepRecovery::StepRecovery;
 
   Status RecoveryNew() override { return Status::OK; }
@@ -30,6 +32,8 @@ class StepMountRecover : public recovery::StepRecovery {
   Status undo() override;
 
  private:
+  std::unique_ptr<IZipInterface> CreateZipInterface(
+      const boost::filesystem::path& mount_path) override;
   Status UmountPackagePath();
 
   STEP_NAME(MountRecover)
index de79bf6966ff0dc17fdc59b5956555b3b832025d..c4dfb2c5061addee1d286d768de2c7157e50acab 100644 (file)
@@ -13,6 +13,7 @@
 #include "common/paths.h"
 #include "common/utils/file_util.h"
 #include "common/tzip_interface.h"
+#include "common/zip_interface.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
@@ -30,8 +31,8 @@ Step::Status StepMountUnpacked::process() {
   bf::path tmp_dir = GenerateTmpDir(kPackageUnpackDirPath);
   context_->unpacked_dir_path.set(tmp_dir);
 
-  TzipInterface tzip(context_->unpacked_dir_path.get());
-  if (!tzip.MountZip(context_->file_path.get())) {
+  auto zip = CreateZipInterface(context_->unpacked_dir_path.get());
+  if (!zip->MountZip(context_->file_path.get())) {
     LOG(ERROR) << "Failed to mount zip file: " << context_->file_path.get();
     return Status::IMAGE_ERROR;
   }
@@ -41,8 +42,8 @@ Step::Status StepMountUnpacked::process() {
 }
 
 Step::Status StepMountUnpacked::undo() {
-  TzipInterface tzip(context_->unpacked_dir_path.get());
-  if (!tzip.UnmountZip()) {
+  auto zip = CreateZipInterface(context_->unpacked_dir_path.get());
+  if (!zip->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip file: " << context_->file_path.get();
     return Status::IMAGE_ERROR;
   }
@@ -51,8 +52,8 @@ Step::Status StepMountUnpacked::undo() {
 
   if (context_->request_type.get() == RequestType::MountUpdate) {
     bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-    TzipInterface tzip_final(mount_point);
-    if (!tzip_final.UnmountZip()) {
+    auto zip_final = CreateZipInterface(mount_point);
+    if (!zip_final->UnmountZip()) {
       LOG(ERROR) << "Failed to unmount zip package after revoke";
       return Status::APP_DIR_ERROR;
     }
@@ -84,5 +85,12 @@ Step::Status StepMountUnpacked::precheck() {
   return Status::OK;
 }
 
+std::unique_ptr<IZipInterface> StepMountUnpacked::CreateZipInterface(
+    const boost::filesystem::path& mount_path) {
+  std::unique_ptr<IZipInterface> zip_interface(
+      new TzipInterface(mount_path));
+  return zip_interface;
+}
+
 }  // namespace mount
 }  // namespace common_installer
index f123ae204c7ea7a9b01fe53f0e0831e9ffa8d168..f1d8b4000752848f6b5691f7bc6c1c9f33e7e3ab 100644 (file)
@@ -8,6 +8,7 @@
 #include <manifest_parser/utils/logging.h>
 
 #include "common/installer_context.h"
+#include "common/mount_base.h"
 #include "common/step/step.h"
 
 namespace common_installer {
@@ -23,8 +24,9 @@ namespace mount {
  * * TZ_SYS_RW/tmpuniquedir (/usr/apps/tmpuniquedir)
  * * TZ_SER_APPS/tmpdir  (/{HOME}/apps_rw/tmpuniquedir)
  */
-class StepMountUnpacked : public Step {
+class StepMountUnpacked : public MountBase, public Step {
  public:
+  using MountBase::MountBase;
   using Step::Step;
 
   Status process() override;
@@ -32,6 +34,10 @@ class StepMountUnpacked : public Step {
   Status undo() override;
   Status precheck() override;
 
+ protected:
+  std::unique_ptr<IZipInterface> CreateZipInterface(
+      const boost::filesystem::path& mount_path) override;
+
   STEP_NAME(MountUnpacked)
 };
 
index c9c5516e2bafe5bc1a354fc5a4a9778434aeff3a..61e74e6baec6affe4b8617e13929bea9081e948e 100644 (file)
@@ -12,6 +12,7 @@
 #include "common/paths.h"
 #include "common/request.h"
 #include "common/tzip_interface.h"
+#include "common/zip_interface.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
@@ -21,8 +22,8 @@ namespace common_installer {
 namespace mount {
 
 Step::Status StepMountUpdate::process() {
-  TzipInterface tzip_unpack(context_->unpacked_dir_path.get());
-  if (!tzip_unpack.UnmountZip()) {
+  auto zip_unpack = CreateZipInterface(context_->unpacked_dir_path.get());
+  if (!zip_unpack->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package from temporary path";
     return Status::APP_DIR_ERROR;
   }
@@ -43,8 +44,8 @@ Step::Status StepMountUpdate::process() {
       strdup(zip_destination_path.c_str());
 
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.MountZip(zip_destination_path)) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
     return Status::APP_DIR_ERROR;
   }
@@ -55,8 +56,8 @@ Step::Status StepMountUpdate::process() {
 
 Step::Status StepMountUpdate::UmountPackagePath() {
   bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-  TzipInterface tzip_final(mount_point);
-  if (!tzip_final.UnmountZip()) {
+  auto zip_final = CreateZipInterface(mount_point);
+  if (!zip_final->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
     return Status::APP_DIR_ERROR;
   }
@@ -91,10 +92,10 @@ Step::Status StepMountUpdate::undo() {
 
     // mount previous file for re-registration of trust anchor
     bf::path mount_point = GetMountLocation(context_->GetPkgPath());
-    TzipInterface tzip_final(mount_point);
+    auto zip_final = CreateZipInterface(mount_point);
     bf::path zip_destination_path =
       GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
-    if (!tzip_final.MountZip(zip_destination_path)) {
+    if (!zip_final->MountZip(zip_destination_path)) {
       LOG(ERROR) << "Failed to mount zip package in installation path";
       return Status::APP_DIR_ERROR;
     }
@@ -133,5 +134,12 @@ Step::Status StepMountUpdate::precheck() {
   return Step::Status::OK;
 }
 
+std::unique_ptr<IZipInterface> StepMountUpdate::CreateZipInterface(
+    const boost::filesystem::path& mount_path) {
+  std::unique_ptr<IZipInterface> zip_interface(
+      new TzipInterface(mount_path));
+  return zip_interface;
+}
+
 }  // namespace mount
 }  // namespace common_installer
index b77672d3b13ac8bef9a351aa549a9d1ef4044a64..26d91c772b5a6d7f4e79d00d78452be8de1e7eb9 100644 (file)
@@ -8,6 +8,7 @@
 #include <manifest_parser/utils/logging.h>
 
 #include "common/installer_context.h"
+#include "common/mount_base.h"
 #include "common/step/step.h"
 
 namespace common_installer {
@@ -26,8 +27,9 @@ namespace mount {
  * * TZ_SYS_RW/$PKGID (/usr/apps/$PKGID)
  * * TZ_SER_APPS/$PKGID  (/{HOME}/apps_rw/$PKGID)
  */
-class StepMountUpdate : public Step {
+class StepMountUpdate : public MountBase, public Step {
  public:
+  using MountBase::MountBase;
   using Step::Step;
 
   Status process() override;
@@ -36,6 +38,8 @@ class StepMountUpdate : public Step {
   Status precheck() override;
 
  protected:
+  std::unique_ptr<IZipInterface> CreateZipInterface(
+      const boost::filesystem::path& mount_path) override;
   Status UmountPackagePath();
 
   STEP_NAME(MountUpdate)
index ac33db5cf42615daed2b66920c9412d67c699d8d..69e002629de46498fb73ca4d4dcc2637a22ef9c9 100644 (file)
@@ -7,18 +7,20 @@
 
 #include <boost/filesystem/path.hpp>
 
+#include <common/zip_interface.h>
+
 #include <memory>
 #include <string>
 
 namespace common_installer {
 
-class TzipInterface {
+class TzipInterface : public common_installer::IZipInterface {
  public:
   explicit TzipInterface(const boost::filesystem::path& mount_path);
   ~TzipInterface();
 
-  bool MountZip(const boost::filesystem::path& zip_path);
-  bool UnmountZip();
+  bool MountZip(const boost::filesystem::path& zip_path) override;
+  bool UnmountZip() override;
 
  private:
   class Pimpl;
diff --git a/src/common/zip_interface.h b/src/common/zip_interface.h
new file mode 100644 (file)
index 0000000..9d458c3
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_ZIP_INTERFACE_H_
+#define COMMON_ZIP_INTERFACE_H_
+
+#include <boost/filesystem/path.hpp>
+
+namespace common_installer {
+
+/**
+ * \brief Interface class for zip interface classes.
+ */
+class IZipInterface {
+ public:
+  virtual ~IZipInterface() = default;
+
+  virtual bool MountZip(const boost::filesystem::path& zip_path) = 0;
+  virtual bool UnmountZip() = 0;
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_ZIP_INTERFACE_H_