Skip to content

Commit 1146b9c

Browse files
committed
Add note and fix downloaded url
1 parent 868a059 commit 1146b9c

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

libmamba/include/mamba/core/package_fetcher.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ namespace mamba
101101

102102
struct CheckSumParams;
103103

104-
bool is_local_package() const;
105-
bool use_explicit_https_url() const;
104+
bool use_oci() const;
106105
const std::string& filename() const;
107106
std::string channel() const;
108107
std::string url_path() const;

libmamba/src/core/package_fetcher.cpp

+21-31
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace mamba
152152
cb.value()(success.transfer.downloaded_size);
153153
}
154154
m_needs_download = false;
155-
m_downloaded_url = success.transfer.effective_url;
155+
m_downloaded_url = m_package_info.package_url;
156156
return expected_t<void>();
157157
};
158158

@@ -317,53 +317,43 @@ namespace mamba
317317
/*******************
318318
* Private methods *
319319
*******************/
320-
// TODO to be removed if not used
321-
bool PackageFetcher::is_local_package() const
322-
{
323-
return util::starts_with(m_package_info.package_url, "file://");
324-
}
325320

326-
bool PackageFetcher::use_explicit_https_url() const
321+
const std::string& PackageFetcher::filename() const
327322
{
328-
// This excludes OCI case, which uses explicitly a "oci://" scheme,
329-
// but is resolved later to something starting with `oci_base_url`
330-
constexpr std::string_view oci_base_url = "https://pkg-containers.githubusercontent.com/";
331-
return util::starts_with(m_package_info.package_url, "https://")
332-
&& !util::starts_with(m_package_info.package_url, oci_base_url);
323+
return m_package_info.filename;
333324
}
334325

335-
const std::string& PackageFetcher::filename() const
326+
bool PackageFetcher::use_oci() const
336327
{
337-
return m_package_info.filename;
328+
constexpr std::string_view oci_scheme = "oci://";
329+
return util::starts_with(m_package_info.package_url, oci_scheme);
338330
}
339331

332+
// NOTE
333+
// In the general case (not fetching from an oci registry),
334+
// `channel()` and `url_path()` are concatenated when passed to `HTTPMirror`
335+
// and the channel is resolved if needed (using the channel alias).
336+
// Therefore, `util::url_concat("", m_package_info.package_url)`
337+
// and `util::url_concat(m_package_info.channel, m_package_info.platform,
338+
// m_package_info.filename)` should be equivalent, except when an explicit url is used as a spec
339+
// with `--override-channels` option.
340+
// Hence, we are favoring the first option (returning "" and `m_package_info.package_url`
341+
// to be concatenated), valid for all the mentioned cases used with `HTTPMirror`.
342+
// In the case of fetching from oci registries (using `OCIMirror`),the actual url
343+
// used is built differently, and returning `m_package_info.package_url` is not relevant
344+
// (i.e oci://ghcr.io/<mirror>/<channel>/<platform>/<filename>).
340345
std::string PackageFetcher::channel() const
341346
{
342-
// if (is_local_package() || use_explicit_https_url())
343-
// {
344-
// // Use explicit url or local package path
345-
// // to fetch package, leaving the channel empty.
346-
// return "";
347-
// }
348-
// return m_package_info.channel;
349-
if (util::starts_with(m_package_info.package_url, "oci://"))
347+
if (use_oci())
350348
{
351349
return m_package_info.channel;
352350
}
353351
return "";
354352
}
355353

356-
// TODO to rename, second_part_url?
357354
std::string PackageFetcher::url_path() const
358355
{
359-
// if (is_local_package() || use_explicit_https_url())
360-
// {
361-
// // Use explicit url or local package path
362-
// // to fetch package.
363-
// return m_package_info.package_url;
364-
// }
365-
// return util::concat(m_package_info.platform, '/', m_package_info.filename);
366-
if (util::starts_with(m_package_info.package_url, "oci://"))
356+
if (use_oci())
367357
{
368358
return util::concat(m_package_info.platform, '/', m_package_info.filename);
369359
}

micromamba/tests/test_create.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def test_create_with_explicit_url(tmp_home, tmp_root_prefix, tmp_path, spec):
12411241
assert pkgs[0]["channel"] == "https://conda.anaconda.org/conda-forge"
12421242

12431243

1244-
def test_create_with_from_mirror(tmp_home, tmp_root_prefix, tmp_path):
1244+
def test_create_from_mirror(tmp_home, tmp_root_prefix, tmp_path):
12451245
"""Attempts to install a package using an explicit channel/mirror."""
12461246
empty_root_prefix = tmp_path / "empty-root-create-from-mirror"
12471247
env_name = "env-create-from-mirror"

0 commit comments

Comments
 (0)