| #include <dds/build/builder.hpp> | #include <dds/build/builder.hpp> | ||||
| #include <dds/error/errors.hpp> | #include <dds/error/errors.hpp> | ||||
| #include <dds/pkg/db.hpp> | #include <dds/pkg/db.hpp> | ||||
| #include <dds/remote/remote.hpp> | |||||
| #include <dds/pkg/remote.hpp> | |||||
| #include <dds/toolchain/from_json.hpp> | #include <dds/toolchain/from_json.hpp> | ||||
| using namespace dds; | using namespace dds; | ||||
| if (!opts.build.add_repos.empty()) { | if (!opts.build.add_repos.empty()) { | ||||
| auto cat = opts.open_catalog(); | auto cat = opts.open_catalog(); | ||||
| for (auto& str : opts.build.add_repos) { | for (auto& str : opts.build.add_repos) { | ||||
| auto repo = remote_repository::connect(str); | |||||
| auto repo = pkg_remote::connect(str); | |||||
| repo.store(cat.database()); | repo.store(cat.database()); | ||||
| } | } | ||||
| } | } |
| #include "./pkg_repo_err_handle.hpp" | #include "./pkg_repo_err_handle.hpp" | ||||
| #include <dds/pkg/db.hpp> | #include <dds/pkg/db.hpp> | ||||
| #include <dds/remote/remote.hpp> | |||||
| #include <dds/pkg/remote.hpp> | |||||
| namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
| static int _pkg_repo_add(const options& opts) { | static int _pkg_repo_add(const options& opts) { | ||||
| auto cat = opts.open_catalog(); | auto cat = opts.open_catalog(); | ||||
| auto repo = remote_repository::connect(opts.pkg.repo.add.url); | |||||
| auto repo = pkg_remote::connect(opts.pkg.repo.add.url); | |||||
| repo.store(cat.database()); | repo.store(cat.database()); | ||||
| if (opts.pkg.repo.add.update) { | if (opts.pkg.repo.add.update) { | ||||
| repo.update_catalog(cat.database()); | |||||
| repo.update_pkg_db(cat.database()); | |||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } |
| #include "./pkg_repo_err_handle.hpp" | #include "./pkg_repo_err_handle.hpp" | ||||
| #include <dds/pkg/db.hpp> | #include <dds/pkg/db.hpp> | ||||
| #include <dds/remote/remote.hpp> | |||||
| #include <dds/pkg/remote.hpp> | |||||
| namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
| #include "./error_handler.hpp" | #include "./error_handler.hpp" | ||||
| #include "./options.hpp" | #include "./options.hpp" | ||||
| #include <dds/pkg/db.hpp> | |||||
| #include <dds/remote/remote.hpp> | |||||
| #include <dds/util/paths.hpp> | #include <dds/util/paths.hpp> | ||||
| #include <dds/util/result.hpp> | #include <dds/util/result.hpp> | ||||
| #include <neo/sqlite3/exec.hpp> | #include <neo/sqlite3/exec.hpp> | ||||
| #include <neo/sqlite3/iter_tuples.hpp> | #include <neo/sqlite3/iter_tuples.hpp> | ||||
| #include <neo/sqlite3/single.hpp> | #include <neo/sqlite3/single.hpp> | ||||
| #include <neo/sqlite3/transaction.hpp> | |||||
| #include <nlohmann/json.hpp> | #include <nlohmann/json.hpp> | ||||
| #include <range/v3/range/conversion.hpp> | #include <range/v3/range/conversion.hpp> | ||||
| #include <range/v3/view/join.hpp> | #include <range/v3/view/join.hpp> |
| #include "./info.hpp" | #include "./info.hpp" | ||||
| #include <dds/deps.hpp> | |||||
| #include <dds/pkg/id.hpp> | |||||
| #include <dds/util/fs.hpp> | #include <dds/util/fs.hpp> | ||||
| #include <dds/util/glob.hpp> | |||||
| #include <neo/sqlite3/database.hpp> | #include <neo/sqlite3/database.hpp> | ||||
| #include <neo/sqlite3/statement.hpp> | #include <neo/sqlite3/statement.hpp> | ||||
| #include <neo/sqlite3/statement_cache.hpp> | #include <neo/sqlite3/statement_cache.hpp> | ||||
| #include <neo/sqlite3/transaction.hpp> | |||||
| #include <string> | #include <string> | ||||
| #include <variant> | |||||
| #include <vector> | #include <vector> | ||||
| namespace dds { | namespace dds { | ||||
| struct dependency; | |||||
| struct pkg_id; | |||||
| class pkg_db { | class pkg_db { | ||||
| neo::sqlite3::database _db; | neo::sqlite3::database _db; | ||||
| mutable neo::sqlite3::statement_cache _stmt_cache{_db}; | mutable neo::sqlite3::statement_cache _stmt_cache{_db}; |
| } // namespace | } // namespace | ||||
| remote_repository remote_repository::connect(std::string_view url_str) { | |||||
| pkg_remote pkg_remote::connect(std::string_view url_str) { | |||||
| DDS_E_SCOPE(e_url_string{std::string(url_str)}); | DDS_E_SCOPE(e_url_string{std::string(url_str)}); | ||||
| const auto url = neo::url::parse(url_str); | const auto url = neo::url::parse(url_str); | ||||
| return {name, url}; | return {name, url}; | ||||
| } | } | ||||
| void remote_repository::store(nsql::database_ref db) { | |||||
| void pkg_remote::store(nsql::database_ref db) { | |||||
| auto st = db.prepare(R"( | auto st = db.prepare(R"( | ||||
| INSERT INTO dds_cat_remotes (name, gen_ident, remote_url) | INSERT INTO dds_cat_remotes (name, gen_ident, remote_url) | ||||
| VALUES (?, ?, ?) | VALUES (?, ?, ?) | ||||
| nsql::exec(st, _name, "[placeholder]", _base_url.to_string()); | nsql::exec(st, _name, "[placeholder]", _base_url.to_string()); | ||||
| } | } | ||||
| void remote_repository::update_catalog(nsql::database_ref db) { | |||||
| void pkg_remote::update_pkg_db(nsql::database_ref db) { | |||||
| dds_log(info, "Pulling repository contents for {} [{}]", _name, _base_url.to_string()); | dds_log(info, "Pulling repository contents for {} [{}]", _name, _base_url.to_string()); | ||||
| auto rdb = remote_db::download_and_open_for_base(_base_url); | auto rdb = remote_db::download_and_open_for_base(_base_url); | ||||
| for (const auto& [name, remote_url] : tups) { | for (const auto& [name, remote_url] : tups) { | ||||
| DDS_E_SCOPE(e_url_string{remote_url}); | DDS_E_SCOPE(e_url_string{remote_url}); | ||||
| remote_repository repo{name, neo::url::parse(remote_url)}; | |||||
| repo.update_catalog(db); | |||||
| pkg_remote repo{name, neo::url::parse(remote_url)}; | |||||
| repo.update_pkg_db(db); | |||||
| } | } | ||||
| dds_log(info, "Recompacting database..."); | dds_log(info, "Recompacting database..."); |
| #pragma once | #pragma once | ||||
| #include <dds/util/fs.hpp> | |||||
| #include <dds/util/result.hpp> | |||||
| #include <neo/concepts.hpp> | |||||
| #include <neo/sqlite3/database.hpp> | #include <neo/sqlite3/database.hpp> | ||||
| #include <neo/url.hpp> | #include <neo/url.hpp> | ||||
| #include <string_view> | #include <string_view> | ||||
| #include <variant> | |||||
| namespace dds { | namespace dds { | ||||
| class remote_repository { | |||||
| class pkg_remote { | |||||
| std::string _name; | std::string _name; | ||||
| neo::url _base_url; | neo::url _base_url; | ||||
| public: | public: | ||||
| remote_repository(std::string name, neo::url url) | |||||
| pkg_remote(std::string name, neo::url url) | |||||
| : _name(std::move(name)) | : _name(std::move(name)) | ||||
| , _base_url(std::move(url)) {} | , _base_url(std::move(url)) {} | ||||
| remote_repository() = default; | |||||
| pkg_remote() = default; | |||||
| static remote_repository connect(std::string_view url); | |||||
| static pkg_remote connect(std::string_view url); | |||||
| void store(neo::sqlite3::database_ref); | void store(neo::sqlite3::database_ref); | ||||
| void update_catalog(neo::sqlite3::database_ref); | |||||
| void update_pkg_db(neo::sqlite3::database_ref); | |||||
| }; | }; | ||||
| void update_all_remotes(neo::sqlite3::database_ref); | void update_all_remotes(neo::sqlite3::database_ref); |