From 25983f96f12870d3712e95a49a0cae606493c8b2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 15 Jan 2018 23:16:08 +0300 Subject: Add type prefix for repository canonical name --- libbpkg/manifest.cxx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'libbpkg') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index bd50c84..9859a47 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -1791,7 +1791,9 @@ namespace bpkg if (remote ()) { - canonical_name_ = strip_domain (url_.authority->host, type_); + canonical_name_ = to_string (type_); + canonical_name_ += ':'; + canonical_name_ += strip_domain (url_.authority->host, type_); // For canonical name and for the HTTP protocol, treat a.com and // a.com:80 as the same name. The same rule applies to the HTTPS (port @@ -1827,7 +1829,7 @@ namespace bpkg url_ = move (u); - // Set canonical name to the base location canonical name host + // Set canonical name to the base location canonical name 'bpkg:' // part. The path part of the canonical name is calculated below. // if (b.remote ()) @@ -1897,17 +1899,25 @@ namespace bpkg string cp (sp.relative () ? sp.posix_string () : sp.string ()); + // Don't allow empty canonical names. + // + if (canonical_name_.empty () && cp.empty ()) + throw invalid_argument ("empty repository name"); + // Note: allow empty paths (e.g., http://stable.cppget.org/1/). // - if (!canonical_name_.empty () && !cp.empty ()) // If we have host and dir. - canonical_name_ += '/'; + if (!cp.empty ()) + { + if (!canonical_name_.empty ()) // If we have host and dir. + canonical_name_ += '/'; + else // If we have just dir. + { + canonical_name_ = to_string (type_); + canonical_name_ += ':'; + } + } canonical_name_ += cp; - - // But don't allow empty canonical names. - // - if (canonical_name_.empty ()) - throw invalid_argument ("empty repository name"); } // repository_manifest -- cgit v1.1