Skip to content

Commit 5e0e879

Browse files
authored
Load local path when offline (#3937)
1 parent 5c83879 commit 5e0e879

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

libmamba/include/mamba/core/subdirdata.hpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define MAMBA_CORE_SUBDIRDATA_HPP
99

1010
#include <algorithm>
11+
#include <optional>
1112
#include <string>
1213

1314
#include <nlohmann/json_fwd.hpp>
@@ -240,9 +241,10 @@ namespace mamba
240241
auto build_check_requests(const SubdirParams& params) -> download::MultiRequest;
241242

242243
template <typename First, typename End>
243-
static auto build_all_index_requests(First subdirs_first, End subdirs_last)
244+
static auto
245+
build_all_index_requests(First subdirs_first, End subdirs_last, const SubdirParams& params)
244246
-> download::MultiRequest;
245-
auto build_index_request() -> download::Request;
247+
auto build_index_request(const SubdirParams& params) -> std::optional<download::Request>;
246248

247249
[[nodiscard]] static auto download_requests(
248250
download::MultiRequest index_requests,
@@ -309,19 +311,14 @@ namespace mamba
309311
// Allow to continue if failed checks, unless asked to stop.
310312
constexpr auto is_interrupted = [](const auto& e)
311313
{ return e.error_code() == mamba_error_code::user_interrupted; };
314+
312315
if (!result.has_value() && result.map_error(is_interrupted).error())
313316
{
314317
return result;
315318
}
316319

317-
// TODO load local channels even when offline if (!ctx.offline)
318-
if (subdir_params.offline)
319-
{
320-
return expected_t<void>();
321-
}
322-
323320
return download_requests(
324-
build_all_index_requests(subdirs_first, subdirs_last),
321+
build_all_index_requests(subdirs_first, subdirs_last, subdir_params),
325322
auth_info,
326323
mirrors,
327324
download_options,
@@ -373,15 +370,19 @@ namespace mamba
373370
}
374371

375372
template <typename First, typename End>
376-
auto SubdirData::build_all_index_requests(First subdirs_first, End subdirs_last)
373+
auto
374+
SubdirData::build_all_index_requests(First subdirs_first, End subdirs_last, const SubdirParams& params)
377375
-> download::MultiRequest
378376
{
379377
download::MultiRequest requests;
380378
for (; subdirs_first != subdirs_last; ++subdirs_first)
381379
{
382380
if (!subdirs_first->valid_cache_found())
383381
{
384-
requests.push_back(subdirs_first->build_index_request());
382+
if (auto request = subdirs_first->build_index_request(params))
383+
{
384+
requests.push_back(*std::move(request));
385+
}
385386
}
386387
}
387388
return requests;

libmamba/src/core/subdirdata.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,14 @@ namespace mamba
746746
return request;
747747
}
748748

749-
download::Request SubdirData::build_index_request()
749+
auto SubdirData::build_index_request(const SubdirParams& params)
750+
-> std::optional<download::Request>
750751
{
752+
if (params.offline && !caching_is_forbidden())
753+
{
754+
return std::nullopt;
755+
}
756+
751757
fs::u8path writable_cache_dir = create_cache_dir(m_writable_pkgs_dir);
752758
auto lock = LockFile(writable_cache_dir);
753759

@@ -805,7 +811,7 @@ namespace mamba
805811
}
806812
};
807813

808-
return request;
814+
return { std::move(request) };
809815
}
810816

811817
expected_t<void> SubdirData::use_existing_cache()

0 commit comments

Comments
 (0)