From 7dc3ecb0ac8498551c6668ffa154155751bcdb59 Mon Sep 17 00:00:00 2001 From: ilho kim Date: Thu, 12 Jan 2023 09:52:13 +0900 Subject: [PATCH] Fix StepCopyBackup's undo operation 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 --- src/common/step/backup/step_copy_backup.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/common/step/backup/step_copy_backup.cc b/src/common/step/backup/step_copy_backup.cc index 2c5f8ba..82d98e4 100644 --- a/src/common/step/backup/step_copy_backup.cc +++ b/src/common/step/backup/step_copy_backup.cc @@ -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 -- 2.7.4