aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/manifest.cxx17
-rw-r--r--tests/repository-location/driver.cxx83
2 files changed, 84 insertions, 16 deletions
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index ac746e6..7f847a3 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -1407,7 +1407,10 @@ namespace bpkg
// Finish calculating the canonical name, unless we are relative.
//
if (relative ())
+ {
+ assert (canonical_name_.empty ());
return;
+ }
// Search for the version path component preceeding canonical name
// <path> component.
@@ -1432,9 +1435,21 @@ namespace bpkg
if (stoul (*i) != 1)
throw invalid_argument ("unsupported repository version");
+ dir_path p (rb, i); // Canonical name path part.
+
+ // Prefix ends with "pkg" component.
+ //
+ bool pc (++i != re && (*i == "pkg" || *i == "bpkg"));
+
+ if (pc)
+ ++i; // Skip "pkg" component from prefix.
+
+ if (!host_.empty () || !pc)
+ p = dir_path (i, re) / p; // Concatenate prefix and path.
+
// Note: allow empty paths (e.g., http://stable.cppget.org/1/).
//
- string d (dir_path (rb, i).posix_string ());
+ string d (p.posix_string ());
if (!canonical_name_.empty () && !d.empty ()) // If we have host and dir.
canonical_name_ += '/';
diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx
index 5d88b0d..908b243 100644
--- a/tests/repository-location/driver.cxx
+++ b/tests/repository-location/driver.cxx
@@ -133,16 +133,51 @@ main (int argc, char* argv[])
{
repository_location l ("1/aa/bb", repository_location ());
assert (l.string () == "1/aa/bb");
+ // Relative locations have no canonical name.
+ //
+ assert (l.canonical_name ().empty ());
+ }
+ {
+ repository_location l ("bpkg/1/aa/bb", repository_location ());
+ assert (l.string () == "bpkg/1/aa/bb");
+ assert (l.canonical_name ().empty ());
+ }
+ {
+ repository_location l ("b/pkg/1/aa/bb", repository_location ());
+ assert (l.string () == "b/pkg/1/aa/bb");
assert (l.canonical_name ().empty ());
}
{
repository_location l ("/1/aa/bb", repository_location ());
assert (l.string () == "/1/aa/bb");
+ assert (l.canonical_name () == "/aa/bb");
+ }
+ {
+ repository_location l ("/pkg/1/aa/bb", repository_location ());
+ assert (l.string () == "/pkg/1/aa/bb");
assert (l.canonical_name () == "aa/bb");
}
{
+ repository_location l ("/var/pkg/1/example.org/math/testing",
+ repository_location ());
+ assert (l.string () == "/var/pkg/1/example.org/math/testing");
+ assert (l.canonical_name () == "example.org/math/testing");
+ }
+ {
+ repository_location l ("/var/pkg/example.org/1/math/testing",
+ repository_location ());
+ assert (l.string () == "/var/pkg/example.org/1/math/testing");
+ assert (l.canonical_name () == "/var/pkg/example.org/math/testing");
+ }
+ {
repository_location l ("/a/b/../c/1/aa/../bb", repository_location ());
assert (l.string () == "/a/c/1/bb");
+ assert (l.canonical_name () == "/a/c/bb");
+ }
+ {
+ repository_location l ("/a/b/../c/pkg/1/aa/../bb",
+ repository_location ());
+ assert (l.string () == "/a/c/pkg/1/bb");
assert (l.canonical_name () == "bb");
}
{
@@ -165,59 +200,71 @@ main (int argc, char* argv[])
{
repository_location l ("http://www.a.com:8080/dd/1/aa/bb");
assert (l.string () == "http://www.a.com:8080/dd/1/aa/bb");
- assert (l.canonical_name () == "a.com:8080/aa/bb");
+ assert (l.canonical_name () == "a.com:8080/dd/aa/bb");
+ assert (!l.secure ());
+ }
+ {
+ repository_location l ("http://www.a.com:8080/dd/pkg/1/aa/bb");
+ assert (l.string () == "http://www.a.com:8080/dd/pkg/1/aa/bb");
+ assert (l.canonical_name () == "a.com:8080/dd/aa/bb");
+ assert (!l.secure ());
+ }
+ {
+ repository_location l ("http://www.a.com:8080/bpkg/dd/1/aa/bb");
+ assert (l.string () == "http://www.a.com:8080/bpkg/dd/1/aa/bb");
+ assert (l.canonical_name () == "a.com:8080/bpkg/dd/aa/bb");
assert (!l.secure ());
}
{
repository_location l ("https://www.a.com:444/dd/1/aa/bb");
assert (l.string () == "https://www.a.com:444/dd/1/aa/bb");
- assert (l.canonical_name () == "a.com:444/aa/bb");
+ assert (l.canonical_name () == "a.com:444/dd/aa/bb");
assert (l.secure ());
}
{
repository_location l ("http://a.com/a/b/../c/1/aa/../bb");
assert (l.string () == "http://a.com/a/c/1/bb");
- assert (l.canonical_name () == "a.com/bb");
+ assert (l.canonical_name () == "a.com/a/c/bb");
}
{
repository_location l ("https://a.com/a/b/../c/1/aa/../bb");
assert (l.string () == "https://a.com/a/c/1/bb");
- assert (l.canonical_name () == "a.com/bb");
+ assert (l.canonical_name () == "a.com/a/c/bb");
}
{
repository_location l ("http://www.CPPget.org/qw/1/a/b/");
assert (l.string () == "http://www.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "cppget.org/a/b");
+ assert (l.canonical_name () == "cppget.org/qw/a/b");
}
{
repository_location l ("http://pkg.CPPget.org/qw/1/a/b/");
assert (l.string () == "http://pkg.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "cppget.org/a/b");
+ assert (l.canonical_name () == "cppget.org/qw/a/b");
}
{
repository_location l ("http://bpkg.CPPget.org/qw/1/a/b/");
assert (l.string () == "http://bpkg.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "cppget.org/a/b");
+ assert (l.canonical_name () == "cppget.org/qw/a/b");
}
{
repository_location l ("http://abc.cppget.org/qw/1/a/b/");
assert (l.string () == "http://abc.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "abc.cppget.org/a/b");
+ assert (l.canonical_name () == "abc.cppget.org/qw/a/b");
}
{
repository_location l ("http://pkg.www.cppget.org/qw/1/a/b/");
assert (l.string () == "http://pkg.www.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "www.cppget.org/a/b");
+ assert (l.canonical_name () == "www.cppget.org/qw/a/b");
}
{
repository_location l ("http://bpkg.www.cppget.org/qw/1/a/b/");
assert (l.string () == "http://bpkg.www.cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "www.cppget.org/a/b");
+ assert (l.canonical_name () == "www.cppget.org/qw/a/b");
}
{
repository_location l ("http://cppget.org/qw//1/a//b/");
assert (l.string () == "http://cppget.org/qw/1/a/b");
- assert (l.canonical_name () == "cppget.org/a/b");
+ assert (l.canonical_name () == "cppget.org/qw/a/b");
}
{
repository_location l ("http://stable.cppget.org/1/");
@@ -230,6 +277,12 @@ main (int argc, char* argv[])
assert (l2.canonical_name () == "stable.cppget.org/math");
}
{
+ repository_location l1 ("http://stable.cppget.org/1/misc");
+ repository_location l2 ("../../pkg/1/math", l1);
+ assert (l2.string () == "http://stable.cppget.org/pkg/1/math");
+ assert (l2.canonical_name () == "stable.cppget.org/math");
+ }
+ {
repository_location l1 ("https://stable.cppget.org/1/misc");
repository_location l2 ("../../1/math", l1);
assert (l2.string () == "https://stable.cppget.org/1/math");
@@ -259,25 +312,25 @@ main (int argc, char* argv[])
repository_location l1 ("/var/r1/1/misc");
repository_location l2 ("../../../r2/1/math", l1);
assert (l2.string () == "/var/r2/1/math");
- assert (l2.canonical_name () == "math");
+ assert (l2.canonical_name () == "/var/r2/math");
}
{
repository_location l1 ("/var/1/misc");
repository_location l2 ("../math", l1);
assert (l2.string () == "/var/1/math");
- assert (l2.canonical_name () == "math");
+ assert (l2.canonical_name () == "/var/math");
}
{
repository_location l1 ("/var/1/stable");
repository_location l2 ("/var/1/test", l1);
assert (l2.string () == "/var/1/test");
- assert (l2.canonical_name () == "test");
+ assert (l2.canonical_name () == "/var/test");
}
{
repository_location l1 ("http://stable.cppget.org/1/misc");
repository_location l2 ("/var/1/test", l1);
assert (l2.string () == "/var/1/test");
- assert (l2.canonical_name () == "test");
+ assert (l2.canonical_name () == "/var/test");
}
{
repository_location l1 ("http://www.cppget.org/1/stable");