Browse Source

Option to import the initial catalog content at any time

default_compile_flags
vector-of-bool 4 years ago
parent
commit
2df0b27af6
3 changed files with 11 additions and 0 deletions
  1. +4
    -0
      src/dds.main.cpp
  2. +6
    -0
      src/dds/catalog/catalog.cpp
  3. +1
    -0
      src/dds/catalog/catalog.hpp

+ 4
- 0
src/dds.main.cpp View File

@@ -170,6 +170,7 @@ struct cli_catalog {
catalog_path_flag cat_path{cmd};

args::Flag import_stdin{cmd, "stdin", "Import JSON from stdin", {"stdin"}};
args::Flag init{cmd, "initial", "Re-import the initial catalog contents", {"initial"}};
args::ValueFlagList<std::string>
json_paths{cmd,
"json",
@@ -178,6 +179,9 @@ struct cli_catalog {

int run() {
auto cat = cat_path.open();
if (init.Get()) {
cat.import_initial();
}
for (const auto& json_fpath : json_paths.Get()) {
cat.import_json_file(json_fpath);
}

+ 6
- 0
src/dds/catalog/catalog.cpp View File

@@ -409,3 +409,9 @@ void catalog::import_json_str(std::string_view content) {
store(pkg);
}
}

void catalog::import_initial() {
sqlite3::transaction_guard tr{_db};
spdlog::info("Restoring built-in initial catalog contents");
store_init_packages(_db, _stmt_cache);
}

+ 1
- 0
src/dds/catalog/catalog.hpp View File

@@ -39,6 +39,7 @@ public:
std::vector<package_id> by_name(std::string_view sv) const noexcept;
std::vector<dependency> dependencies_of(const package_id& pkg) const noexcept;

void import_initial();
void import_json_str(std::string_view json_str);
void import_json_file(path_ref json_path) {
auto content = dds::slurp_file(json_path);

Loading…
Cancel
Save