From: Junghyun Yeon Date: Tue, 11 Aug 2020 02:36:27 +0000 (+0900) Subject: Change line ending X-Git-Tag: submit/tizen/20200813.053606~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5656baf6fc5ac22a8366f160e6f81900974310c0;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Change line ending Change line endings of some files from CRLF to LF Change-Id: Ie185cf28e3075df2165d681e43d6c7ae8fb09f63 Signed-off-by: Junghyun Yeon --- diff --git a/src/pkg_initdb/init_pkg_db.cc b/src/pkg_initdb/init_pkg_db.cc index 413b0446..7023902f 100644 --- a/src/pkg_initdb/init_pkg_db.cc +++ b/src/pkg_initdb/init_pkg_db.cc @@ -1,133 +1,133 @@ -// Copyright (c) 2020 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 -#include -#include - -#include -#include - -#include -#include -#include - -#include "pkg_initdb/init_pkg_db.h" -#include "pkg_initdb/manifest_loader.h" -#include "pkg_initdb/option_checker.h" - -#include "common/utils/file_util.h" -#include "common/utils/subprocess.h" - -namespace bf = boost::filesystem; -namespace ci = common_installer; - -namespace { - -const uid_t kRootUserUid = 0; -const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); -const char kBackendDirectoryPath[] = "/etc/package-manager/backend/"; - -void RemoveDatabase(const std::string& path) { - ci::Remove(path); - ci::Remove(path + "-journal"); -} - -void RemoveOldDatabases(uid_t uid, bool is_global) { - char *parser_db = getUserPkgParserDBPathUID(uid); - - if (parser_db == nullptr) { - std::cerr << "Failed to get db path, cannot remove old databases"; - return; - } - - RemoveDatabase(parser_db); - free(parser_db); - - if (!is_global) - return; - - char *cert_db = getUserPkgCertDBPath(); - if (!cert_db) { - std::cerr << "Failed to get cert db path" << std::endl; - return; - } - - RemoveDatabase(cert_db); - free(cert_db); -} - -} // namespace - -bool InitPkgDB::Init(int argc, char *argv[]) { - return option_checker_.Init(argc, argv); -} - -void InitPkgDB::RunBackend(const std::string& pkgid, - const std::string& type, bool preload) { - bf::path backend_path(kBackendDirectoryPath); - backend_path /= type; - ci::Subprocess backend(backend_path.string()); - auto params = option_checker_.GetParams(preload, pkgid); - if (preload) { - if (option_checker_.GetUid() != kRootUserUid) { - std::cerr << "Preload request for non-root user" << std::endl; - return; - } - params.emplace_back("--preload"); - } - - backend.RunWithArgs(params); - backend.Wait(); -} - -void InitPkgDB::LoadDirectory(const std::string& path, - bool preload) { - ManifestLoader manifest_loader(path); - std::list manifest_list = manifest_loader.LoadManifest(); - - for (auto &manifest_info : manifest_list) { - std::cerr << "Manifest : " << std::get<0>(manifest_info) << - (option_checker_.IsPartialRW() ? " (rw-only)":" (all)") << std::endl; - RunBackend(std::get<1>(manifest_info), std::get<2>(manifest_info), - preload); - } -} - -bool InitPkgDB::Run() { - if (!HandleDatabase()) - return false; - - if (option_checker_.IsGlobal()) { - if (!option_checker_.IsRWOnly()) - LoadDirectory(tzplatform_getenv(TZ_SYS_RO_PACKAGES), true); - - if (option_checker_.IsROOnly()) - return true; - - LoadDirectory(tzplatform_getenv(TZ_SYS_RW_PACKAGES), false); - } else { - // Specified user location - tzplatform_set_user(option_checker_.GetUid()); - std::string user_dir(tzplatform_getenv(TZ_USER_PACKAGES)); - tzplatform_reset_user(); - LoadDirectory(user_dir, false); - } - - return true; -} - -bool InitPkgDB::HandleDatabase() { - if (option_checker_.GetKeepDb()) - return true; - - uid_t uid = option_checker_.GetUid(); - RemoveOldDatabases(uid, option_checker_.IsGlobal()); - if (pkgmgr_parser_create_and_initialize_db(uid) < 0) { - std::cerr << "Cannot create db" << std::endl; - return false; - } - - return true; -} +// Copyright (c) 2020 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 +#include +#include + +#include +#include + +#include +#include +#include + +#include "pkg_initdb/init_pkg_db.h" +#include "pkg_initdb/manifest_loader.h" +#include "pkg_initdb/option_checker.h" + +#include "common/utils/file_util.h" +#include "common/utils/subprocess.h" + +namespace bf = boost::filesystem; +namespace ci = common_installer; + +namespace { + +const uid_t kRootUserUid = 0; +const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); +const char kBackendDirectoryPath[] = "/etc/package-manager/backend/"; + +void RemoveDatabase(const std::string& path) { + ci::Remove(path); + ci::Remove(path + "-journal"); +} + +void RemoveOldDatabases(uid_t uid, bool is_global) { + char *parser_db = getUserPkgParserDBPathUID(uid); + + if (parser_db == nullptr) { + std::cerr << "Failed to get db path, cannot remove old databases"; + return; + } + + RemoveDatabase(parser_db); + free(parser_db); + + if (!is_global) + return; + + char *cert_db = getUserPkgCertDBPath(); + if (!cert_db) { + std::cerr << "Failed to get cert db path" << std::endl; + return; + } + + RemoveDatabase(cert_db); + free(cert_db); +} + +} // namespace + +bool InitPkgDB::Init(int argc, char *argv[]) { + return option_checker_.Init(argc, argv); +} + +void InitPkgDB::RunBackend(const std::string& pkgid, + const std::string& type, bool preload) { + bf::path backend_path(kBackendDirectoryPath); + backend_path /= type; + ci::Subprocess backend(backend_path.string()); + auto params = option_checker_.GetParams(preload, pkgid); + if (preload) { + if (option_checker_.GetUid() != kRootUserUid) { + std::cerr << "Preload request for non-root user" << std::endl; + return; + } + params.emplace_back("--preload"); + } + + backend.RunWithArgs(params); + backend.Wait(); +} + +void InitPkgDB::LoadDirectory(const std::string& path, + bool preload) { + ManifestLoader manifest_loader(path); + std::list manifest_list = manifest_loader.LoadManifest(); + + for (auto &manifest_info : manifest_list) { + std::cerr << "Manifest : " << std::get<0>(manifest_info) << + (option_checker_.IsPartialRW() ? " (rw-only)":" (all)") << std::endl; + RunBackend(std::get<1>(manifest_info), std::get<2>(manifest_info), + preload); + } +} + +bool InitPkgDB::Run() { + if (!HandleDatabase()) + return false; + + if (option_checker_.IsGlobal()) { + if (!option_checker_.IsRWOnly()) + LoadDirectory(tzplatform_getenv(TZ_SYS_RO_PACKAGES), true); + + if (option_checker_.IsROOnly()) + return true; + + LoadDirectory(tzplatform_getenv(TZ_SYS_RW_PACKAGES), false); + } else { + // Specified user location + tzplatform_set_user(option_checker_.GetUid()); + std::string user_dir(tzplatform_getenv(TZ_USER_PACKAGES)); + tzplatform_reset_user(); + LoadDirectory(user_dir, false); + } + + return true; +} + +bool InitPkgDB::HandleDatabase() { + if (option_checker_.GetKeepDb()) + return true; + + uid_t uid = option_checker_.GetUid(); + RemoveOldDatabases(uid, option_checker_.IsGlobal()); + if (pkgmgr_parser_create_and_initialize_db(uid) < 0) { + std::cerr << "Cannot create db" << std::endl; + return false; + } + + return true; +} diff --git a/src/pkg_initdb/init_pkg_db.h b/src/pkg_initdb/init_pkg_db.h index 6f776e90..f41e99bb 100644 --- a/src/pkg_initdb/init_pkg_db.h +++ b/src/pkg_initdb/init_pkg_db.h @@ -1,28 +1,28 @@ -// Copyright (c) 2020 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 PKG_INITDB_INIT_PKG_DB_H_ -#define PKG_INITDB_INIT_PKG_DB_H_ - -#include - -#include -#include - -class InitPkgDB { - public: - bool Init(int argc, char *argv[]); - bool Run(); - - private: - bool HandleDatabase(); - void LoadDirectory(const std::string& path, bool preload); - void RunBackend(const std::string& pkgid, - const std::string& type, - bool preload); - - OptionChecker option_checker_; -}; - -#endif // PKG_INITDB_INIT_PKG_DB_H_ +// Copyright (c) 2020 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 PKG_INITDB_INIT_PKG_DB_H_ +#define PKG_INITDB_INIT_PKG_DB_H_ + +#include + +#include +#include + +class InitPkgDB { + public: + bool Init(int argc, char *argv[]); + bool Run(); + + private: + bool HandleDatabase(); + void LoadDirectory(const std::string& path, bool preload); + void RunBackend(const std::string& pkgid, + const std::string& type, + bool preload); + + OptionChecker option_checker_; +}; + +#endif // PKG_INITDB_INIT_PKG_DB_H_ diff --git a/src/pkg_initdb/manifest_loader.cc b/src/pkg_initdb/manifest_loader.cc index 2c6d7526..96ad6a32 100644 --- a/src/pkg_initdb/manifest_loader.cc +++ b/src/pkg_initdb/manifest_loader.cc @@ -1,55 +1,55 @@ -// Copyright (c) 2020 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 -#include - -#include - -#include -#include - -#include -#include -#include - -#include "pkg_initdb/manifest_loader.h" - -namespace bf = boost::filesystem; - -ManifestLoader::ManifestLoader(const std::string& path) { - path_ = bf::path(path); -} - -std::list ManifestLoader::LoadManifest() { - std::list list; - std::cerr << "Loading manifest files from " << path_ << std::endl; - for (bf::directory_iterator iter(path_); iter != bf::directory_iterator(); - ++iter) { - if (!bf::is_regular_file(iter->path())) - continue; - - tpk::parse::TPKConfigParser parser; - if (!parser.ParseManifest(iter->path())) { - std::cerr << "Failed to parse tizen manifest file: " - << parser.GetErrorMessage() << std::endl; - continue; - } - auto package_info = - std::static_pointer_cast( - parser.GetManifestData(tpk::parse::PackageInfo::key())); - if (!package_info) { - std::cerr << "Failed to get package info" << std::endl; - continue; - } - std::string type = package_info->type(); - if (type.empty()) - type = "tpk"; - - list.emplace_back( - std::make_tuple(iter->path().string(), package_info->package(), type)); - } - - return list; -} +// Copyright (c) 2020 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 +#include + +#include + +#include +#include + +#include +#include +#include + +#include "pkg_initdb/manifest_loader.h" + +namespace bf = boost::filesystem; + +ManifestLoader::ManifestLoader(const std::string& path) { + path_ = bf::path(path); +} + +std::list ManifestLoader::LoadManifest() { + std::list list; + std::cerr << "Loading manifest files from " << path_ << std::endl; + for (bf::directory_iterator iter(path_); iter != bf::directory_iterator(); + ++iter) { + if (!bf::is_regular_file(iter->path())) + continue; + + tpk::parse::TPKConfigParser parser; + if (!parser.ParseManifest(iter->path())) { + std::cerr << "Failed to parse tizen manifest file: " + << parser.GetErrorMessage() << std::endl; + continue; + } + auto package_info = + std::static_pointer_cast( + parser.GetManifestData(tpk::parse::PackageInfo::key())); + if (!package_info) { + std::cerr << "Failed to get package info" << std::endl; + continue; + } + std::string type = package_info->type(); + if (type.empty()) + type = "tpk"; + + list.emplace_back( + std::make_tuple(iter->path().string(), package_info->package(), type)); + } + + return list; +} diff --git a/src/pkg_initdb/manifest_loader.h b/src/pkg_initdb/manifest_loader.h index 26579955..d2f61358 100644 --- a/src/pkg_initdb/manifest_loader.h +++ b/src/pkg_initdb/manifest_loader.h @@ -1,25 +1,25 @@ -// Copyright (c) 2020 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 PKG_INITDB_MANIFEST_LOADER_H_ -#define PKG_INITDB_MANIFEST_LOADER_H_ - -#include -#include -#include - -namespace bf = boost::filesystem; - -using ManifestInfo = std::tuple; - -class ManifestLoader { - public: - explicit ManifestLoader(const std::string& path); - std::list LoadManifest(); - - private: - bf::path path_; -}; - -#endif // PKG_INITDB_MANIFEST_LOADER_H_ +// Copyright (c) 2020 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 PKG_INITDB_MANIFEST_LOADER_H_ +#define PKG_INITDB_MANIFEST_LOADER_H_ + +#include +#include +#include + +namespace bf = boost::filesystem; + +using ManifestInfo = std::tuple; + +class ManifestLoader { + public: + explicit ManifestLoader(const std::string& path); + std::list LoadManifest(); + + private: + bf::path path_; +}; + +#endif // PKG_INITDB_MANIFEST_LOADER_H_ diff --git a/src/pkg_initdb/option_checker.cc b/src/pkg_initdb/option_checker.cc index 3bd9e081..d94989d3 100644 --- a/src/pkg_initdb/option_checker.cc +++ b/src/pkg_initdb/option_checker.cc @@ -1,131 +1,131 @@ -// Copyright (c) 2020 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 -#include -#include -#include - -#include - -#include -#include -#include - -#include "pkg_initdb/option_checker.h" - -namespace bpo = boost::program_options; - -namespace { - -const uid_t kRootUserUid = 0; -const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); - -bool IsGlobalUser(uid_t uid) { - return uid == kRootUserUid || uid == kGlobalUserUid; -} - -} // namespace - -bool OptionChecker::Init(int argc, char* argv[]) { - try { - options_.add_options() - ("uid,u", bpo::value()->default_value(kRootUserUid), "user id") - ("partial-rw", "rw-partition only") - ("ro", "readonly packages only") - ("rw", "rw packages only") - ("keep-db", "keep current database") - ("help,h", "display this help message") - ("recover-db", "register pkg db only"); - bpo::store(bpo::parse_command_line(argc, argv, options_), opt_map_); - if (opt_map_.count("help")) { - std::cerr << options_ << std::endl; - return false; - } - if (opt_map_.count("partial-rw")) - partial_rw_ = true; - if (opt_map_.count("ro")) - ro_only_ = true; - if (opt_map_.count("rw")) - rw_only_ = true; - if (opt_map_.count("keep-db")) - keep_db_ = true; - if (opt_map_.count("recover-db")) - recover_db_ = true; - bpo::notify(opt_map_); - uid_ = opt_map_["uid"].as(); - } catch (...) { - std::cerr << "Exception occurred: " - << boost::current_exception_diagnostic_information() - << std::endl; - return false; - } - return ValidateOptions(); -} - -bool OptionChecker::GetKeepDb() { - return keep_db_; -} - -uid_t OptionChecker::GetUid() { - return uid_; -} - -bool OptionChecker::IsGlobal() { - return IsGlobalUser(uid_); -} - -bool OptionChecker::IsRWOnly() { - return rw_only_; -} - -bool OptionChecker::IsROOnly() { - return ro_only_; -} - -bool OptionChecker::IsPartialRW() { - return partial_rw_; -} - -bool OptionChecker::ValidateOptions() { - if (ro_only_ && rw_only_) { - std::cerr << "Conflicting options : 'ro' and 'rw"; - return false; - } else if (rw_only_ && partial_rw_) { - std::cerr << "Conflicting options : 'rw' and 'partial-rw"; - return false; - } else if (!IsGlobalUser(uid_) && (ro_only_ || rw_only_ || partial_rw_)) { - std::cerr << "Conflicting options : 'rw' or 'partial-rw'" - << " only affect on global user"; - return false; - } else if (recover_db_ && partial_rw_) { - std::cerr << "Conflicting options : 'recover-db' and 'partial-rw'"; - return false; - } - - return true; -} - -std::vector OptionChecker::GetParams(bool is_preload_pkg, - const std::string& pkgid) { - std::vector params; - if (is_preload_pkg) - params.emplace_back("--preload"); - - if (partial_rw_) - params.emplace_back("--partial-rw"); - - if (!IsGlobalUser(uid_)) { - params.emplace_back("--uid"); - params.emplace_back(std::to_string(uid_)); - } - - if (recover_db_) - params.emplace_back("--recover-db"); - else - params.emplace_back("-y"); - params.emplace_back(pkgid); - - return params; -} +// Copyright (c) 2020 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 +#include +#include +#include + +#include + +#include +#include +#include + +#include "pkg_initdb/option_checker.h" + +namespace bpo = boost::program_options; + +namespace { + +const uid_t kRootUserUid = 0; +const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); + +bool IsGlobalUser(uid_t uid) { + return uid == kRootUserUid || uid == kGlobalUserUid; +} + +} // namespace + +bool OptionChecker::Init(int argc, char* argv[]) { + try { + options_.add_options() + ("uid,u", bpo::value()->default_value(kRootUserUid), "user id") + ("partial-rw", "rw-partition only") + ("ro", "readonly packages only") + ("rw", "rw packages only") + ("keep-db", "keep current database") + ("help,h", "display this help message") + ("recover-db", "register pkg db only"); + bpo::store(bpo::parse_command_line(argc, argv, options_), opt_map_); + if (opt_map_.count("help")) { + std::cerr << options_ << std::endl; + return false; + } + if (opt_map_.count("partial-rw")) + partial_rw_ = true; + if (opt_map_.count("ro")) + ro_only_ = true; + if (opt_map_.count("rw")) + rw_only_ = true; + if (opt_map_.count("keep-db")) + keep_db_ = true; + if (opt_map_.count("recover-db")) + recover_db_ = true; + bpo::notify(opt_map_); + uid_ = opt_map_["uid"].as(); + } catch (...) { + std::cerr << "Exception occurred: " + << boost::current_exception_diagnostic_information() + << std::endl; + return false; + } + return ValidateOptions(); +} + +bool OptionChecker::GetKeepDb() { + return keep_db_; +} + +uid_t OptionChecker::GetUid() { + return uid_; +} + +bool OptionChecker::IsGlobal() { + return IsGlobalUser(uid_); +} + +bool OptionChecker::IsRWOnly() { + return rw_only_; +} + +bool OptionChecker::IsROOnly() { + return ro_only_; +} + +bool OptionChecker::IsPartialRW() { + return partial_rw_; +} + +bool OptionChecker::ValidateOptions() { + if (ro_only_ && rw_only_) { + std::cerr << "Conflicting options : 'ro' and 'rw"; + return false; + } else if (rw_only_ && partial_rw_) { + std::cerr << "Conflicting options : 'rw' and 'partial-rw"; + return false; + } else if (!IsGlobalUser(uid_) && (ro_only_ || rw_only_ || partial_rw_)) { + std::cerr << "Conflicting options : 'rw' or 'partial-rw'" + << " only affect on global user"; + return false; + } else if (recover_db_ && partial_rw_) { + std::cerr << "Conflicting options : 'recover-db' and 'partial-rw'"; + return false; + } + + return true; +} + +std::vector OptionChecker::GetParams(bool is_preload_pkg, + const std::string& pkgid) { + std::vector params; + if (is_preload_pkg) + params.emplace_back("--preload"); + + if (partial_rw_) + params.emplace_back("--partial-rw"); + + if (!IsGlobalUser(uid_)) { + params.emplace_back("--uid"); + params.emplace_back(std::to_string(uid_)); + } + + if (recover_db_) + params.emplace_back("--recover-db"); + else + params.emplace_back("-y"); + params.emplace_back(pkgid); + + return params; +} diff --git a/src/pkg_initdb/option_checker.h b/src/pkg_initdb/option_checker.h index 56457425..37d64fdf 100644 --- a/src/pkg_initdb/option_checker.h +++ b/src/pkg_initdb/option_checker.h @@ -1,52 +1,52 @@ -// Copyright (c) 2020 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 PKG_INITDB_OPTION_CHECKER_H_ -#define PKG_INITDB_OPTION_CHECKER_H_ - -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace bs = boost::system; -namespace bpo = boost::program_options; - -class OptionChecker { - public: - OptionChecker() : - options_("Allowed options"), partial_rw_(false), - ro_only_(false), rw_only_(false), keep_db_(false), - recover_db_(false), uid_(-1) {} - - bool Init(int argc, char* argv[]); - - bool GetKeepDb(); - bool IsGlobal(); - bool IsRWOnly(); - bool IsROOnly(); - bool IsPartialRW(); - uid_t GetUid(); - std::vector GetParams( - bool is_preload, const std::string& pkgid); - - private: - bool ValidateOptions(); - - bpo::options_description options_; - bool partial_rw_; - bool ro_only_; - bool rw_only_; - bool keep_db_; - bool recover_db_; - bpo::variables_map opt_map_; - uid_t uid_; -}; - -#endif // PKG_INITDB_OPTION_CHECKER_H_ +// Copyright (c) 2020 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 PKG_INITDB_OPTION_CHECKER_H_ +#define PKG_INITDB_OPTION_CHECKER_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace bs = boost::system; +namespace bpo = boost::program_options; + +class OptionChecker { + public: + OptionChecker() : + options_("Allowed options"), partial_rw_(false), + ro_only_(false), rw_only_(false), keep_db_(false), + recover_db_(false), uid_(-1) {} + + bool Init(int argc, char* argv[]); + + bool GetKeepDb(); + bool IsGlobal(); + bool IsRWOnly(); + bool IsROOnly(); + bool IsPartialRW(); + uid_t GetUid(); + std::vector GetParams( + bool is_preload, const std::string& pkgid); + + private: + bool ValidateOptions(); + + bpo::options_description options_; + bool partial_rw_; + bool ro_only_; + bool rw_only_; + bool keep_db_; + bool recover_db_; + bpo::variables_map opt_map_; + uid_t uid_; +}; + +#endif // PKG_INITDB_OPTION_CHECKER_H_