Load local path when offline (#3937)

This commit is contained in:
Antoine Prouvost 2025-05-13 16:37:45 +02:00 committed by GitHub
parent 5c838795ab
commit 5e0e879e0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 13 deletions

View File

@ -8,6 +8,7 @@
#define MAMBA_CORE_SUBDIRDATA_HPP
#include <algorithm>
#include <optional>
#include <string>
#include <nlohmann/json_fwd.hpp>
@ -240,9 +241,10 @@ namespace mamba
auto build_check_requests(const SubdirParams& params) -> download::MultiRequest;
template <typename First, typename End>
static auto build_all_index_requests(First subdirs_first, End subdirs_last)
static auto
build_all_index_requests(First subdirs_first, End subdirs_last, const SubdirParams& params)
-> download::MultiRequest;
auto build_index_request() -> download::Request;
auto build_index_request(const SubdirParams& params) -> std::optional<download::Request>;
[[nodiscard]] static auto download_requests(
download::MultiRequest index_requests,
@ -309,19 +311,14 @@ namespace mamba
// Allow to continue if failed checks, unless asked to stop.
constexpr auto is_interrupted = [](const auto& e)
{ return e.error_code() == mamba_error_code::user_interrupted; };
if (!result.has_value() && result.map_error(is_interrupted).error())
{
return result;
}
// TODO load local channels even when offline if (!ctx.offline)
if (subdir_params.offline)
{
return expected_t<void>();
}
return download_requests(
build_all_index_requests(subdirs_first, subdirs_last),
build_all_index_requests(subdirs_first, subdirs_last, subdir_params),
auth_info,
mirrors,
download_options,
@ -373,7 +370,8 @@ namespace mamba
}
template <typename First, typename End>
auto SubdirData::build_all_index_requests(First subdirs_first, End subdirs_last)
auto
SubdirData::build_all_index_requests(First subdirs_first, End subdirs_last, const SubdirParams& params)
-> download::MultiRequest
{
download::MultiRequest requests;
@ -381,7 +379,10 @@ namespace mamba
{
if (!subdirs_first->valid_cache_found())
{
requests.push_back(subdirs_first->build_index_request());
if (auto request = subdirs_first->build_index_request(params))
{
requests.push_back(*std::move(request));
}
}
}
return requests;

View File

@ -746,8 +746,14 @@ namespace mamba
return request;
}
download::Request SubdirData::build_index_request()
auto SubdirData::build_index_request(const SubdirParams& params)
-> std::optional<download::Request>
{
if (params.offline && !caching_is_forbidden())
{
return std::nullopt;
}
fs::u8path writable_cache_dir = create_cache_dir(m_writable_pkgs_dir);
auto lock = LockFile(writable_cache_dir);
@ -805,7 +811,7 @@ namespace mamba
}
};
return request;
return { std::move(request) };
}
expected_t<void> SubdirData::use_existing_cache()