From 8546868b68642c2c9199825b5043c435b80dc90e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Sep 2016 23:26:35 +0300 Subject: Do not strip absolute location canonical name prefix if the result is empty --- bpkg/manifest.cxx | 7 +++++++ tests/repository-location/driver.cxx | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index 86ca7fa..d6c6afb 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -1682,6 +1682,13 @@ namespace bpkg dir_path sp (strip_path ( path_, remote () ? strip_mode::component : strip_mode::path)); + // If for an absolute path location the stripping result is empty (which + // also means part is empty as well) then fallback to stripping + // just the version component. + // + if (absolute () && sp.empty ()) + sp = strip_path (path_, strip_mode::version); + string cp (sp.relative () ? sp.posix_string () : sp.string ()); // Note: allow empty paths (e.g., http://stable.cppget.org/1/). diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx index 48b32fd..2a2418c 100644 --- a/tests/repository-location/driver.cxx +++ b/tests/repository-location/driver.cxx @@ -237,6 +237,16 @@ main (int argc, char* argv[]) assert (l.canonical_name () == "aa/bb"); } { + repository_location l ("/var/bpkg/1", repository_location ()); + assert (l.string () == "/var/bpkg/1"); + assert (l.canonical_name () == "/var/bpkg"); + } + { + repository_location l ("/1", repository_location ()); + assert (l.string () == "/1"); + assert (l.canonical_name () == "/"); + } + { repository_location l ("/var/pkg/1/example.org/math/testing", repository_location ()); assert (l.string () == "/var/pkg/1/example.org/math/testing"); -- cgit v1.1