Skip recover change owner
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_recover_files.cc
index 5bd1ff8..6eb28cb 100644 (file)
@@ -44,7 +44,7 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepRecoverFiles::RecoveryNew() {
-  if (!RemoveAll(context_->GetPkgPath()))
+  if (!ClearPath(context_->GetPkgPath()))
     return Status::RECOVERY_ERROR;
 
   LOG(INFO) << "Package files recovery done";
@@ -64,7 +64,7 @@ Step::Status StepRecoverFiles::RecoveryUpdate() {
         if (iter->path().filename() == kExternalMemoryMountPoint)
           continue;
 
-        if (!RemoveAll(iter->path())) {
+        if (!ClearPath(iter->path())) {
           LOG(ERROR) << "Cannot restore widget files to its correct location";
           return Status::RECOVERY_ERROR;
         }
@@ -81,7 +81,7 @@ Step::Status StepRecoverFiles::RecoveryUpdate() {
         return Status::RECOVERY_ERROR;
     }
 
-    RemoveAll(backup_path);
+    ClearPath(backup_path);
   }
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
@@ -91,7 +91,7 @@ Step::Status StepRecoverFiles::RecoveryMountNew() {
   bf::path zip_location = GetZipPackageLocation(
         context_->GetPkgPath(), context_->pkgid.get());
   Remove(zip_location);
-  RemoveAll(context_->GetPkgPath());
+  ClearPath(context_->GetPkgPath());
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
 }
@@ -112,12 +112,16 @@ Step::Status StepRecoverFiles::RecoveryMountUpdate() {
   // still unpacked due to necessity.
   bf::path backup_path = GetBackupPathForPackagePath(context_->GetPkgPath());
   if (bf::exists(backup_path)) {
-    if (!MoveDir(backup_path, context_->GetPkgPath(),
-                 FS_MERGE_OVERWRITE | FS_COMMIT_COPY_FILE)) {
-      LOG(ERROR) << "Failed to recovery backup file "
-                 << "in recovery of mount update";
-      return Status::APP_DIR_ERROR;
+    for (bf::directory_iterator iter(backup_path);
+         iter != bf::directory_iterator(); ++iter) {
+      ClearPath(context_->GetPkgPath() / iter->path().filename());
+      if (!Move(iter->path(), context_->GetPkgPath())) {
+        LOG(ERROR) << "Failed to recovery backup file(" << iter->path()
+            << ") in recovery of mount update";
+        return Status::RECOVERY_ERROR;
+      }
     }
+    ClearPath(backup_path);
   }
 
   LOG(INFO) << "Package files recovery done";
@@ -129,7 +133,7 @@ Step::Status StepRecoverFiles::RecoveryReadonlyUpdateInstall() {
   bf::path pkg_path =
       bf::path(GetRootAppPath(false, context_->uid.get())) /
       context_->pkgid.get();
-  if (!RemoveAll(pkg_path))
+  if (!ClearPath(pkg_path))
     return Status::RECOVERY_ERROR;
 
   LOG(INFO) << "Package files recovery done";
@@ -146,7 +150,7 @@ Step::Status StepRecoverFiles::Cleanup() {
   if (!bf::exists(backup_path))
     return Status::OK;
 
-  if (!RemoveAll(backup_path)) {
+  if (!ClearPath(backup_path)) {
     LOG(ERROR) << "Failed to remove backup path";
     return Status::RECOVERY_ERROR;
   }
@@ -154,6 +158,10 @@ Step::Status StepRecoverFiles::Cleanup() {
   return Status::OK;
 }
 
+bool StepRecoverFiles::ClearPath(const bf::path& path) {
+  return RemoveAll(path);
+}
+
 }  // namespace filesystem
 }  // namespace common_installer