remove deprecated and not-supported RW directories 79/80279/9
authorjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 15 Jul 2016 12:44:20 +0000 (21:44 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 22 Jul 2016 08:24:04 +0000 (17:24 +0900)
and, remove pre-packed RW directories.

Change-Id: Id20197c874a7f8b831764cedd65676c1fb317f42
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/common/shared_dirs.cc
src/common/shared_dirs.h
src/common/step/filesystem/step_create_per_user_storage_directories.cc
src/common/step/filesystem/step_create_storage_directories.cc
src/common/step/filesystem/step_create_storage_directories.h

index adee60d..a93202d 100644 (file)
@@ -4,6 +4,9 @@
 
 #include "common/shared_dirs.h"
 
+#include <manifest_parser/utils/logging.h>
+#include <manifest_parser/utils/version_number.h>
+
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 #include <boost/program_options.hpp>
@@ -11,7 +14,6 @@
 
 #include <glib.h>
 #include <gio/gio.h>
-#include <manifest_parser/utils/logging.h>
 #include <vcore/Certificate.h>
 #include <pkgmgr-info.h>
 #include <pwd.h>
@@ -51,15 +53,17 @@ namespace ci = common_installer;
 
 namespace {
 
+const utils::VersionNumber ver30("3.0");
+
 typedef std::vector<std::tuple<uid_t, gid_t, bf::path>> user_list;
 const std::vector<const char*> kEntries = {
   {"/"},
   {"cache/"},
   {"data/"},
   {"shared/"},
-  {"shared/cache/"},
 };
 
+const char kSharedDataDir[] = "shared/data";
 const char kTrustedDir[] = "shared/trusted";
 const char kSkelAppDir[] = "/etc/skel/apps_rw";
 const char kPackagePattern[] = R"(^[0-9a-zA-Z_-]+(\.?[0-9a-zA-Z_-]+)*$)";
@@ -412,9 +416,14 @@ bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid) {
   return true;
 }
 
-bool CreateSkelDirectories(const std::string& pkgid) {
+bool CreateSkelDirectories(const std::string& pkgid,
+                           const std::string& api_version,
+                           bool trusted) {
   bf::path path = bf::path(kSkelAppDir) / pkgid;
   LOG(DEBUG) << "Creating directories in: " << path;
+
+  utils::VersionNumber api_ver(api_version);
+
   bs::error_code error;
   bf::create_directories(path, error);
 
@@ -423,7 +432,13 @@ bool CreateSkelDirectories(const std::string& pkgid) {
     return false;
   }
 
-  for (auto& entry : kEntries) {
+  std::vector<const char*> dirs(kEntries);
+  if (trusted)
+    dirs.push_back(kTrustedDir);
+  if (api_ver < ver30) {
+    dirs.push_back(kSharedDataDir);
+  }
+  for (auto& entry : dirs) {
     bf::path subpath = path / entry;
     bf::create_directories(subpath, error);
     if (error && !bf::exists(subpath)) {
index c992944..7d94de6 100644 (file)
@@ -110,11 +110,15 @@ PkgList CreatePkgInformationList(uid_t uid = getuid(),
  * \brief Create skeleton directories for package
  *
  * \param pkgid package id
+ * \param api_version package api version
+ * \param trusted signed package flag
  *
  * \return bool true if succeed, false otherwise
  *
  */
-bool CreateSkelDirectories(const std::string& pkgid);
+bool CreateSkelDirectories(const std::string& pkgid,
+                           const std::string& api_version,
+                           bool trusted);
 
 /**
  * \brief Performs deletion of directories
index 707aec7..6cd8ccf 100644 (file)
@@ -2,10 +2,11 @@
 // Use of this source code is governed by an apache 2.0 license that can be
 // found in the LICENSE file.
 
+#include "common/step/filesystem/step_create_per_user_storage_directories.h"
+
 #include <string>
 #include <vector>
 
-#include "common/step/filesystem/step_create_per_user_storage_directories.h"
 #include "common/privileges.h"
 
 #include "common/pkgdir_tool_request.h"
@@ -22,7 +23,15 @@ common_installer::Step::Status StepCreatePerUserStorageDirectories::process() {
   std::string package_id = context_->pkgid.get();
   LOG(INFO) << "Creating per-user directories for package: " << package_id;
 
-  if (!common_installer::CreateSkelDirectories(package_id)) {
+  manifest_x* manifest = context_->manifest_data.get();
+  std::string str_ver(manifest->api_version);
+  std::string author_id = context_->certificate_info.get().author_id.get();
+  bool trusted = false;
+  if (!author_id.empty())
+    trusted = true;
+
+  if (!common_installer::CreateSkelDirectories(package_id,
+      str_ver, trusted)) {
     LOG(ERROR) << "Failed to create skel dirs";
     return Status::APP_DIR_ERROR;
   }
index 9734214..eea839f 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "common/step/filesystem/step_create_storage_directories.h"
 
+#include <manifest_parser/utils/version_number.h>
+
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 #include <boost/system/error_code.hpp>
@@ -22,8 +24,10 @@ namespace {
 const char kCache[] = "cache";
 const char kData[] = "data";
 const char kShared[] = "shared";
-const char kSharedData[] = "data";
-const char kSharedTrusted[] = "trusted";
+const char kSharedCache[] = "shared/cache";
+const char kSharedData[] = "shared/data";
+const char kSharedTrusted[] = "shared/trusted";
+const utils::VersionNumber ver30("3.0");
 
 }  // namespace
 
@@ -31,8 +35,11 @@ namespace common_installer {
 namespace filesystem {
 
 common_installer::Step::Status StepCreateStorageDirectories::process() {
-  if (context_->request_mode.get() == RequestMode::GLOBAL)
+  if (context_->request_mode.get() == RequestMode::GLOBAL) {
+    // remove packaged RW diriectories
+    RemoveAll();
     return Status::OK;
+  }
   if (!ShareDir())
     return Status::APP_DIR_ERROR;
   if (!PrivateDir())
@@ -59,25 +66,43 @@ bool StepCreateStorageDirectories::ShareDir() {
 
 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::path shared_trusted_path = context_->pkg_path.get() / kSharedTrusted;
   bf::create_directory(shared_trusted_path, error_code);
   if (error_code) {
     LOG(ERROR) << "Failed to create shared/trusted directory for package";
     return false;
   }
 
-  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";
+  manifest_x* manifest = context_->manifest_data.get();
+  if (!manifest) {
+    LOG(ERROR) << "Failed to get manifest info";
     return false;
   }
+  std::string str_ver(manifest->api_version);
+  utils::VersionNumber api_version(str_ver);
+
+  bf::path shared_data_path = context_->pkg_path.get() / kSharedData;
+  bf::path shared_cache_path = context_->pkg_path.get() / kSharedCache;
+
+  if (api_version >= ver30) {
+    // remove shared/data (deprecated)
+    bf::remove_all(shared_data_path, error_code);
+    if (error_code) {
+      LOG(ERROR) << "Can't remove dir:" << shared_data_path;
+      return false;
+    }
+  } else {
+    bf::create_directory(shared_data_path, error_code);
+    if (error_code) {
+      LOG(ERROR) << "Failed to create shared/data directory for package";
+      return false;
+    }
+  }
 
-  bf::path shared_cache_path = shared_path / kCache;
-  bf::create_directory(shared_cache_path, error_code);
+  // remove shared/cache (do not support)
+  bf::remove_all(shared_cache_path, error_code);
   if (error_code) {
-    LOG(ERROR) << "Failed to create shared/cache directory for package";
+    LOG(ERROR) << "Can't remove dir:" << shared_cache_path;
     return false;
   }
 
@@ -113,5 +138,20 @@ bool StepCreateStorageDirectories::CacheDir() {
   return true;
 }
 
+void StepCreateStorageDirectories::RemoveAll() {
+  bs::error_code error_code;
+  bf::path data_path = context_->pkg_path.get() / kData;
+  bf::path cache_path = context_->pkg_path.get() / kCache;
+  bf::path shared_data_path = context_->pkg_path.get() / kSharedData;
+  bf::path shared_cache_path = context_->pkg_path.get() / kSharedCache;
+  bf::path shared_trusted_path = context_->pkg_path.get() / kSharedTrusted;
+
+  bf::remove_all(data_path, error_code);
+  bf::remove_all(cache_path, error_code);
+  bf::remove_all(shared_data_path, error_code);
+  bf::remove_all(shared_cache_path, error_code);
+  bf::remove_all(shared_trusted_path, error_code);
+}
+
 }  // namespace filesystem
 }  // namespace common_installer
index 0a523eb..915e349 100644 (file)
@@ -39,6 +39,7 @@ class StepCreateStorageDirectories : public common_installer::Step {
   bool SubShareDir();
   bool PrivateDir();
   bool CacheDir();
+  void RemoveAll();
 
   STEP_NAME(CreateStorageDirectories)
 };