Fix StepRecoverStorageDirectories 50/218450/12
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 21 Nov 2019 08:27:20 +0000 (17:27 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 13 Dec 2019 07:12:23 +0000 (07:12 +0000)
Recover when shared data directory updated.

Change-Id: Id72db565a8f6668f10990e128d78d4a6f48e50f0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/filesystem/step_recover_storage_directories.cc

index 852ccd4..fdd324a 100644 (file)
@@ -8,17 +8,36 @@
 #include <boost/filesystem/path.hpp>
 #include <boost/system/error_code.hpp>
 
+#include <pkgmgrinfo_basic.h>
+
 #include "common/paths.h"
+#include "common/privileges.h"
+#include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
+#include "common/utils/glist_range.h"
+#include "common/utils/user_util.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
 
 namespace {
 
 const char kDataLocation[] = "data";
 const char kSharedResLocation[] = "shared";
 
-}  // namespace
+bool ShouldCreateSharedDataDir(manifest_x* manifest) {
+  if (ci::ShouldSupportLegacySharedDataDir(manifest->api_version))
+    return true;
 
-namespace bf = boost::filesystem;
+  for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+    if (!strcmp(priv->value, ci::privileges::kPrivForSharedData))
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace
 
 namespace common_installer {
 namespace filesystem {
@@ -43,8 +62,6 @@ bool StepRecoverStorageDirectories::MoveAppStorage(
 }
 
 Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
-  if (context_->request_mode.get() == RequestMode::GLOBAL)
-    return Status::OK;
   if (!context_->GetPkgPath().empty()) {
     bf::path backup_path = common_installer::GetBackupPathForPackagePath(
         context_->GetPkgPath());
@@ -52,6 +69,33 @@ Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
       MoveAppStorage(context_->GetPkgPath(), backup_path, kDataLocation);
       MoveAppStorage(context_->GetPkgPath(), backup_path, kSharedResLocation);
     }
+
+    manifest_x* manifest = context_->manifest_data.get();
+    if (!manifest) {
+      LOG(WARNING) << "Cannot find manifest data. "
+                      "Some directories may not be recovered.";
+      return Status::OK;
+    }
+
+    if (ShouldCreateSharedDataDir(manifest)) {
+      if (context_->request_mode.get() == RequestMode::GLOBAL) {
+        if (!ci::RestorePerUserSharedDataDir(context_->pkgid.get()))
+          return Status::APP_DIR_ERROR;
+      } else {
+        if (!ci::RestoreSharedDataDir(context_->pkgid.get(),
+                context_->uid.get()))
+          return Status::APP_DIR_ERROR;
+      }
+    } else {
+      if (context_->request_mode.get() == RequestMode::GLOBAL) {
+        if (!ci::DeletePerUserSharedDataDir(context_->pkgid.get()))
+          return Status::APP_DIR_ERROR;
+      } else {
+        if (!ci::DeleteSharedDataDir(context_->pkgid.get(),
+                context_->uid.get()))
+          return Status::APP_DIR_ERROR;
+      }
+    }
   }
   return Status::OK;
 }