Fix uninstalling package installed at extended storage 44/142344/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 3 Aug 2017 11:59:18 +0000 (20:59 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 9 Aug 2017 04:45:06 +0000 (04:45 +0000)
Change-Id: Id4ed544792f34a1e6803f03bab4e24ab7c5f75ee
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/configuration/step_check_install_location.cc [new file with mode: 0644]
src/common/step/configuration/step_check_install_location.h [new file with mode: 0644]
src/common/step/filesystem/step_remove_files.cc

diff --git a/src/common/step/configuration/step_check_install_location.cc b/src/common/step/configuration/step_check_install_location.cc
new file mode 100644 (file)
index 0000000..19a5dd2
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/configuration/step_check_install_location.h"
+
+#include <vconf.h>
+#include <vconf-internal-keys.h>
+
+#include <cstring>
+#include <string>
+
+#include "common/installer_context.h"
+
+namespace {
+
+const char kInstalledInternally[] = "installed_internal";
+const char kInstalledExternally[] = "installed_external";
+const char kInstalledExtended[] = "installed_extended";
+
+const char kDefaultStorageVconfKey[] =
+    VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT;
+
+}  // namespace
+
+namespace common_installer {
+namespace configuration {
+
+Step::Status StepCheckInstallLocation::process() {
+  manifest_x* manifest = context_->manifest_data.get();
+  if (!manifest->installed_storage || !strlen(manifest->installed_storage)) {
+    // int type vconf value:
+    // 0 means internal storage, 1 means external storage
+    int default_storage = 0;
+    if (vconf_get_int(kDefaultStorageVconfKey, &default_storage))
+      LOG(WARNING) << "Cannot get default storage type, set internal storage "
+                   << "as default value";
+    if (default_storage == 0)
+      context_->storage.set(Storage::INTERNAL);
+    else if (default_storage == 1)
+      context_->storage.set(Storage::EXTERNAL);
+    else
+      context_->storage.set(Storage::EXTENDED);
+  } else {
+    if (!strcmp(manifest->installed_storage, kInstalledInternally)) {
+      context_->storage.set(Storage::INTERNAL);
+    } else if (!strcmp(manifest->installed_storage, kInstalledExternally)) {
+      context_->storage.set(Storage::EXTERNAL);
+    } else if (!strcmp(manifest->installed_storage, kInstalledExtended)) {
+      context_->storage.set(Storage::EXTENDED);
+    } else {
+      LOG(WARNING) << "Unknown installed storage: "
+                   << manifest->installed_storage;
+      LOG(WARNING) << "Assume installed at internal storage";
+      context_->storage.set(Storage::INTERNAL);
+    }
+  }
+
+  return Status::OK;
+}
+
+}  // namespace configuration
+}  // namespace common_installer
diff --git a/src/common/step/configuration/step_check_install_location.h b/src/common/step/configuration/step_check_install_location.h
new file mode 100644 (file)
index 0000000..3f13a4d
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_CONFIGURATION_STEP_CHECK_INSTALL_LOCATION_H_
+#define COMMON_STEP_CONFIGURATION_STEP_CHECK_INSTALL_LOCATION_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace configuration {
+
+class StepCheckInstallLocation : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+  STEP_NAME(CheckInstallLocation)
+};
+
+}  // namespace configuration
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_CONFIGURATION_STEP_CHECK_INSTALL_LOCATION_H_
index b224e94..817f330 100644 (file)
@@ -102,6 +102,15 @@ Step::Status StepRemoveFiles::process() {
   if (is_error)
     return Status::ERROR;
 
+  // Remove package files at extended storage
+  if (context_->storage.get() == Storage::EXTENDED) {
+    bf::path extended_path =
+        bf::path(GetExtendedRootAppPath(context_->uid.get())) /
+            context_->pkgid.get();
+    if (!RemoveAll(extended_path))
+      return Status::APP_DIR_ERROR;
+  }
+
   return Status::OK;
 }