From: jongmyeongko Date: Fri, 15 Jul 2016 12:44:20 +0000 (+0900) Subject: remove deprecated and not-supported RW directories X-Git-Tag: accepted/tizen/common/20160722.135218~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32bfbba9ddb60ec8338aa4efcd0fad42b7ba3954;p=platform%2Fcore%2Fappfw%2Fapp-installers.git remove deprecated and not-supported RW directories and, remove pre-packed RW directories. Change-Id: Id20197c874a7f8b831764cedd65676c1fb317f42 Signed-off-by: jongmyeongko --- diff --git a/src/common/shared_dirs.cc b/src/common/shared_dirs.cc index adee60d..a93202d 100644 --- a/src/common/shared_dirs.cc +++ b/src/common/shared_dirs.cc @@ -4,6 +4,9 @@ #include "common/shared_dirs.h" +#include +#include + #include #include #include @@ -11,7 +14,6 @@ #include #include -#include #include #include #include @@ -51,15 +53,17 @@ namespace ci = common_installer; namespace { +const utils::VersionNumber ver30("3.0"); + typedef std::vector> user_list; const std::vector 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 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)) { diff --git a/src/common/shared_dirs.h b/src/common/shared_dirs.h index c992944..7d94de6 100644 --- a/src/common/shared_dirs.h +++ b/src/common/shared_dirs.h @@ -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 diff --git a/src/common/step/filesystem/step_create_per_user_storage_directories.cc b/src/common/step/filesystem/step_create_per_user_storage_directories.cc index 707aec7..6cd8ccf 100644 --- a/src/common/step/filesystem/step_create_per_user_storage_directories.cc +++ b/src/common/step/filesystem/step_create_per_user_storage_directories.cc @@ -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 #include -#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; } diff --git a/src/common/step/filesystem/step_create_storage_directories.cc b/src/common/step/filesystem/step_create_storage_directories.cc index 9734214..eea839f 100644 --- a/src/common/step/filesystem/step_create_storage_directories.cc +++ b/src/common/step/filesystem/step_create_storage_directories.cc @@ -4,6 +4,8 @@ #include "common/step/filesystem/step_create_storage_directories.h" +#include + #include #include #include @@ -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 diff --git a/src/common/step/filesystem/step_create_storage_directories.h b/src/common/step/filesystem/step_create_storage_directories.h index 0a523eb..915e349 100644 --- a/src/common/step/filesystem/step_create_storage_directories.h +++ b/src/common/step/filesystem/step_create_storage_directories.h @@ -39,6 +39,7 @@ class StepCreateStorageDirectories : public common_installer::Step { bool SubShareDir(); bool PrivateDir(); bool CacheDir(); + void RemoveAll(); STEP_NAME(CreateStorageDirectories) };