--- /dev/null
+// 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_
#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;
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;
}
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;
}
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;
}
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
#include <manifest_parser/utils/logging.h>
#include "common/installer_context.h"
+#include "common/mount_base.h"
#include "common/step/step.h"
namespace common_installer {
* * 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
#include "common/paths.h"
#include "common/tzip_interface.h"
+#include "common/zip_interface.h"
namespace bf = boost::filesystem;
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;
}
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;
}
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
#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 {
/**
* \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; }
Status undo() override;
private:
+ std::unique_ptr<IZipInterface> CreateZipInterface(
+ const boost::filesystem::path& mount_path) override;
Status UmountPackagePath();
STEP_NAME(MountRecover)
#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;
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;
}
}
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;
}
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;
}
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
#include <manifest_parser/utils/logging.h>
#include "common/installer_context.h"
+#include "common/mount_base.h"
#include "common/step/step.h"
namespace common_installer {
* * 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;
Status undo() override;
Status precheck() override;
+ protected:
+ std::unique_ptr<IZipInterface> CreateZipInterface(
+ const boost::filesystem::path& mount_path) override;
+
STEP_NAME(MountUnpacked)
};
#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;
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;
}
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;
}
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;
}
// 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;
}
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
#include <manifest_parser/utils/logging.h>
#include "common/installer_context.h"
+#include "common/mount_base.h"
#include "common/step/step.h"
namespace common_installer {
* * 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;
Status precheck() override;
protected:
+ std::unique_ptr<IZipInterface> CreateZipInterface(
+ const boost::filesystem::path& mount_path) override;
Status UmountPackagePath();
STEP_NAME(MountUpdate)
#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;
--- /dev/null
+// 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_