Refactor functions creating/opening a recovery file 79/159379/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 8 Nov 2017 10:55:44 +0000 (19:55 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 15 Nov 2017 04:13:50 +0000 (13:13 +0900)
Change-Id: Id7d5668aa99c264958ad46ddfd70384a0be0602a
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/recovery_file.cc
src/common/recovery_file.h
src/common/step/configuration/step_configure.cc
src/common/step/recovery/step_open_recovery_file.cc

index 74177f9..af8f55e 100644 (file)
@@ -54,13 +54,13 @@ std::string TruncateNewLine(const char* data) {
 namespace common_installer {
 namespace recovery {
 
-std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFileForPath(
-    const boost::filesystem::path& path) {
+std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFile(
+    const boost::filesystem::path& path, RequestType type) {
   if (bf::exists(path)) {
     LOG(ERROR) << "Recovery file already exists!";
     return nullptr;
   }
-  std::unique_ptr<RecoveryFile> file(new RecoveryFile(path, false));
+  std::unique_ptr<RecoveryFile> file(new RecoveryFile(path, type, false));
   if (file->is_detached()) {
     LOG(ERROR) << "Failed to access file";
     return nullptr;
@@ -68,13 +68,14 @@ std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFileForPath(
   return file;
 }
 
-std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFileForPath(
+std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFile(
     const boost::filesystem::path& path) {
   if (!bf::exists(path)) {
     LOG(ERROR) << "Cannot open recovery file";
     return nullptr;
   }
-  std::unique_ptr<RecoveryFile> file(new RecoveryFile(path, true));
+  std::unique_ptr<RecoveryFile> file(new RecoveryFile(path,
+      RequestType::Unknown, true));
   if (file->is_detached()) {
     LOG(ERROR) << "Failed to read recovery file";
     return nullptr;
@@ -82,8 +83,8 @@ std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFileForPath(
   return file;
 }
 
-RecoveryFile::RecoveryFile(const bf::path& path, bool load)
-    : type_(RequestType::Unknown), path_(path) {
+RecoveryFile::RecoveryFile(const bf::path& path, RequestType type, bool load)
+    : type_(type), path_(path) {
   if (load) {
     if (!ReadFileContent()) {
       path_.clear();
index bf334ae..57fa2a0 100644 (file)
@@ -32,8 +32,8 @@ class RecoveryFile {
    *
    * \return new RecoveryFile object
    */
-  static std::unique_ptr<RecoveryFile> CreateRecoveryFileForPath(
-      const boost::filesystem::path& path);
+  static std::unique_ptr<RecoveryFile> CreateRecoveryFile(
+      const boost::filesystem::path& path, RequestType type);
 
   /**
    * Opens RecoveryFile object for given request
@@ -42,7 +42,7 @@ class RecoveryFile {
    *
    * \return new RecoveryFile object
    */
-  static std::unique_ptr<RecoveryFile> OpenRecoveryFileForPath(
+  static std::unique_ptr<RecoveryFile> OpenRecoveryFile(
       const boost::filesystem::path& path);
 
   /** Desctructor */
@@ -109,7 +109,8 @@ class RecoveryFile {
   bool WriteAndCommitFileContent();
 
  private:
-  RecoveryFile(const boost::filesystem::path& path, bool load);
+  RecoveryFile(const boost::filesystem::path& path, RequestType type,
+      bool load);
 
   bool ReadFileContent();
 
index 7449c15..11a338b 100644 (file)
@@ -153,10 +153,11 @@ Step::Status StepConfigure::process() {
       requestType == RequestType::MountInstall ||
       requestType == RequestType::MountUpdate) {
     std::unique_ptr<recovery::RecoveryFile> recovery_file =
-        recovery::RecoveryFile::CreateRecoveryFileForPath(
+        recovery::RecoveryFile::CreateRecoveryFile(
             GenerateTemporaryPath(
                 context_->root_application_path.get() /
-                (context_->pkg_type.get() + "-recovery")));
+                (context_->pkg_type.get() + "-recovery")),
+            requestType);
     if (!recovery_file) {
       LOG(ERROR) << "Failed to create recovery file";
       return Status::CONFIG_ERROR;
index df38c6b..86c4ab8 100644 (file)
@@ -15,7 +15,7 @@ namespace recovery {
 
 Step::Status StepOpenRecoveryFile::process() {
   std::unique_ptr<recovery::RecoveryFile> recovery_file =
-      RecoveryFile::OpenRecoveryFileForPath(context_->file_path.get());
+      RecoveryFile::OpenRecoveryFile(context_->file_path.get());
   if (!recovery_file) {
     LOG(ERROR) << "Failed to open recovery file";
     return Status::RECOVERY_ERROR;