Change line ending 25/240725/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 11 Aug 2020 02:36:27 +0000 (11:36 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 11 Aug 2020 02:36:27 +0000 (11:36 +0900)
Change line endings of some files from CRLF to LF

Change-Id: Ie185cf28e3075df2165d681e43d6c7ae8fb09f63
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkg_initdb/init_pkg_db.cc
src/pkg_initdb/init_pkg_db.h
src/pkg_initdb/manifest_loader.cc
src/pkg_initdb/manifest_loader.h
src/pkg_initdb/option_checker.cc
src/pkg_initdb/option_checker.h

index 413b04466c4778283cf35203fd645edbff812d39..7023902f409c0e2adc8932d0bdf5d3fd249f1b31 100644 (file)
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#include <boost/filesystem/path.hpp>\r
-#include <boost/filesystem/operations.hpp>\r
-#include <tzplatform_config.h>\r
-\r
-#include <pkgmgr_parser_db.h>\r
-#include <pkgmgr-info.h>\r
-\r
-#include <iostream>\r
-#include <list>\r
-#include <string>\r
-\r
-#include "pkg_initdb/init_pkg_db.h"\r
-#include "pkg_initdb/manifest_loader.h"\r
-#include "pkg_initdb/option_checker.h"\r
-\r
-#include "common/utils/file_util.h"\r
-#include "common/utils/subprocess.h"\r
-\r
-namespace bf = boost::filesystem;\r
-namespace ci = common_installer;\r
-\r
-namespace {\r
-\r
-const uid_t kRootUserUid = 0;\r
-const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);\r
-const char kBackendDirectoryPath[] = "/etc/package-manager/backend/";\r
-\r
-void RemoveDatabase(const std::string& path) {\r
-  ci::Remove(path);\r
-  ci::Remove(path + "-journal");\r
-}\r
-\r
-void RemoveOldDatabases(uid_t uid, bool is_global) {\r
-  char *parser_db = getUserPkgParserDBPathUID(uid);\r
-\r
-  if (parser_db == nullptr) {\r
-    std::cerr << "Failed to get db path, cannot remove old databases";\r
-    return;\r
-  }\r
-\r
-  RemoveDatabase(parser_db);\r
-  free(parser_db);\r
-\r
-  if (!is_global)\r
-    return;\r
-\r
-  char *cert_db = getUserPkgCertDBPath();\r
-  if (!cert_db) {\r
-    std::cerr << "Failed to get cert db path" << std::endl;\r
-    return;\r
-  }\r
-\r
-  RemoveDatabase(cert_db);\r
-  free(cert_db);\r
-}\r
-\r
-}  // namespace\r
-\r
-bool InitPkgDB::Init(int argc, char *argv[]) {\r
-  return option_checker_.Init(argc, argv);\r
-}\r
-\r
-void InitPkgDB::RunBackend(const std::string& pkgid,\r
-    const std::string& type, bool preload) {\r
-  bf::path backend_path(kBackendDirectoryPath);\r
-  backend_path /= type;\r
-  ci::Subprocess backend(backend_path.string());\r
-  auto params = option_checker_.GetParams(preload, pkgid);\r
-  if (preload) {\r
-    if (option_checker_.GetUid() != kRootUserUid) {\r
-      std::cerr << "Preload request for non-root user" << std::endl;\r
-      return;\r
-    }\r
-    params.emplace_back("--preload");\r
-  }\r
-\r
-  backend.RunWithArgs(params);\r
-  backend.Wait();\r
-}\r
-\r
-void InitPkgDB::LoadDirectory(const std::string& path,\r
-    bool preload) {\r
-  ManifestLoader manifest_loader(path);\r
-  std::list<ManifestInfo> manifest_list = manifest_loader.LoadManifest();\r
-\r
-  for (auto &manifest_info : manifest_list) {\r
-    std::cerr << "Manifest : " << std::get<0>(manifest_info) <<\r
-        (option_checker_.IsPartialRW() ? " (rw-only)":" (all)") << std::endl;\r
-    RunBackend(std::get<1>(manifest_info), std::get<2>(manifest_info),\r
-        preload);\r
-  }\r
-}\r
-\r
-bool InitPkgDB::Run() {\r
-  if (!HandleDatabase())\r
-    return false;\r
-\r
-  if (option_checker_.IsGlobal()) {\r
-    if (!option_checker_.IsRWOnly())\r
-      LoadDirectory(tzplatform_getenv(TZ_SYS_RO_PACKAGES), true);\r
-\r
-    if (option_checker_.IsROOnly())\r
-      return true;\r
-\r
-    LoadDirectory(tzplatform_getenv(TZ_SYS_RW_PACKAGES), false);\r
-  } else {\r
-    // Specified user location\r
-    tzplatform_set_user(option_checker_.GetUid());\r
-    std::string user_dir(tzplatform_getenv(TZ_USER_PACKAGES));\r
-    tzplatform_reset_user();\r
-    LoadDirectory(user_dir, false);\r
-  }\r
-\r
-  return true;\r
-}\r
-\r
-bool InitPkgDB::HandleDatabase() {\r
-  if (option_checker_.GetKeepDb())\r
-    return true;\r
-\r
-  uid_t uid = option_checker_.GetUid();\r
-  RemoveOldDatabases(uid, option_checker_.IsGlobal());\r
-  if (pkgmgr_parser_create_and_initialize_db(uid) < 0) {\r
-    std::cerr << "Cannot create db" << std::endl;\r
-    return false;\r
-  }\r
-\r
-  return true;\r
-}\r
+// 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 <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <tzplatform_config.h>
+
+#include <pkgmgr_parser_db.h>
+#include <pkgmgr-info.h>
+
+#include <iostream>
+#include <list>
+#include <string>
+
+#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<ManifestInfo> 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;
+}
index 6f776e906a11acefb493cac38b4294e24747dd05..f41e99bb12c908887ac7558f1799ac83d80a2580 100644 (file)
@@ -1,28 +1,28 @@
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#ifndef PKG_INITDB_INIT_PKG_DB_H_\r
-#define PKG_INITDB_INIT_PKG_DB_H_\r
-\r
-#include <pkg_initdb/option_checker.h>\r
-\r
-#include <list>\r
-#include <string>\r
-\r
-class InitPkgDB {\r
- public:\r
-  bool Init(int argc, char *argv[]);\r
-  bool Run();\r
-\r
- private:\r
-  bool HandleDatabase();\r
-  void LoadDirectory(const std::string& path, bool preload);\r
-  void RunBackend(const std::string& pkgid,\r
-                  const std::string& type,\r
-                  bool preload);\r
-\r
-  OptionChecker option_checker_;\r
-};\r
-\r
-#endif  // PKG_INITDB_INIT_PKG_DB_H_\r
+// 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 <pkg_initdb/option_checker.h>
+
+#include <list>
+#include <string>
+
+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_
index 2c6d7526e8a620f058d14bdea089e5fcbf14def5..96ad6a3262588954d50cdcf2f206771fe450b8e7 100644 (file)
@@ -1,55 +1,55 @@
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#include <boost/filesystem/path.hpp>\r
-#include <boost/filesystem/operations.hpp>\r
-\r
-#include <tzplatform_config.h>\r
-\r
-#include <tpk_manifest_handlers/package_handler.h>\r
-#include <tpk_manifest_handlers/tpk_config_parser.h>\r
-\r
-#include <iostream>\r
-#include <list>\r
-#include <string>\r
-\r
-#include "pkg_initdb/manifest_loader.h"\r
-\r
-namespace bf = boost::filesystem;\r
-\r
-ManifestLoader::ManifestLoader(const std::string& path) {\r
-  path_ = bf::path(path);\r
-}\r
-\r
-std::list<ManifestInfo> ManifestLoader::LoadManifest() {\r
-  std::list<ManifestInfo> list;\r
-  std::cerr << "Loading manifest files from " << path_ << std::endl;\r
-  for (bf::directory_iterator iter(path_); iter != bf::directory_iterator();\r
-       ++iter) {\r
-    if (!bf::is_regular_file(iter->path()))\r
-      continue;\r
-\r
-    tpk::parse::TPKConfigParser parser;\r
-    if (!parser.ParseManifest(iter->path())) {\r
-      std::cerr << "Failed to parse tizen manifest file: "\r
-                << parser.GetErrorMessage() << std::endl;\r
-      continue;\r
-    }\r
-    auto package_info =\r
-        std::static_pointer_cast<const tpk::parse::PackageInfo>(\r
-            parser.GetManifestData(tpk::parse::PackageInfo::key()));\r
-    if (!package_info) {\r
-      std::cerr << "Failed to get package info" << std::endl;\r
-      continue;\r
-    }\r
-    std::string type = package_info->type();\r
-    if (type.empty())\r
-      type = "tpk";\r
-\r
-    list.emplace_back(\r
-        std::make_tuple(iter->path().string(), package_info->package(), type));\r
-  }\r
-\r
-  return list;\r
-}\r
+// 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 <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+
+#include <tzplatform_config.h>
+
+#include <tpk_manifest_handlers/package_handler.h>
+#include <tpk_manifest_handlers/tpk_config_parser.h>
+
+#include <iostream>
+#include <list>
+#include <string>
+
+#include "pkg_initdb/manifest_loader.h"
+
+namespace bf = boost::filesystem;
+
+ManifestLoader::ManifestLoader(const std::string& path) {
+  path_ = bf::path(path);
+}
+
+std::list<ManifestInfo> ManifestLoader::LoadManifest() {
+  std::list<ManifestInfo> 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<const tpk::parse::PackageInfo>(
+            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;
+}
index 26579955e47471e18752cfe46827da4629e8ef23..d2f61358d454cc52c8947f32c2a90ba5ce0a4a19 100644 (file)
@@ -1,25 +1,25 @@
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#ifndef PKG_INITDB_MANIFEST_LOADER_H_\r
-#define PKG_INITDB_MANIFEST_LOADER_H_\r
-\r
-#include <list>\r
-#include <string>\r
-#include <tuple>\r
-\r
-namespace bf = boost::filesystem;\r
-\r
-using ManifestInfo = std::tuple<std::string, std::string, std::string>;\r
-\r
-class ManifestLoader {\r
- public:\r
-  explicit ManifestLoader(const std::string& path);\r
-  std::list<ManifestInfo> LoadManifest();\r
-\r
- private:\r
-  bf::path path_;\r
-};\r
-\r
-#endif  // PKG_INITDB_MANIFEST_LOADER_H_\r
+// 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 <list>
+#include <string>
+#include <tuple>
+
+namespace bf = boost::filesystem;
+
+using ManifestInfo = std::tuple<std::string, std::string, std::string>;
+
+class ManifestLoader {
+ public:
+  explicit ManifestLoader(const std::string& path);
+  std::list<ManifestInfo> LoadManifest();
+
+ private:
+  bf::path path_;
+};
+
+#endif  // PKG_INITDB_MANIFEST_LOADER_H_
index 3bd9e0816852538277cde89466f71be391cbf01d..d94989d34c8faf138e198011936c3a66e05f03f2 100644 (file)
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#include <boost/exception/diagnostic_information.hpp>\r
-#include <boost/filesystem/operations.hpp>\r
-#include <boost/program_options.hpp>\r
-#include <boost/system/error_code.hpp>\r
-\r
-#include <tzplatform_config.h>\r
-\r
-#include <string>\r
-#include <iostream>\r
-#include <vector>\r
-\r
-#include "pkg_initdb/option_checker.h"\r
-\r
-namespace bpo = boost::program_options;\r
-\r
-namespace {\r
-\r
-const uid_t kRootUserUid = 0;\r
-const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);\r
-\r
-bool IsGlobalUser(uid_t uid) {\r
-  return uid == kRootUserUid || uid == kGlobalUserUid;\r
-}\r
-\r
-}  // namespace\r
-\r
-bool OptionChecker::Init(int argc, char* argv[]) {\r
-  try {\r
-    options_.add_options()\r
-        ("uid,u", bpo::value<int>()->default_value(kRootUserUid), "user id")\r
-        ("partial-rw", "rw-partition only")\r
-        ("ro", "readonly packages only")\r
-        ("rw", "rw packages only")\r
-        ("keep-db", "keep current database")\r
-        ("help,h", "display this help message")\r
-        ("recover-db", "register pkg db only");\r
-    bpo::store(bpo::parse_command_line(argc, argv, options_), opt_map_);\r
-    if (opt_map_.count("help")) {\r
-      std::cerr << options_ << std::endl;\r
-      return false;\r
-    }\r
-    if (opt_map_.count("partial-rw"))\r
-      partial_rw_ = true;\r
-    if (opt_map_.count("ro"))\r
-      ro_only_ = true;\r
-    if (opt_map_.count("rw"))\r
-      rw_only_ = true;\r
-    if (opt_map_.count("keep-db"))\r
-      keep_db_ = true;\r
-    if (opt_map_.count("recover-db"))\r
-      recover_db_ = true;\r
-    bpo::notify(opt_map_);\r
-    uid_ = opt_map_["uid"].as<int>();\r
-  } catch (...) {\r
-    std::cerr << "Exception occurred: "\r
-              << boost::current_exception_diagnostic_information()\r
-              << std::endl;\r
-    return false;\r
-  }\r
-  return ValidateOptions();\r
-}\r
-\r
-bool OptionChecker::GetKeepDb() {\r
-  return keep_db_;\r
-}\r
-\r
-uid_t OptionChecker::GetUid() {\r
-  return uid_;\r
-}\r
-\r
-bool OptionChecker::IsGlobal() {\r
-  return IsGlobalUser(uid_);\r
-}\r
-\r
-bool OptionChecker::IsRWOnly() {\r
-  return rw_only_;\r
-}\r
-\r
-bool OptionChecker::IsROOnly() {\r
-  return ro_only_;\r
-}\r
-\r
-bool OptionChecker::IsPartialRW() {\r
-  return partial_rw_;\r
-}\r
-\r
-bool OptionChecker::ValidateOptions() {\r
-  if (ro_only_ && rw_only_) {\r
-    std::cerr << "Conflicting options : 'ro' and 'rw";\r
-    return false;\r
-  } else if (rw_only_ && partial_rw_) {\r
-    std::cerr << "Conflicting options : 'rw' and 'partial-rw";\r
-    return false;\r
-  } else if (!IsGlobalUser(uid_) && (ro_only_ || rw_only_ || partial_rw_)) {\r
-    std::cerr << "Conflicting options : 'rw' or 'partial-rw'"\r
-              << " only affect on global user";\r
-    return false;\r
-  } else if (recover_db_ && partial_rw_) {\r
-    std::cerr << "Conflicting options : 'recover-db' and 'partial-rw'";\r
-    return false;\r
-  }\r
-\r
-  return true;\r
-}\r
-\r
-std::vector<std::string> OptionChecker::GetParams(bool is_preload_pkg,\r
-    const std::string& pkgid) {\r
-  std::vector<std::string> params;\r
-  if (is_preload_pkg)\r
-    params.emplace_back("--preload");\r
-\r
-  if (partial_rw_)\r
-    params.emplace_back("--partial-rw");\r
-\r
-  if (!IsGlobalUser(uid_)) {\r
-    params.emplace_back("--uid");\r
-    params.emplace_back(std::to_string(uid_));\r
-  }\r
-\r
-  if (recover_db_)\r
-    params.emplace_back("--recover-db");\r
-  else\r
-    params.emplace_back("-y");\r
-  params.emplace_back(pkgid);\r
-\r
-  return params;\r
-}\r
+// 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 <boost/exception/diagnostic_information.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/program_options.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <tzplatform_config.h>
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#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<int>()->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<int>();
+  } 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<std::string> OptionChecker::GetParams(bool is_preload_pkg,
+    const std::string& pkgid) {
+  std::vector<std::string> 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;
+}
index 5645742579d5554ef627b2114c36dd82608dabd3..37d64fdf6da7123f063fd3f7f68c8d362a21d18e 100644 (file)
@@ -1,52 +1,52 @@
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved\r
-// Use of this source code is governed by an apache-2.0 license that can be\r
-// found in the LICENSE file.\r
-\r
-#ifndef PKG_INITDB_OPTION_CHECKER_H_\r
-#define PKG_INITDB_OPTION_CHECKER_H_\r
-\r
-#include <boost/exception/diagnostic_information.hpp>\r
-#include <boost/filesystem/operations.hpp>\r
-#include <boost/filesystem/path.hpp>\r
-#include <boost/program_options.hpp>\r
-#include <boost/system/error_code.hpp>\r
-\r
-#include <string>\r
-#include <iostream>\r
-#include <vector>\r
-\r
-namespace bs = boost::system;\r
-namespace bpo = boost::program_options;\r
-\r
-class OptionChecker {\r
- public:\r
-  OptionChecker() :\r
-      options_("Allowed options"), partial_rw_(false),\r
-      ro_only_(false), rw_only_(false), keep_db_(false),\r
-      recover_db_(false), uid_(-1) {}\r
-\r
-  bool Init(int argc, char* argv[]);\r
-\r
-  bool GetKeepDb();\r
-  bool IsGlobal();\r
-  bool IsRWOnly();\r
-  bool IsROOnly();\r
-  bool IsPartialRW();\r
-  uid_t GetUid();\r
-  std::vector<std::string> GetParams(\r
-      bool is_preload, const std::string& pkgid);\r
-\r
- private:\r
-  bool ValidateOptions();\r
-\r
-  bpo::options_description options_;\r
-  bool partial_rw_;\r
-  bool ro_only_;\r
-  bool rw_only_;\r
-  bool keep_db_;\r
-  bool recover_db_;\r
-  bpo::variables_map opt_map_;\r
-  uid_t uid_;\r
-};\r
-\r
-#endif  // PKG_INITDB_OPTION_CHECKER_H_\r
+// 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 <boost/exception/diagnostic_information.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/program_options.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+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<std::string> 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_