Force backup 69/103169/8
authorPiotr Ganicz <p.ganicz@samsung.com>
Wed, 7 Dec 2016 10:38:34 +0000 (11:38 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Fri, 6 Jan 2017 07:04:49 +0000 (23:04 -0800)
This commit deletes old backup files that can remain in system
after previous invalid installation before creating a new backup.

Change-Id: I9c983823f7af7b43151799929d5008025e2c04ed

src/common/step/backup/step_backup_icons.cc
src/common/step/backup/step_backup_manifest.cc
src/common/step/backup/step_copy_backup.cc
src/common/utils/file_util.cc
src/common/utils/file_util.h

index df532ef41496605b6eaa602d678ee71598bd226f..c7684b2b88adfb0caf1371b44e6b86b81582d2ca 100644 (file)
@@ -48,7 +48,7 @@ Step::Status StepBackupIcons::process() {
 
   // backup
   for (auto& pair : icons_) {
-    if (!MoveFile(pair.first, pair.second)) {
+    if (!MoveFile(pair.first, pair.second, true)) {
       LOG(ERROR) << "Cannot create backup for icon: " << pair.first;
       return Status::ICON_ERROR;
     }
index 26ffebfcd63ffed28407d96b17426c85cef717ff..e1f2f384c8834c431271d1dd43a3a3bb89c59342 100644 (file)
@@ -37,7 +37,8 @@ Step::Status StepBackupManifest::process() {
       GetBackupPathForManifestFile(context_->xml_path.get());
   context_->backup_xml_path.set(backup_xml_path);
   bs::error_code error;
-  bf::copy(context_->xml_path.get(), context_->backup_xml_path.get(), error);
+  bf::copy_file(context_->xml_path.get(), context_->backup_xml_path.get(),
+                bf::copy_option::overwrite_if_exists, error);
   if (error) {
     LOG(ERROR) << "Failed to make a copy of xml manifest file";
     return Status::MANIFEST_ERROR;
index 3058c523842230309df0a6ce9cb24072e5da30b1..4316f7fea1b8e6e4ce08e1ab5d3be446265408f1 100644 (file)
@@ -49,6 +49,9 @@ Step::Status StepCopyBackup::precheck() {
 }
 
 Step::Status StepCopyBackup::process() {
+  // if backup file exists
+  if (!CleanBackupDirectory())
+    return Status::APP_DIR_ERROR;
   if (!Backup())
     return Status::APP_DIR_ERROR;
 
@@ -92,7 +95,6 @@ bool StepCopyBackup::Backup() {
   // create backup directory
   bs::error_code error;
   bf::create_directories(backup_path_, error);
-
   // create copy of old package content skipping the external memory mount point
   for (bf::directory_iterator iter(context_->pkg_path.get());
        iter != bf::directory_iterator(); ++iter) {
index fe4fe3c8850d7c9d826cb0216d8143bf5e0f28a6..99d54f4de7021112decc034404f4ea4710c2f075 100644 (file)
@@ -267,8 +267,8 @@ bool MoveDir(const bf::path& src, const bf::path& dst, FSFlag flags) {
   return true;
 }
 
-bool MoveFile(const bf::path& src, const bf::path& dst) {
-  if (bf::exists(dst))
+bool MoveFile(const bf::path& src, const bf::path& dst, bool force) {
+  if (!force && bf::exists(dst))
     return false;
   bs::error_code error;
   bf::rename(src, dst, error);
index 1abc7fe9fcecb551d11cf34c3703eae29061b896..416d2b25639fece2fdf98d607f4fd4fcdb9d8857 100644 (file)
@@ -37,7 +37,7 @@ bool MoveDir(const boost::filesystem::path& src,
              const boost::filesystem::path& dst, FSFlag flags = FS_NONE);
 
 bool MoveFile(const boost::filesystem::path& src,
-              const boost::filesystem::path& dst);
+              const boost::filesystem::path& dst, bool force = false);
 
 bool SetDirPermissions(const boost::filesystem::path& path,
                        boost::filesystem::perms permissions);