Change backup logic of StepBackupManifest 07/250307/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 23 Dec 2020 08:51:21 +0000 (17:51 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 23 Dec 2020 11:26:52 +0000 (20:26 +0900)
Change its method from copying it into move and copy
to ensure backup manifest is valid one.
(Move is atomic operation)

Change-Id: Ia65e2104d62f17be3c1c9fb28c44cf756b11977d
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/step/backup/step_backup_manifest.cc
src/common/step/pkgmgr/step_recover_parser_plugins.cc

index bc1fa54..ed09995 100644 (file)
@@ -37,13 +37,12 @@ Step::Status StepBackupManifest::process() {
   bf::path backup_xml_path =
       GetBackupPathForManifestFile(context_->xml_path.get());
   context_->backup_xml_path.set(backup_xml_path);
-  bs::error_code error;
-  bf::copy_file(context_->xml_path.get(), context_->backup_xml_path.get(),
-                bf::copy_option::overwrite_if_exists, error);
-  if (error) {
+  if (!MoveFile(context_->xml_path.get(), backup_xml_path, true) ||
+      !CopyFile(backup_xml_path, context_->xml_path.get())) {
     LOG(ERROR) << "Failed to make a copy of xml manifest file";
     return Status::MANIFEST_ERROR;
   }
+
   LOG(DEBUG) << "Manifest backup created";
   return Status::OK;
 }
index 5cbd53f..250a8bc 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "common/plugins/plugin.h"
 #include "common/step/pkgmgr/step_run_parser_plugins.h"
+#include "common/utils/paths.h"
 
 namespace bf = boost::filesystem;
 namespace ci = common_installer;
@@ -67,7 +68,7 @@ bool StepRecoverParserPlugin::SetXmlPath() {
           context_->is_readonly_package.get()))
       / context_->pkgid.get();
   xml_path += ".xml";
-  context_->xml_path.set(xml_path);
+  context_->xml_path.set(GetBackupPathForManifestFile(xml_path));
   return true;
 }