Restore 2.x directory structure of package 27/43827/7 accepted/tizen/mobile/20150729.073548 accepted/tizen/tv/20150729.073605 accepted/tizen/wearable/20150729.073624 submit/tizen/20150729.044523
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 12 Jun 2015 13:35:18 +0000 (15:35 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 28 Jul 2015 07:36:30 +0000 (09:36 +0200)
Example:
  $HOME/apps_rw/{PKGID}/bin/{APPID_1}, {APPID_2} (symlink)
  $HOME/apps_rw/{PKGID}/data/
  $HOME/apps_rw/{PKGID}/shared/data/
  $HOME/apps_rw/{PKGID}/shared/res/
  $HOME/apps_rw/{PKGID}/shared/trusted/
  $HOME/apps_rw/{PKGID}/res/wgt/... (all wgt contents)

Installation/Update/Deinstallation/RDS modes should work.

BUT NOTE THAT:
 - runtime requires to known where to look for widget files after
   this change,
 - security-manager should not require app_id,
 - security-manager must not block installation when path without
   app_id is passed,
 - C API must be aware of new paths.

Change-Id: Idc3609ae355389a9df696c85315e5bcd71a9a3ef

12 files changed:
src/common/security_registration.cc
src/common/step/step_copy.cc
src/common/step/step_copy_backup.cc
src/common/step/step_generate_xml.cc
src/tpk/step/step_copy_manifest_xml.cc
src/tpk/step/step_create_symbolic_link.cc
src/wgt/CMakeLists.txt
src/wgt/step/step_create_symbolic_link.cc
src/wgt/step/step_rds_modify.cc
src/wgt/step/step_wgt_resource_directory.cc [new file with mode: 0644]
src/wgt/step/step_wgt_resource_directory.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index c9542e3..a00463f 100644 (file)
@@ -129,7 +129,7 @@ bool RegisterSecurityContextForApps(
       return false;
     }
     if (!RegisterSecurityContext(ui->appid, pkg_id,
-        path/ui->appid, manifest)) {
+        path, manifest)) {
       return false;
     }
   }
@@ -141,7 +141,7 @@ bool RegisterSecurityContextForApps(
       return false;
     }
     if (!RegisterSecurityContext(svc->appid, pkg_id,
-        path/svc->appid, manifest)) {
+        path, manifest)) {
       return false;
     }
   }
index 3bd888f..a38c5b7 100644 (file)
@@ -62,18 +62,6 @@ Step::Status StepCopy::process() {
 
   bf::path install_path = context_->pkg_path.get();
 
-  // FIXME: correctly order app's data.
-  // If there is 1 app in package, the app's data are stored in
-  // <pkg_path>/<app_id>/
-  // If there are >1 apps in the package, app's data are stored in <pkg_path>
-  // considering that multiple apps data are already separated in folders.
-  manifest_x *m = context_->manifest_data.get();
-  if ((m->uiapplication && !m->uiapplication->next && !m->serviceapplication) ||
-      (m->serviceapplication && !m->serviceapplication->next &&
-      !m->uiapplication)) {
-    install_path /= bf::path(context_->manifest_data.get()->mainapp_id);
-  }
-
   bs::error_code error;
   bf::create_directories(install_path.parent_path(), error);
   if (error) {
index 68c6333..3d0359e 100644 (file)
@@ -27,16 +27,6 @@ Step::Status StepCopyBackup::process() {
 
   install_path_ = context_->pkg_path.get();
 
-  // FIXME: correctly order app's data.
-  // If there is 1 app in package, app's data are stored in <pkg_path>/<app_id>
-  // If there are >1 apps in package, app's data are stored in <pkg_path>
-  // considering that multiple apps data are already separated in folders.
-  manifest_x *m = context_->manifest_data.get();
-  if ((m->uiapplication && !m->uiapplication->next && !m->serviceapplication) ||
-      (m->serviceapplication && !m->serviceapplication->next &&
-      !m->uiapplication))
-    install_path_ /= bf::path(context_->manifest_data.get()->mainapp_id);
-
   backup_path_ = GetBackupPathForPackagePath(context_->pkg_path.get());
 
   // backup old content
index 0e773d2..0f197aa 100755 (executable)
@@ -49,7 +49,7 @@ Step::Status StepGenerateXml::GenerateApplicationCommonXml(T* app,
   xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST app->appid);
 
   // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-  fs::path exec_path = context_->pkg_path.get() / fs::path(app->appid)
+  fs::path exec_path = context_->pkg_path.get()
       / fs::path("bin") / fs::path(app->appid);
   xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
                               BAD_CAST exec_path.string().c_str());
index 2df0818..517965a 100644 (file)
@@ -80,8 +80,6 @@ namespace {
       try {
         // Find (ui|service)-application element, and get appid
         if (boost::regex_search(line, m, appid_pattern)) {
-          std::string appid = m[3].str();
-          pkg_path /= bf::path(appid);
           pkg_path /= bf::path("bin");
 
           result = boost::regex_replace(line, appid_exec_replace_pattern,
index 309b2c5..9cebb19 100644 (file)
@@ -29,7 +29,7 @@ bool CreateSymLink(T *app, ContextInstaller* context) {
   boost::system::error_code boost_error;
 
   for (; app != nullptr; app=app->next) {
-    fs::path bindir = context->pkg_path.get() / fs::path(app->appid) /
+    fs::path bindir = context->pkg_path.get() /
         fs::path("bin");
     LOG(INFO) << "Creating dir: " << bindir;
     if (!common_installer::CreateDir(bindir)) {
@@ -64,7 +64,6 @@ bool CreateSymLink(T *app, ContextInstaller* context) {
     if (app->icon && app->icon->name) {
       // Check if the icon file actually exists
       fs::path src_icon_path = fs::path(context->pkg_path.get())
-          / fs::path(app->appid)
           / fs::path(app->icon->name);
       if (fs::exists(src_icon_path)) {
         // copy icon to the destination dir
@@ -99,8 +98,7 @@ bool RemoveSymLink(T *app, ContextInstaller* context) {
    * So we don't remove the bin/ directory.
    */
   for (; app != nullptr; app=app->next) {
-    fs::path exec_path = fs::path(context->pkg_path.get()) /
-        fs::path(app->appid) / fs::path("bin");
+    fs::path exec_path = fs::path(context->pkg_path.get()) / fs::path("bin");
     fs::remove_all(exec_path / fs::path(app->appid));
   }
   return true;
index 6254ac1..f2a3be8 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_resource_directory.cc
   wgt_app_query_interface.cc
   wgt_backend.cc
 )
index 1144899..16309a5 100644 (file)
@@ -36,7 +36,7 @@ common_installer::Step::Status StepCreateSymbolicLink::process() {
   for (; ui != nullptr; ui = ui->next) {
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
     fs::path exec_path =
-        context_->pkg_path.get() / fs::path(ui->appid)
+        context_->pkg_path.get()
             / fs::path("bin");
     common_installer::CreateDir(exec_path);
 
@@ -51,9 +51,7 @@ common_installer::Step::Status StepCreateSymbolicLink::process() {
   }
   for (; svc != nullptr; svc = svc->next) {
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-    fs::path exec_path =
-        context_->pkg_path.get() / fs::path(svc->appid)/
-            fs::path("bin");
+    fs::path exec_path = context_->pkg_path.get() / fs::path("bin");
     common_installer::CreateDir(exec_path);
 
     exec_path /= fs::path(svc->appid);
@@ -75,16 +73,12 @@ common_installer::Step::Status StepCreateSymbolicLink::undo() {
   serviceapplication_x* svc = context_->manifest_data.get()->serviceapplication;
 
   for (; ui != nullptr; ui = ui->next) {
-    fs::path exec_path =
-        context_->pkg_path.get() / fs::path(ui->appid)
-            / fs::path("bin");
+    fs::path exec_path = context_->pkg_path.get() / fs::path("bin");
     if (fs::exists(exec_path))
       fs::remove_all(exec_path);
   }
   for (; svc != nullptr; svc = svc->next) {
-    fs::path exec_path =
-        context_->pkg_path.get() / fs::path(svc->appid)
-            / fs::path("bin");
+    fs::path exec_path = context_->pkg_path.get() / fs::path("bin");
     if (fs::exists(exec_path))
       fs::remove_all(exec_path);
   }
index 73be210..a690b72 100644 (file)
@@ -56,8 +56,7 @@ common_installer::Step::Status StepRDSModify::process() {
   }
   context_->pkg_path.set(
         context_->root_application_path.get() /context_->pkgid.get());
-  bf::path install_path = context_->pkg_path.get() /
-      context_->manifest_data.get()->mainapp_id;
+  bf::path install_path = context_->pkg_path.get() / "res" / "wgt";
   bf::path unzip_path = context_->unpacked_dir_path.get();
   if (!AddFiles(unzip_path, install_path) ||
      !ModifyFiles(unzip_path, install_path) ||
diff --git a/src/wgt/step/step_wgt_resource_directory.cc b/src/wgt/step/step_wgt_resource_directory.cc
new file mode 100644 (file)
index 0000000..4563a07
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright (c) 2015 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.
+
+#include "wgt/step/step_wgt_resource_directory.h"
+
+#include <boost/filesystem/path.hpp>
+
+#include "common/utils/file_util.h"
+#include "common/utils/logging.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace wgt {
+namespace wgt_resources {
+
+common_installer::Step::Status StepWgtResourceDirectory::process() {
+  bf::path temp_path = context_->unpacked_dir_path.get();
+  temp_path += ".temp";
+  bf::path resource_path = context_->unpacked_dir_path.get() / "res/wgt";
+
+  if (!common_installer::MoveDir(context_->unpacked_dir_path.get(),
+                                        temp_path)) {
+    LOG(ERROR) << "Failed to move: " << context_->unpacked_dir_path.get()
+               << " to: " << temp_path;
+    return Status::ERROR;
+  }
+  bs::error_code error;
+  bf::create_directories(resource_path.parent_path(), error);
+  if (error) {
+    LOG(ERROR) << "Failed to create proper directory structure in widget";
+    return Status::ERROR;
+  }
+  if (!common_installer::MoveDir(temp_path, resource_path)) {
+    LOG(ERROR) << "Failed to move: " << temp_path << " to: " << resource_path;
+    return Status::ERROR;
+  }
+
+  LOG(INFO) << "Widget content moved to res/wgt subdirectory";
+  return Status::OK;
+}
+
+}  // namespace wgt_resources
+}  // namespace wgt
diff --git a/src/wgt/step/step_wgt_resource_directory.h b/src/wgt/step/step_wgt_resource_directory.h
new file mode 100644 (file)
index 0000000..0f9e90a
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (c) 2015 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 WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_
+#define WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_
+
+#include "common/app_installer.h"
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace wgt {
+namespace wgt_resources {
+
+//
+// This step fixes unpacked directory structure so that all widget content
+// is moved from root path to res/wgt before we copy whole directory in
+// StepCopy
+//
+class StepWgtResourceDirectory : public common_installer::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; }
+
+  SCOPE_LOG_TAG(CreateWgtResourceDirectory)
+};
+
+}  // namespace wgt_resources
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_
index d9ee266..4b3dd3d 100644 (file)
@@ -34,6 +34,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_resource_directory.h"
 #include "wgt/wgt_app_query_interface.h"
 
 namespace ci = common_installer;
@@ -56,6 +57,7 @@ int main(int argc, char** argv) {
       installer.AddStep<wgt::parse::StepParse>();
       installer.AddStep<ci::signature::StepCheckSignature>();
       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::symbolic_link::StepCreateSymbolicLink>();
@@ -71,6 +73,7 @@ int main(int argc, char** argv) {
       installer.AddStep<ci::signature::StepCheckSignature>();
       installer.AddStep<wgt::check_settings::StepCheckSettingsLevel>();
       installer.AddStep<ci::old_certificate::StepCheckOldCertificate>();
+      installer.AddStep<wgt::wgt_resources::StepWgtResourceDirectory>();
       installer.AddStep<ci::old_manifest::StepOldManifest>();
       installer.AddStep<ci::backup_manifest::StepBackupManifest>();
       installer.AddStep<ci::backup_icons::StepBackupIcons>();