Reflect pending cache when process operation end
[platform/core/appfw/app-installers.git] / src / common / installer / app_installer.cc
index 27de74d..bbed096 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <unistd.h>
 
+#include <algorithm>
+#include <cmath>
 #include <cstdio>
 #include <fstream>
 #include <TTraceWrapper.h>
@@ -43,7 +45,6 @@
 #include "common/step/filesystem/step_migrate_legacy_external_image.h"
 #include "common/step/filesystem/step_move_installed_storage.h"
 #include "common/step/filesystem/step_optional_acquire_external_storage.h"
-#include "common/step/filesystem/step_recover_change_owner.h"
 #include "common/step/filesystem/step_recover_external_storage.h"
 #include "common/step/filesystem/step_recover_files.h"
 #include "common/step/filesystem/step_recover_globalapp_symlinks.h"
@@ -110,6 +111,7 @@ const char kLogFileName[] = LOGDIR"/app-installers.log";
 const char kHistoryFileName[] = LOGDIR"/installation-history.log";
 const int kLogRotationSize = 1024 * 256;  // 256KB
 const int kLogMaximumRotation = 3;
+const int kSignalCount = 10;
 
 }
 
@@ -234,6 +236,8 @@ AppInstaller::Result AppInstaller::Process() {
 
   unsigned total_steps = steps_.size();
   unsigned current_step = 1;
+  double div = total_steps / static_cast<double>(kSignalCount);
+  int interval = std::max(1, static_cast<int>(std::round(div)));
 
   for (it_ = steps_.begin(); it_ != steps_.end(); ++it_, ++current_step) {
     status_ = SafeExecute(*it_, &Step::precheck, "precheck");
@@ -250,9 +254,14 @@ AppInstaller::Result AppInstaller::Process() {
     if (!context_->pkgid.get().empty())
       history_logger_.LogHistoryStart(context_->pkgid.get(),
           GetPackageVersion(), context_->request_type.get());
-    SendProgress(current_step * kProgressRange / total_steps);
+
+    if (current_step == total_steps || current_step % interval == 0)
+      SendProgress(current_step * kProgressRange / total_steps);
   }
 
+  if (!context_->pkgid.get().empty())
+    pkgmgr_parser_update_pending_cache(context_->pkgid.get().c_str());
+
   return result_;
 }
 
@@ -516,7 +525,6 @@ void AppInstaller::RecoverySteps() {
   AddStep<ci::filesystem::StepRecoverFiles>();
   AddStep<ci::pkgmgr::StepRecoverPrivSharedres>();
   AddStep<ci::mount::StepMountRecover>();
-  AddStep<ci::filesystem::StepRecoverChangeOwner>();
   AddStep<ci::pkgmgr::StepRecoverApplication>();
   AddStep<ci::security::StepRecoverTrustAnchor>();
   AddStep<ci::security::StepRecoverSecurity>();
@@ -871,7 +879,7 @@ void AppInstaller::SendProgress(int progress) {
 }
 
 void AppInstaller::SendFinished(Step::Status process_status) {
-  pkgmgr_parser_clear_cache_memory_db();
+  pkgmgr_parser_update_pending_cache(context_->pkgid.get().c_str());
 
   if (!SendStartIfNotSent(false))
     return;
@@ -887,6 +895,7 @@ Step::Status AppInstaller::SafeExecute(std::unique_ptr<Step> const& step_ptr,
   Step::Status process_status = Step::Status::OK;
   try {
     TTRACE(TTRACE_TAG_APP, "%s_%s", step_ptr->name(), name.c_str());
+    LOG(DEBUG) << step_ptr->name() << "_" << name.c_str();
     process_status = ((*step_ptr).*method)();
   } catch (const std::exception& err) {
     LOG(ERROR) << "Exception occurred in " << name.c_str() << "(): "