Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

73 lines
2.3KB

  1. #include "../options.hpp"
  2. #include <dds/dym.hpp>
  3. #include <dds/error/errors.hpp>
  4. #include <dds/pkg/db.hpp>
  5. #include <dds/pkg/get/get.hpp>
  6. #include <dds/util/http/pool.hpp>
  7. #include <dds/util/result.hpp>
  8. #include <boost/leaf/handle_exception.hpp>
  9. #include <json5/parse_data.hpp>
  10. #include <neo/url.hpp>
  11. namespace dds::cli::cmd {
  12. static int _pkg_get(const options& opts) {
  13. auto cat = opts.open_catalog();
  14. for (const auto& item : opts.pkg.get.pkgs) {
  15. auto id = pkg_id::parse(item);
  16. dds::dym_target dym;
  17. auto info = cat.get(id);
  18. if (!info) {
  19. dds::throw_user_error<dds::errc::no_such_catalog_package>(
  20. "No package in the database matched the ID '{}'.{}", item, dym.sentence_suffix());
  21. }
  22. auto tsd = get_package_sdist(*info);
  23. auto dest = opts.out_path.value_or(fs::current_path()) / id.to_string();
  24. dds_log(info, "Create sdist at {}", dest.string());
  25. fs::remove_all(dest);
  26. safe_rename(tsd.sdist.path, dest);
  27. }
  28. return 0;
  29. }
  30. int pkg_get(const options& opts) {
  31. return boost::leaf::try_catch( //
  32. [&] {
  33. try {
  34. return _pkg_get(opts);
  35. } catch (...) {
  36. dds::capture_exception();
  37. }
  38. },
  39. [&](neo::url_validation_error url_err, dds::e_url_string bad_url) {
  40. dds_log(error,
  41. "Invalid package URL in the database [{}]: {}",
  42. bad_url.value,
  43. url_err.what());
  44. return 1;
  45. },
  46. [&](const json5::parse_error& e, neo::url bad_url) {
  47. dds_log(error,
  48. "Error parsing JSON5 document package downloaded from [{}]: {}",
  49. bad_url.to_string(),
  50. e.what());
  51. return 1;
  52. },
  53. [](dds::e_sqlite3_error_exc e) {
  54. dds_log(error, "Error accessing the package database: {}", e.message);
  55. return 1;
  56. },
  57. [&](dds::e_system_error_exc e, dds::network_origin conn) {
  58. dds_log(error,
  59. "Error opening connection to [{}:{}]: {}",
  60. conn.hostname,
  61. conn.port,
  62. e.message);
  63. return 1;
  64. });
  65. }
  66. } // namespace dds::cli::cmd