Fix StepCopyBackup's undo operation 26/286726/2
authorilho kim <ilho159.kim@samsung.com>
Thu, 12 Jan 2023 00:52:13 +0000 (09:52 +0900)
committerilho kim <ilho159.kim@samsung.com>
Fri, 13 Jan 2023 07:30:55 +0000 (07:30 +0000)
Fix the operation of restoring the backup directory which created in the
step, the backup directory's ownership and smack label are not set

Change-Id: I6d5613461ba4c773c3450a1d61b67d4ed9f13d6b
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/common/step/backup/step_copy_backup.cc

index 2c5f8ba..82d98e4 100644 (file)
@@ -276,16 +276,24 @@ bool StepCopyBackup::CleanBackupDirectory() {
 
 bool StepCopyBackup::RollbackApplicationDirectory() {
   bs::error_code error;
-  if (bf::exists(context_->GetPkgPath())) {
-    bf::remove_all(context_->GetPkgPath(), error);
-    if (error) {
-      return false;
+  bf::path root_path = context_->GetPkgPath();
+  if (bf::exists(root_path)) {
+    for (bf::directory_iterator iter(root_path);
+         iter != bf::directory_iterator(); ++iter) {
+      bf::remove_all(iter->path(), error);
+      if (error)
+        return false;
     }
   }
 
-  if (!MoveDir(backup_path_, context_->GetPkgPath())) {
-    return false;
+  for (bf::directory_iterator iter(backup_path_);
+       iter != bf::directory_iterator(); ++iter) {
+    if (!Move(iter->path(), root_path)) {
+      LOG(ERROR) << "Failed to recovery backup file(" << iter->path() << ")";
+      return false;
+    }
   }
+  RemoveAll(backup_path_);
 
   uid_t uid = context_->uid.get();
   // restore ownership changed during installation