Extending "shared" directory functionality. 80/44680/2
authorPawel Sikorski <p.sikorski@samsung.com>
Thu, 23 Jul 2015 12:51:56 +0000 (14:51 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 28 Jul 2015 07:36:30 +0000 (09:36 +0200)
Tizen 3.x defines new requirement, in which resources located
in "res/wgt/shared" folder should be moved to package ./shared directory.
Additionally, symbolic link should be created ./res/wgt/shared -> ./shared

On the other hand, tizen 2.x applications, should follow old policy (no data
movement)

Solution:
Introduction of derived StepWgtCreateStorageDirectories that adds above
functionality.

Change-Id: I3de99339f7d1123d9501f94577b9e2a79383511d

src/common/context_installer.h
src/common/step/step_check_signature.cc
src/common/step/step_create_storage_directories.cc
src/common/step/step_create_storage_directories.h
src/common/step/step_unzip.h
src/tpk/step/step_parse.cc
src/wgt/CMakeLists.txt
src/wgt/step/step_parse.cc
src/wgt/step/step_wgt_create_storage_directories.cc [new file with mode: 0644]
src/wgt/step/step_wgt_create_storage_directories.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index cd18579..0534fd6 100644 (file)
@@ -24,8 +24,10 @@ namespace common_installer {
 class ConfigData {
  public:
   ConfigData() {}
-  Property<std::string> application_name;
-  Property<std::string> required_version;
+  /** version pointed in <application> tag*/
+  Property<std::string> required_api_version;
+  /** version pointed int <widget> tag*/
+  Property<std::string> required_tizen_version;
 };
 
 class BackendData {
index 79fe0f6..3a7cc92 100644 (file)
@@ -224,7 +224,7 @@ Step::Status StepCheckSignature::process() {
   // TODO(t.iwanek): refactoring, move to wgt backend
   bool is_webapp = context_->pkg_type.get() == "wgt";
   if (!ValidatePrivilegeLevel(level, is_webapp,
-      context_->config_data.get().required_version.get().c_str(),
+      context_->config_data.get().required_api_version.get().c_str(),
       context_->manifest_data.get()->privileges))
     return Status::ERROR;
 
index f6d95d6..60e2fb8 100644 (file)
@@ -13,36 +13,71 @@ namespace bs = boost::system;
 
 namespace {
 
-const char kDataLocation[] = "data";
-const char kSharedLocation[] = "shared";
+const char kData[] = "data";
+const char kShared[] = "shared";
+const char kSharedData[] = "data";
+const char kSharedTrusted[] = "trusted";
 
-bool CreateStorageDirectoriesForPath(const bf::path& path) {
+}  // namespace
+
+namespace common_installer {
+namespace create_storage {
+
+common_installer::Step::Status StepCreateStorageDirectories::process() {
+  if (!ShareDir())
+    return Status::ERROR;
+  if (!PrivateDir())
+    return Status::ERROR;
+
+  return Status::OK;
+}
+
+bool StepCreateStorageDirectories::ShareDir() {
   bs::error_code error_code;
-  bf::path data_path = path / kDataLocation;
-  bf::create_directory(data_path, error_code);
-  if (error_code) {
-    LOG(ERROR) << "Failed to create private directory for widget";
-    return false;
-  }
-  bf::path shared_path = path / kSharedLocation;
+  bf::path shared_path = context_->pkg_path.get() / kShared;
   bf::create_directory(shared_path, error_code);
   if (error_code) {
-    LOG(ERROR) << "Failed to create shared directory for widget";
+    LOG(ERROR) << "Failed to create shared directory for package";
     return false;
   }
+
+  if (!SubShareDir())
+    return false;
+
   return true;
 }
 
-}  // namespace
+bool StepCreateStorageDirectories::SubShareDir() {
+  bs::error_code error_code;
+  bf::path shared_path = context_->pkg_path.get() / kShared;
+  bf::path shared_trusted_path = shared_path / kSharedTrusted;
+  bf::create_directory(shared_trusted_path, error_code);
+  if (error_code) {
+    LOG(ERROR) << "Failed to create shared/trusted directory for package";
+    return false;
+  }
 
-namespace common_installer {
-namespace create_storage {
+  bf::path shared_data_path = shared_path / kSharedData;
+  bf::create_directory(shared_data_path, error_code);
+  if (error_code) {
+    LOG(ERROR) << "Failed to create shared/data directory for package";
+    return false;
+  }
 
-common_installer::Step::Status StepCreateStorageDirectories::process() {
-  if (!CreateStorageDirectoriesForPath(context_->pkg_path.get()))
-    return Status::ERROR;
-  return Status::OK;
+  return true;
+}
+
+bool StepCreateStorageDirectories::PrivateDir() {
+  bs::error_code error_code;
+  bf::path data_path = context_->pkg_path.get() / kData;
+  bf::create_directory(data_path, error_code);
+  if (error_code) {
+    LOG(ERROR) << "Failed to create private directory for package";
+    return false;
+  }
+  return true;
 }
 
+
 }  // namespace create_storage
 }  // namespace common_installer
index 44e29b8..d4a4d71 100644 (file)
 namespace common_installer {
 namespace create_storage {
 
+/**
+ * \brief Installation.
+ *        Responsible for creating shared and data directories (wgt/tpk)
+ *
+ * * process method implements creation of data and shared directories for
+ *   package.
+ * * Other methods are empty.
+ *
+ * CreateStorageDirectories works on below directories:
+ * * context_->pkg_path.get(), eg:
+ *   * TZ_SYS_RW/PKGID/<new-dir> (/usr/apps/PKGID/<new-dir>)
+ *   * TZ_SER_APPS/PKGID/<new-dir>  (/{HOME}/apps_rw/PKGID/<new-dir>)
+ */
 class StepCreateStorageDirectories : public common_installer::Step {
  public:
   using Step::Step;
@@ -20,6 +33,11 @@ class StepCreateStorageDirectories : public common_installer::Step {
   Status undo() override { return Status::OK; }
   Status precheck() override { return Status::OK; }
 
+ protected:
+  bool ShareDir();
+  bool SubShareDir();
+  bool PrivateDir();
+
   SCOPE_LOG_TAG(CreateStorageDirectories)
 };
 
index bb032b8..b0e8135 100644 (file)
@@ -23,6 +23,11 @@ namespace unzip {
  * rough space requirements vs availability.
  * Since process method unpacks the package to given directory, undo method
  * removes them.
+ *
+ * Unzip unpacks resources to following directory:
+ * * TZ_SYS_RW/tmpuniquedir (/usr/apps/tmpuniquedir)
+ * * TZ_SER_APPS/tmpdir  (/{HOME}/apps_rw/tmpuniquedir)
+ * ContextInstaller::unpacked_dir_path points to this location.
  */
 class StepUnzip : public Step {
  public:
index 763ac7d..54bfdf1 100644 (file)
@@ -147,8 +147,7 @@ bool StepParse::SetContextByManifestParser(XmlTree* tree) {
   }
 
   // set context_
-  context_->config_data.get().application_name.set(label->content());
-  context_->config_data.get().required_version.set(
+  context_->config_data.get().required_api_version.set(
       manifest->attr("api-version"));
   context_->pkgid.set(manifest->attr("package"));
   context_->manifest_data.set(static_cast<manifest_x*>(
index f2a3be8..19ed590 100644 (file)
@@ -6,6 +6,7 @@ SET(SRCS
   step/step_parse.cc
   step/step_rds_parse.cc
   step/step_rds_modify.cc
+  step/step_wgt_create_storage_directories.cc
   step/step_wgt_resource_directory.cc
   wgt_app_query_interface.cc
   wgt_backend.cc
index 791ed2d..92f1420 100755 (executable)
@@ -291,15 +291,11 @@ common_installer::Step::Status StepParse::process() {
   if (short_name_set.begin() != short_name_set.end())
     short_name = short_name_set.begin()->second;
 
-  const std::string& version = wgt_info->version();
+  const std::string& tizen_version = wgt_info->version();
   const std::string& required_api_version = info->required_version();
 
-  if (manifest->uiapplication->label) {
-    context_->config_data.get().application_name.set(
-        std::string(manifest->uiapplication->label->name));
-  }
-
-  context_->config_data.get().required_version.set(required_api_version);
+  context_->config_data.get().required_api_version.set(required_api_version);
+  context_->config_data.get().required_tizen_version.set(tizen_version);
   context_->pkgid.set(std::string(manifest->package));
 
   std::shared_ptr<const PermissionsInfo> perm_info =
@@ -327,7 +323,7 @@ common_installer::Step::Status StepParse::process() {
   LOG(DEBUG) << "  id          = " <<  info->id();
   LOG(DEBUG) << "  name        = " <<  name;
   LOG(DEBUG) << "  short_name  = " <<  short_name;
-  LOG(DEBUG) << "  version     = " <<  version;
+  LOG(DEBUG) << "  tizen_version     = " <<  tizen_version;
   LOG(DEBUG) << "  icon        = " <<  manifest->uiapplication->icon->name;
   LOG(DEBUG) << "  api_version = " <<  info->required_version();
   LOG(DEBUG) << "  privileges -[";
diff --git a/src/wgt/step/step_wgt_create_storage_directories.cc b/src/wgt/step/step_wgt_create_storage_directories.cc
new file mode 100644 (file)
index 0000000..ed661b4
--- /dev/null
@@ -0,0 +1,85 @@
+// Copyright (c) 2015 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 "wgt/step/step_wgt_create_storage_directories.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
+
+#include "common/utils/file_util.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace {
+
+const char kSharedLocation[] = "shared";
+const char kResWgt[] = "res/wgt";
+
+}  // namespace
+
+namespace wgt {
+namespace create_storage {
+
+common_installer::Step::Status StepWgtCreateStorageDirectories::process() {
+  if (!PrivateDir())
+    return Status::ERROR;
+
+  char rel_version =
+      context_->config_data.get().required_tizen_version.get().at(0);
+
+  if ((rel_version-'0') < 3) {
+    LOG(DEBUG) << "Shared directory preparation for tizen 2.x";
+    if (!ShareDir())
+      return Status::ERROR;
+  } else {
+    LOG(DEBUG) << "Shared directory preparation for tizen 3.x";
+    if (!ShareDirFor3x())
+      return Status::ERROR;
+  }
+
+  if (!SubShareDir())
+    return Status::ERROR;
+
+  return Status::OK;
+}
+
+bool StepWgtCreateStorageDirectories::ShareDirFor2x() {
+  bs::error_code error_code;
+  bf::path shared_path = context_->pkg_path.get() / kSharedLocation;
+  bf::create_directory(shared_path, error_code);
+  if (error_code) {
+    LOG(ERROR) << "Failed to create shared directory for widget";
+    return false;
+  }
+  return true;
+}
+
+bool StepWgtCreateStorageDirectories::ShareDirFor3x() {
+  bf::path res_wgt_path = context_->pkg_path.get() / kResWgt;
+  if (!bf::exists(res_wgt_path / kSharedLocation)) {
+    if (!ShareDir())
+      return false;
+  } else {
+    bf::path src = res_wgt_path / kSharedLocation;
+    bf::path dst = context_->pkg_path.get() / kSharedLocation;
+    if (!common_installer::MoveDir(src, dst)) {
+      LOG(ERROR) << "Failed to move shared data from res/wgt to shared";
+      return false;
+    }
+
+    bs::error_code error_code;
+    bf::create_symlink(dst, src, error_code);
+    if (error_code) {
+      LOG(ERROR) << "Failed to create symbolic link for shared dir"
+        << boost::system::system_error(error_code).what();
+      return false;
+    }
+  }  // else
+  return true;
+}
+
+}  // namespace create_storage
+}  // namespace wgt
diff --git a/src/wgt/step/step_wgt_create_storage_directories.h b/src/wgt/step/step_wgt_create_storage_directories.h
new file mode 100644 (file)
index 0000000..3f92a73
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (c) 2015 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.
+
+#ifndef WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_
+#define WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_
+
+#include "common/step/step_create_storage_directories.h"
+#include "utils/logging.h"
+
+namespace wgt {
+namespace create_storage {
+
+/**
+ * \brief Installation (WGT).
+ *        Responsible for creating shared and data directories.
+ *        It extends StepCreateStorageDirectories (it adds distinction between
+ *        2.x and 3.x shared dir handling
+ *
+ * process method implements creation of shared and data directories.
+ * Depending on tizen required version it can also move "shared" resources
+ * from ./res/wgt/shared to ./shared dir (and create symlink back
+ * to ./res/wgt/shared).
+ *
+ * StepWgtCreateStorageDirectories works on following directory:
+ * * TZ_SYS_RW/PKGID (/usr/apps/PKGID)
+ * * TZ_SER_APPS/PKGID  (/{HOME}/apps_rw/PKGID)
+ */
+class StepWgtCreateStorageDirectories :
+    public common_installer::create_storage::StepCreateStorageDirectories {
+ public:
+  using common_installer::create_storage::
+      StepCreateStorageDirectories::StepCreateStorageDirectories;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+ private:
+  bool ShareDirFor2x();
+  bool ShareDirFor3x();
+
+  SCOPE_LOG_TAG(CreateWgtStorageDirectories)
+};
+
+}  // namespace create_storage
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_
index 4b3dd3d..e196503 100644 (file)
@@ -13,7 +13,6 @@
 #include "common/step/step_copy.h"
 #include "common/step/step_copy_backup.h"
 #include "common/step/step_copy_storage_directories.h"
-#include "common/step/step_create_storage_directories.h"
 #include "common/step/step_generate_xml.h"
 #include "common/step/step_parse.h"
 #include "common/step/step_register_app.h"
@@ -34,6 +33,7 @@
 #include "wgt/step/step_parse.h"
 #include "wgt/step/step_rds_parse.h"
 #include "wgt/step/step_rds_modify.h"
+#include "wgt/step/step_wgt_create_storage_directories.h"
 #include "wgt/step/step_wgt_resource_directory.h"
 #include "wgt/wgt_app_query_interface.h"
 
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
       installer.AddStep<wgt::check_settings::StepCheckSettingsLevel>();
       installer.AddStep<wgt::wgt_resources::StepWgtResourceDirectory>();
       installer.AddStep<ci::copy::StepCopy>();
-      installer.AddStep<ci::create_storage::StepCreateStorageDirectories>();
+      installer.AddStep<wgt::create_storage::StepWgtCreateStorageDirectories>();
       installer.AddStep<wgt::symbolic_link::StepCreateSymbolicLink>();
       installer.AddStep<ci::generate_xml::StepGenerateXml>();
       installer.AddStep<ci::register_app::StepRegisterApplication>();