bpo::options_description options("Allowed options");
bpo::variables_map opt_map;
uid_t uid;
+ bool partial_rw = false;
+ bool ro_only = false;
bool rw_only = false;
- bool initial = false;
+ bool keep_db = false;
try {
options.add_options()
("uid,u", bpo::value<int>()->default_value(kRootUserUid), "user id")
("partial-rw", "rw-partition only")
- ("ro", "readonly package only")
+ ("ro", "readonly packages only")
+ ("rw", "rw packages only")
+ ("keep-db", "keep current database")
("help,h", "display this help message");
bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
if (opt_map.count("help")) {
std::cerr << options << std::endl;
return -1;
}
+
if (opt_map.count("partial-rw"))
- rw_only = true;
+ partial_rw = true;
if (opt_map.count("ro"))
- initial = true;
+ ro_only = true;
+ if (opt_map.count("rw"))
+ rw_only = true;
+ if (opt_map.count("keep-db"))
+ keep_db = true;
bpo::notify(opt_map);
uid = opt_map["uid"].as<int>();
} catch (...) {
std::cerr << "Exception occurred: "
- << boost::current_exception_diagnostic_information() << std::endl;
+ << boost::current_exception_diagnostic_information()
+ << std::endl;
return -1;
}
- RemoveOldDatabases(uid);
-
- int ret = pkgmgr_parser_create_and_initialize_db(uid);
- if (ret < 0) {
- std::cerr << "Cannot create db" << std::endl;
+ if (ro_only && rw_only) {
+ std::cerr << "Conflicting options : 'ro' and 'rw";
+ return -1;
+ } else if (rw_only && partial_rw) {
+ std::cerr << "Conflicting options : 'rw' and 'partial-rw";
+ return -1;
+ } else if (!IsGlobal(uid) && (ro_only || rw_only || partial_rw)) {
+ std::cerr << "Conflicting options : 'rw' or 'partial-rw'"
+ << " only affect on global user";
return -1;
}
+ if (!keep_db) {
+ RemoveOldDatabases(uid);
+
+ int ret = pkgmgr_parser_create_and_initialize_db(uid);
+ if (ret < 0) {
+ std::cerr << "Cannot create db" << std::endl;
+ return -1;
+ }
+ }
+
if (IsGlobal(uid)) {
// RO location
- bf::path ro_dir(tzplatform_getenv(TZ_SYS_RO_PACKAGES));
- InitdbLoadDirectory(uid, ro_dir, true, rw_only);
+ if (!rw_only) {
+ bf::path ro_dir(tzplatform_getenv(TZ_SYS_RO_PACKAGES));
+ InitdbLoadDirectory(uid, ro_dir, true, partial_rw);
+ }
- if (initial)
- return ret;
+ if (ro_only)
+ return 0;
// RW location
bf::path rw_dir(tzplatform_getenv(TZ_SYS_RW_PACKAGES));
tzplatform_reset_user();
}
- return ret;
+ return 0;
}