Add codes to enable ManifestDirectInstall for mount installed pkg 44/167144/8
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 16 Jan 2018 00:12:15 +0000 (09:12 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 5 Feb 2018 08:52:17 +0000 (08:52 +0000)
- Add step to check existance of mount path to determine
  whether pkg is mount installed or not during ManifestDirectInstall.
- Refactoring functions for backup directory.

Change-Id: I582671ae1f679f0553cf11bbcc6c64ff49dce2b4
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/step/mount/step_check_mount_path.cc [new file with mode: 0644]
src/common/step/mount/step_check_mount_path.h [new file with mode: 0644]
src/common/utils/file_util.cc
src/common/utils/file_util.h

diff --git a/src/common/step/mount/step_check_mount_path.cc b/src/common/step/mount/step_check_mount_path.cc
new file mode 100644 (file)
index 0000000..661f763
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (c) 2018 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.
+
+#include "step/mount/step_check_mount_path.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+
+#include <string>
+
+#include "common/paths.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+namespace mount {
+
+Step::Status StepCheckMountPath::process() {
+  bf::path zip_destination_path =
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
+  if (!bf::exists(zip_destination_path))
+    return Status::OK;
+
+  context_->manifest_data.get()->zip_mount_file =
+      strdup(zip_destination_path.c_str());
+
+  return Status::OK;
+}
+
+Step::Status StepCheckMountPath::precheck() {
+  if (context_->root_application_path.get().empty()) {
+    LOG(ERROR) << "root_application_path attribute is empty";
+    return Step::Status::INVALID_VALUE;
+  }
+
+  if (context_->pkgid.get().empty()) {
+    LOG(ERROR) << "pkgid attribute is empty";
+    return Step::Status::PACKAGE_NOT_FOUND;
+  }
+
+  return Step::Status::OK;
+}
+
+}  // namespace mount
+}  // namespace common_installer
diff --git a/src/common/step/mount/step_check_mount_path.h b/src/common/step/mount/step_check_mount_path.h
new file mode 100644 (file)
index 0000000..c302252
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (c) 2018 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_STEP_MOUNT_STEP_CHECK_MOUNT_PATH_H_
+#define COMMON_STEP_MOUNT_STEP_CHECK_MOUNT_PATH_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace mount {
+
+/**
+ * \brief Responsible for checking existance of mount path to perform
+ * ManifestDirectInstall for mount installed pkg.
+ *
+ */
+class StepCheckMountPath : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override;
+
+  STEP_NAME(CheckMouhtPath)
+};
+
+}  // namespace mount
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_MOUNT_STEP_CHECK_MOUNT_PATH_H_
index 93a6374264423a7eebc7969c6fe406f790ee6d93..1f06c59e3c909c28603d4e2b80879e1003169172 100644 (file)
@@ -368,6 +368,21 @@ bool MoveFile(const bf::path& src, const bf::path& dst, bool force) {
   return true;
 }
 
+bool BackupDir(const boost::filesystem::path& src,
+    const boost::filesystem::path& dst, const std::string& entry) {
+  if (!bf::exists(src / entry))
+    return true;
+  if (!MoveDir(src / entry, dst / entry,
+      FS_MERGE_OVERWRITE |
+      FS_COMMIT_COPY_FILE |
+      FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)) {
+    LOG(ERROR) << "Failed to backup file";
+    return false;
+  }
+
+  return true;
+}
+
 int64_t GetUnpackedPackageSize(const bf::path& path) {
   int64_t size = 0;
   int64_t block_size = GetBlockSizeForPath(path);
index b2ed7a7ed2d64eb02be2584b93c9e2e79d9a9f7e..7e3ebf63900a2c883718fdd453268bd853171d8e 100644 (file)
@@ -44,6 +44,9 @@ bool MoveDir(const boost::filesystem::path& src,
 bool MoveFile(const boost::filesystem::path& src,
               const boost::filesystem::path& dst, bool force = false);
 
+bool BackupDir(const boost::filesystem::path& src,
+    const boost::filesystem::path& dst, const std::string& entry);
+
 bool SetDirPermissions(const boost::filesystem::path& path,
                        boost::filesystem::perms permissions);