aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-unpack.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-05-21 21:10:09 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-05-24 17:39:13 +0300
commit3a6c4ab1b6fc79a6a543088553cdd6bc8cb0a1dd (patch)
tree1ca0c3b9ef763276ff45c20a62d2504833e5f67d /bpkg/pkg-unpack.cxx
parent1cab4fbd051ee5a71f073446ad5ad1b3d79f1031 (diff)
Adapt to inventing package_name type
Diffstat (limited to 'bpkg/pkg-unpack.cxx')
-rw-r--r--bpkg/pkg-unpack.cxx33
1 files changed, 24 insertions, 9 deletions
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index 89a737b..85cd93f 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -33,7 +33,7 @@ namespace bpkg
static void
pkg_unpack_check (const dir_path& c,
transaction& t,
- const string& n,
+ const package_name& n,
bool replace)
{
tracer trace ("pkg_update_check");
@@ -61,13 +61,14 @@ namespace bpkg
}
}
- // Select the external package in this configuration.
+ // Select the external package in this configuration. Can return a new
+ // selected package object, replacing the existing one.
//
static shared_ptr<selected_package>
pkg_unpack (const common_options& o,
dir_path c,
transaction& t,
- string n,
+ package_name n,
version v,
dir_path d,
repository_location rl,
@@ -104,6 +105,20 @@ namespace bpkg
//
pkg_purge_fs (c, t, p, simulate);
+ // Note that if the package name spelling changed then we need to update
+ // it, to make sure that the subsequent commands don't fail and the
+ // diagnostics is not confusing. Hover, we cannot update the object id,
+ // so have to erase it and persist afterwards.
+ //
+ if (p->name.string () != n.string ())
+ {
+ db.erase (p);
+ p = nullptr;
+ }
+ }
+
+ if (p != nullptr)
+ {
p->version = move (v);
p->state = package_state::unpacked;
p->repository_fragment = move (rl);
@@ -190,7 +205,7 @@ namespace bpkg
pkg_unpack (const common_options& o,
const dir_path& c,
transaction& t,
- string n,
+ package_name n,
version v,
bool replace,
bool simulate)
@@ -254,7 +269,7 @@ namespace bpkg
pkg_unpack (const common_options& co,
const dir_path& c,
transaction& t,
- const string& name,
+ const package_name& name,
bool simulate)
{
tracer trace ("pkg_unpack");
@@ -280,7 +295,7 @@ namespace bpkg
// Also, since we must have verified the archive during fetch,
// here we can just assume what the resulting directory will be.
//
- dir_path d (c / dir_path (p->name + '-' + p->version.string ()));
+ dir_path d (c / dir_path (p->name.string () + '-' + p->version.string ()));
if (exists (d))
fail << "package directory " << d << " already exists";
@@ -462,9 +477,9 @@ namespace bpkg
fail << "package name argument expected" <<
info << "run 'bpkg help pkg-unpack' for more information";
- const char* arg (args.next ());
- string n (parse_package_name (arg));
- version v (parse_package_version (arg));
+ const char* arg (args.next ());
+ package_name n (parse_package_name (arg));
+ version v (parse_package_version (arg));
external = !v.empty ();