Skip the security registration if it is unnecessary
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_recover_files.cc
index 5f2f6ca..5bd1ff8 100644 (file)
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
 
+namespace {
+
+const char kExternalMemoryMountPoint[] = ".mmc";
+
+bool Move(const boost::filesystem::path& from,
+    const boost::filesystem::path& to,
+    common_installer::FSFlag flag = common_installer::FSFlag::FS_NONE) {
+  if (bf::is_directory(from)) {
+    if (!common_installer::MoveDir(from, to / from.filename(), flag)) {
+      LOG(ERROR) << "Failed to move directory: " << from;
+      return false;
+    }
+  } else {
+    if (!common_installer::MoveFile(from, to / from.filename())) {
+      LOG(ERROR) << "Fail to move file: " << from;
+      return false;
+    }
+  }
+
+  return true;
+}
+
+}  // namespace
+
 namespace common_installer {
 namespace filesystem {
 
@@ -35,15 +59,29 @@ Step::Status StepRecoverFiles::RecoveryUpdate() {
   if (bf::exists(backup_path)) {
     // Remove pkgdir only if backup original contents is completely done.
     if (backup_done) {
-      if (!RemoveAll(context_->GetPkgPath())) {
-        LOG(ERROR) << "Cannot restore widget files to its correct location";
-        return Status::RECOVERY_ERROR;
+      for (bf::directory_iterator iter(context_->GetPkgPath());
+           iter != bf::directory_iterator(); ++iter) {
+        if (iter->path().filename() == kExternalMemoryMountPoint)
+          continue;
+
+        if (!RemoveAll(iter->path())) {
+          LOG(ERROR) << "Cannot restore widget files to its correct location";
+          return Status::RECOVERY_ERROR;
+        }
       }
       // it may fail during recovery.
       recovery_file->set_backup_done(false);
       recovery_file->WriteAndCommitFileContent();
     }
-    (void) MoveDir(backup_path, context_->GetPkgPath(), FS_MERGE_OVERWRITE);
+
+    // create copy of old package content skipping the external memory mount point
+    for (bf::directory_iterator iter(backup_path);
+         iter != bf::directory_iterator(); ++iter) {
+      if (!Move(iter->path(), context_->GetPkgPath()))
+        return Status::RECOVERY_ERROR;
+    }
+
+    RemoveAll(backup_path);
   }
   LOG(INFO) << "Package files recovery done";
   return Status::OK;