diff options
-rw-r--r-- | bpkg/build.cxx | 12 | ||||
-rw-r--r-- | bpkg/forward | 2 | ||||
-rw-r--r-- | bpkg/package | 41 | ||||
-rw-r--r-- | bpkg/package.cxx | 22 | ||||
-rw-r--r-- | bpkg/package.xml | 10 | ||||
-rw-r--r-- | bpkg/pkg-command.cxx | 4 | ||||
-rw-r--r-- | bpkg/pkg-configure.cxx | 18 | ||||
-rw-r--r-- | bpkg/pkg-disfigure | 4 | ||||
-rw-r--r-- | bpkg/pkg-disfigure.cxx | 23 | ||||
-rw-r--r-- | bpkg/pkg-fetch.cxx | 6 | ||||
-rw-r--r-- | bpkg/pkg-purge.cxx | 24 | ||||
-rw-r--r-- | bpkg/pkg-status.cxx | 6 | ||||
-rw-r--r-- | bpkg/pkg-unpack.cxx | 18 |
13 files changed, 97 insertions, 93 deletions
diff --git a/bpkg/build.cxx b/bpkg/build.cxx index e9377ec..d2ec9e8 100644 --- a/bpkg/build.cxx +++ b/bpkg/build.cxx @@ -21,7 +21,7 @@ using namespace butl; namespace bpkg { - struct selected_package // @@ Swap names. + struct satisfied_package { shared_ptr<available_package> ap; // Note: might be transient. @@ -29,7 +29,7 @@ namespace bpkg optional<dir_path> directory; }; - using packages = vector<selected_package>; + using packages = vector<satisfied_package>; void build (const build_options& o, cli::scanner& args) @@ -58,7 +58,7 @@ namespace bpkg { const char* s (args.next ()); - selected_package pkg; + satisfied_package pkg; // Reduce all the potential variations (archive, directory, // package, package version) to the single available_package @@ -158,9 +158,9 @@ namespace bpkg // package that we will be building (which may or may not be // the same as the selected package). // - shared_ptr<package> p (db.find<package> (n)); + shared_ptr<selected_package> p (db.find<selected_package> (n)); - if (p != nullptr && p->state == state::broken) + if (p != nullptr && p->state == package_state::broken) fail << "unable to build broken package " << n << info << "use 'pkg-purge --force' to remove"; @@ -215,7 +215,7 @@ namespace bpkg // can get its manifest. // ap = make_shared<available_package> ( - p->state == state::fetched + p->state == package_state::fetched ? pkg_verify (o, *p->archive) : pkg_verify (*p->src_root)); } diff --git a/bpkg/forward b/bpkg/forward index cddc89f..9ca44b6 100644 --- a/bpkg/forward +++ b/bpkg/forward @@ -14,7 +14,7 @@ namespace bpkg // <bpkg/package> // - class package; + class selected_package; } #endif // BPKG_FORWARD diff --git a/bpkg/package b/bpkg/package index 04cb821..ac0ac0f 100644 --- a/bpkg/package +++ b/bpkg/package @@ -312,9 +312,9 @@ namespace bpkg std::pair<shared_ptr<available_package>, shared_ptr<repository>> filter_one (const shared_ptr<repository>&, odb::result<available_package>&&); - // state + // package_state // - enum class state + enum class package_state { broken, fetched, @@ -323,31 +323,30 @@ namespace bpkg }; string - to_string (state); + to_string (package_state); - state - to_state (const string&); // May throw invalid_argument. + package_state + to_package_state (const string&); // May throw invalid_argument. inline std::ostream& - operator<< (std::ostream& os, state s) {return os << to_string (s);} + operator<< (std::ostream& os, package_state s) {return os << to_string (s);} - #pragma db map type(state) as(string) \ - to(to_string (?)) \ - from(bpkg::to_state (?)) + #pragma db map type(package_state) as(string) \ + to(to_string (?)) \ + from(bpkg::to_package_state (?)) // package // #pragma db object pointer(shared_ptr) session - class package + class selected_package { public: using version_type = bpkg::version; - using state_type = bpkg::state; string name; // Object id. version_type version; - state_type state; + package_state state; // Repository from which this package came. Note that it is not // a pointer to the repository object because it could be wiped @@ -390,7 +389,7 @@ namespace bpkg // A map of "effective" prerequisites (i.e., pointers to other // selected packages) to optional dependency constraint. // - using prerequisites_type = std::map<lazy_shared_ptr<package>, + using prerequisites_type = std::map<lazy_shared_ptr<selected_package>, optional<dependency_constraint>, compare_lazy_ptr>; prerequisites_type prerequisites; @@ -404,16 +403,16 @@ namespace bpkg private: friend class odb::access; - package () = default; + selected_package () = default; }; // Return a list of packages that depend on this package along with // their constraints. // /* - #pragma db view object(package) \ - container(package::prerequisites = pp inner: pp.key) - struct package_dependents + #pragma db view object(selected_package) \ + container(selected_package::prerequisites = pp inner: pp.key) + struct package_dependent { #pragma db column(pp.id) string name; @@ -426,10 +425,10 @@ namespace bpkg // @@ Using raw container table since ODB doesn't support containers // in views yet. // - #pragma db view object(package) \ - table("package_prerequisites" = "pp" inner: \ - "pp.prerequisite = " + package::name) - struct package_dependents + #pragma db view object(selected_package) \ + table("selected_package_prerequisites" = "pp" inner: \ + "pp.prerequisite = " + selected_package::name) + struct package_dependent { #pragma db column("pp.package") string name; diff --git a/bpkg/package.cxx b/bpkg/package.cxx index e764c3f..2612cbe 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -124,26 +124,26 @@ namespace bpkg // state // string - to_string (state s) + to_string (package_state s) { switch (s) { - case state::broken: return "broken"; - case state::fetched: return "fetched"; - case state::unpacked: return "unpacked"; - case state::configured: return "configured"; + case package_state::broken: return "broken"; + case package_state::fetched: return "fetched"; + case package_state::unpacked: return "unpacked"; + case package_state::configured: return "configured"; } return string (); // Should never reach. } - state - to_state (const string& s) + package_state + to_package_state (const string& s) { - if (s == "broken") return state::broken; - else if (s == "fetched") return state::fetched; - else if (s == "unpacked") return state::unpacked; - else if (s == "configured") return state::configured; + if (s == "broken") return package_state::broken; + else if (s == "fetched") return package_state::fetched; + else if (s == "unpacked") return package_state::unpacked; + else if (s == "configured") return package_state::configured; else throw invalid_argument ("invalid package state '" + s + "'"); } } diff --git a/bpkg/package.xml b/bpkg/package.xml index 9935e06..79d7ac7 100644 --- a/bpkg/package.xml +++ b/bpkg/package.xml @@ -152,7 +152,7 @@ <column name="version_revision"/> </index> </table> - <table name="package" kind="object"> + <table name="selected_package" kind="object"> <column name="name" type="TEXT" null="true"/> <column name="version_epoch" type="INTEGER" null="true"/> <column name="version_canonical_upstream" type="TEXT" null="true"/> @@ -169,7 +169,7 @@ <column name="name"/> </primary-key> </table> - <table name="package_prerequisites" kind="container"> + <table name="selected_package_prerequisites" kind="container"> <column name="package" type="TEXT" null="true"/> <column name="prerequisite" type="TEXT" null="true"/> <column name="operation" type="TEXT" null="true"/> @@ -179,16 +179,16 @@ <column name="version_upstream" type="TEXT" null="true"/> <foreign-key name="package_fk" on-delete="CASCADE"> <column name="package"/> - <references table="package"> + <references table="selected_package"> <column name="name"/> </references> </foreign-key> - <index name="package_prerequisites_package_i"> + <index name="selected_package_prerequisites_package_i"> <column name="package"/> </index> <foreign-key name="prerequisite_fk" deferrable="DEFERRED"> <column name="prerequisite"/> - <references table="package"> + <references table="selected_package"> <column name="name"/> </references> </foreign-key> diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index fc8deb9..39caa8e 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -36,13 +36,13 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr<package> p (db.find<package> (n)); + shared_ptr<selected_package> p (db.find<selected_package> (n)); t.commit (); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::configured) + if (p->state != package_state::configured) fail << "package " << n << " is " << p->state << info << "expected it to be configured"; diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 208fad4..c76fae9 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -53,12 +53,12 @@ namespace bpkg transaction t (db.begin ()); session s; - shared_ptr<package> p (db.find<package> (n)); + shared_ptr<selected_package> p (db.find<selected_package> (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::unpacked) + if (p->state != package_state::unpacked) fail << "package " << n << " is " << p->state << info << "expected it to be unpacked"; @@ -91,9 +91,11 @@ namespace bpkg bool satisfied (false); for (const dependency& d: da) { - if (shared_ptr<package> dp = db.find<package> (d.name)) + const string& n (d.name); + + if (shared_ptr<selected_package> dp = db.find<selected_package> (n)) { - if (dp->state != state::configured) + if (dp->state != package_state::configured) continue; if (!satisfies (dp->version, d.constraint)) @@ -113,8 +115,8 @@ namespace bpkg if (!s1 && !s2) fail << "incompatible constraints " - << "(" << d.name << " " << *c << ") and " - << "(" << d.name << " " << *d.constraint << ")"; + << "(" << n << " " << *c << ") and " + << "(" << n << " " << *d.constraint << ")"; if (s2 && !s1) c = d.constraint; @@ -161,14 +163,14 @@ namespace bpkg // Indicate to pkg_disfigure() we are partially configured. // p->out_root = out_root.leaf (); - p->state = state::broken; + p->state = package_state::broken; pkg_disfigure (c, t, p); // Commits the transaction. throw; } p->out_root = out_root.leaf (); - p->state = state::configured; + p->state = package_state::configured; db.update (p); t.commit (); diff --git a/bpkg/pkg-disfigure b/bpkg/pkg-disfigure index 2df892b..ef78d05 100644 --- a/bpkg/pkg-disfigure +++ b/bpkg/pkg-disfigure @@ -6,7 +6,7 @@ #define BPKG_PKG_DISFIGURE #include <bpkg/types> -#include <bpkg/forward> // transaction, package +#include <bpkg/forward> // transaction, selected_package #include <bpkg/pkg-disfigure-options> namespace bpkg @@ -23,7 +23,7 @@ namespace bpkg void pkg_disfigure (const dir_path& configuration, transaction&, - const shared_ptr<package>&); + const shared_ptr<selected_package>&); } #endif // BPKG_PKG_DISFIGURE diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index a3d0336..d9e5552 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -19,9 +19,10 @@ namespace bpkg void pkg_disfigure (const dir_path& c, transaction& t, - const shared_ptr<package>& p) + const shared_ptr<selected_package>& p) { - assert (p->state == state::configured || p->state == state::broken); + assert (p->state == package_state::configured || + p->state == package_state::broken); tracer trace ("pkg_disfigure"); @@ -30,18 +31,18 @@ namespace bpkg // Check that we have no dependents. // - if (p->state == state::configured) + if (p->state == package_state::configured) { - using query = query<package_dependents>; + using query = query<package_dependent>; - auto r (db.query<package_dependents> (query::name == p->name)); + auto r (db.query<package_dependent> (query::name == p->name)); if (!r.empty ()) { diag_record dr; dr << fail << "package " << p->name << " still has dependencies:"; - for (const package_dependents& pd: r) + for (const package_dependent& pd: r) { dr << info << "package " << pd.name; @@ -72,7 +73,7 @@ namespace bpkg // string bspec; - if (p->state == state::configured) + if (p->state == package_state::configured) { bspec = "clean(" + out_root.string () + "/) " "disfigure(" + out_root.string () + "/)"; @@ -110,7 +111,7 @@ namespace bpkg // If we failed to disfigure the package, set it to the broken // state. The user can then try to clean things up with pkg-purge. // - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -120,7 +121,7 @@ namespace bpkg } p->out_root = nullopt; - p->state = state::unpacked; + p->state = package_state::unpacked; db.update (p); t.commit (); @@ -143,12 +144,12 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr<package> p (db.find<package> (n)); + shared_ptr<selected_package> p (db.find<selected_package> (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::configured) + if (p->state != package_state::configured) fail << "package " << n << " is " << p->state << info << "expected it to be configured"; diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx index 4a2a9ea..14022e8 100644 --- a/bpkg/pkg-fetch.cxx +++ b/bpkg/pkg-fetch.cxx @@ -120,7 +120,7 @@ namespace bpkg // See if this package already exists in this configuration. // - if (shared_ptr<package> p = db.find<package> (n)) + if (shared_ptr<selected_package> p = db.find<selected_package> (n)) fail << "package " << n << " already exists in configuration " << c << info << "version: " << p->version << ", state: " << p->state; @@ -136,10 +136,10 @@ namespace bpkg // Add the package to the configuration. // - shared_ptr<package> p (new package { + shared_ptr<selected_package> p (new selected_package { move (m.name), move (m.version), - state::fetched, + package_state::fetched, move (rl), move (a), purge, diff --git a/bpkg/pkg-purge.cxx b/bpkg/pkg-purge.cxx index 76101ef..5e14a2b 100644 --- a/bpkg/pkg-purge.cxx +++ b/bpkg/pkg-purge.cxx @@ -33,7 +33,7 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr<package> p (db.find<package> (n)); + shared_ptr<selected_package> p (db.find<selected_package> (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; @@ -42,7 +42,7 @@ namespace bpkg // switch (p->state) { - case state::fetched: + case package_state::fetched: { // If we have --keep, then this is a no-op. We could have // detected this and returned but we still want the normal @@ -51,14 +51,14 @@ namespace bpkg // break; } - case state::unpacked: + case package_state::unpacked: { if (o.keep () && !p->archive) fail << "package " << n << " has no archive to keep"; break; } - case state::broken: + case package_state::broken: { if (!o.force ()) fail << "broken package " << n << " can only be purged with --force"; @@ -80,7 +80,7 @@ namespace bpkg { dir_path d (p->src_root->absolute () ? *p->src_root : c / *p->src_root); - if (p->state != state::broken) + if (p->state != package_state::broken) { try { @@ -92,7 +92,7 @@ namespace bpkg } catch (const failed&) { - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -116,7 +116,9 @@ namespace bpkg // if (p->out_root) { - assert (p->state == state::broken); // Can only be present if broken. + // Can only be present if broken. + // + assert (p->state == package_state::broken); dir_path d (c / *p->out_root); // Always relative. @@ -131,7 +133,7 @@ namespace bpkg { path a (p->archive->absolute () ? *p->archive : c / *p->archive); - if (p->state != state::broken) + if (p->state != package_state::broken) { try { @@ -143,7 +145,7 @@ namespace bpkg } catch (const failed&) { - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -162,9 +164,9 @@ namespace bpkg if (o.keep ()) { - if (p->state != state::fetched) // That no-op we were talking about. + if (p->state != package_state::fetched) // No-op we were talking about. { - p->state = state::fetched; + p->state = package_state::fetched; db.update (p); } } diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx index 196106a..c1cd12f 100644 --- a/bpkg/pkg-status.cxx +++ b/bpkg/pkg-status.cxx @@ -46,15 +46,15 @@ namespace bpkg // First search in the packages that already exist in this configuration. // - shared_ptr<package> p; + shared_ptr<selected_package> p; { - using query = query<package>; + using query = query<selected_package>; query q (query::name == n); if (!v.empty ()) q = q && query::version == v; - p = db.query_one<package> (q); + p = db.query_one<selected_package> (q); } // Now look for available packages. If the user specified the version diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 32d2af3..a7c53b6 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -22,7 +22,7 @@ using namespace butl; namespace bpkg { - static shared_ptr<package> + static shared_ptr<selected_package> pkg_unpack (database& db, const dir_path& c, const dir_path& d, bool purge) { tracer trace ("pkg_unpack(dir)"); @@ -42,7 +42,7 @@ namespace bpkg // See if this package already exists in this configuration. // - if (shared_ptr<package> p = db.find<package> (n)) + if (shared_ptr<selected_package> p = db.find<selected_package> (n)) fail << "package " << n << " already exists in configuration " << c << info << "version: " << p->version << ", state: " << p->state; @@ -60,10 +60,10 @@ namespace bpkg // Add the package to the configuration. Use the special root // repository as the repository of this package. // - shared_ptr<package> p (new package { + shared_ptr<selected_package> p (new selected_package { move (m.name), move (m.version), - state::unpacked, + package_state::unpacked, repository_location (), nullopt, // No archive false, // Don't purge archive. @@ -79,7 +79,7 @@ namespace bpkg return p; } - static shared_ptr<package> + static shared_ptr<selected_package> pkg_unpack (const common_options& co, database& db, const dir_path& c, @@ -89,12 +89,12 @@ namespace bpkg tracer_guard tg (db, trace); transaction t (db.begin ()); - shared_ptr<package> p (db.find<package> (name)); + shared_ptr<selected_package> p (db.find<selected_package> (name)); if (p == nullptr) fail << "package " << name << " does not exist in configuration " << c; - if (p->state != state::fetched) + if (p->state != package_state::fetched) fail << "package " << name << " is " << p->state << info << "expected it to be fetched"; @@ -169,7 +169,7 @@ namespace bpkg p->src_root = d.leaf (); // For now assuming to be in configuration. p->purge_src = true; - p->state = state::unpacked; + p->state = package_state::unpacked; db.update (p); t.commit (); @@ -189,7 +189,7 @@ namespace bpkg database db (open (c, trace)); - shared_ptr<package> p; + shared_ptr<selected_package> p; if (o.existing ()) { |