7
7
#ifndef MAMBA_CORE_SUBDIRDATA_HPP
8
8
#define MAMBA_CORE_SUBDIRDATA_HPP
9
9
10
+ #include < algorithm>
10
11
#include < memory>
11
12
#include < string>
12
13
@@ -131,8 +132,21 @@ namespace mamba
131
132
* The result can be inspected with the input subdirs methods, such as
132
133
* @ref valid_cache_found, @ref valid_json_cache_path etc.
133
134
*/
135
+ template <typename SubdirIter1, typename SubdirIter2>
134
136
[[nodiscard]] static auto download_required_indexes (
135
- std::vector<SubdirData>& subdirs,
137
+ SubdirIter1 subdirs_first,
138
+ SubdirIter2 subdirs_last,
139
+ const SubdirParams& subdir_params,
140
+ const specs::AuthenticationDataBase& auth_info,
141
+ const download::mirror_map& mirrors,
142
+ const download::Options& download_options,
143
+ const download::RemoteFetchParams& remote_fetch_params,
144
+ download::Monitor* check_monitor = nullptr ,
145
+ download::Monitor* download_monitor = nullptr
146
+ ) -> expected_t<void>;
147
+ template <typename Subdirs>
148
+ [[nodiscard]] static auto download_required_indexes (
149
+ Subdirs& subdirs,
136
150
const SubdirParams& subdir_params,
137
151
const specs::AuthenticationDataBase& auth_info,
138
152
const download::mirror_map& mirrors,
@@ -196,6 +210,10 @@ namespace mamba
196
210
197
211
[[nodiscard]] auto repodata_url_path () const -> std::string;
198
212
213
+ /* *************************************************
214
+ * Implementation details of SubdirData::create *
215
+ **************************************************/
216
+
199
217
void load (
200
218
const MultiPackageCache& caches,
201
219
ChannelContext& channel_context,
@@ -209,12 +227,33 @@ namespace mamba
209
227
const specs::Channel& channel
210
228
);
211
229
212
- auto build_check_requests (const SubdirParams& params) -> download::MultiRequest;
213
- auto build_index_request () -> download::Request;
230
+ /* ********************************************************************
231
+ * Implementation details of SubdirData::download_required_indexes *
232
+ *********************************************************************/
214
233
215
234
auto use_existing_cache () -> expected_t<void>;
216
235
auto finalize_transfer (SubdirMetadata::HttpMetadata http_data) -> expected_t<void>;
217
236
void refresh_last_write_time (const fs::u8path& json_file, const fs::u8path& solv_file);
237
+
238
+ template <typename First, typename End>
239
+ static auto
240
+ build_all_check_requests (First subdirs_first, End subdirs_last, const SubdirParams& params)
241
+ -> download::MultiRequest;
242
+ auto build_check_requests (const SubdirParams& params) -> download::MultiRequest;
243
+
244
+ template <typename First, typename End>
245
+ static auto build_all_index_requests (First subdirs_first, End subdirs_last)
246
+ -> download::MultiRequest;
247
+ auto build_index_request () -> download::Request;
248
+
249
+ [[nodiscard]] static auto download_requests (
250
+ download::MultiRequest index_requests,
251
+ const specs::AuthenticationDataBase& auth_info,
252
+ const download::mirror_map& mirrors,
253
+ const download::Options& download_options,
254
+ const download::RemoteFetchParams& remote_fetch_params,
255
+ download::Monitor* download_monitor
256
+ ) -> expected_t<void>;
218
257
};
219
258
220
259
/* *
@@ -243,5 +282,112 @@ namespace mamba
243
282
*/
244
283
auto create_cache_dir (const fs::u8path& cache_path) -> std::string;
245
284
285
+ /* *********************************
286
+ * Implementation of Subdirdata *
287
+ **********************************/
288
+
289
+ template <typename SubdirIter1, typename SubdirIter2>
290
+ auto SubdirData::download_required_indexes (
291
+ SubdirIter1 subdirs_first,
292
+ SubdirIter2 subdirs_last,
293
+ const SubdirParams& subdir_params,
294
+ const specs::AuthenticationDataBase& auth_info,
295
+ const download::mirror_map& mirrors,
296
+ const download::Options& download_options,
297
+ const download::RemoteFetchParams& remote_fetch_params,
298
+ download::Monitor* check_monitor,
299
+ download::Monitor* download_monitor
300
+ ) -> expected_t<void>
301
+ {
302
+ auto result = download_requests (
303
+ build_all_check_requests (subdirs_first, subdirs_last, subdir_params),
304
+ auth_info,
305
+ mirrors,
306
+ download_options,
307
+ remote_fetch_params,
308
+ check_monitor
309
+ );
310
+
311
+ // Allow to continue if failed checks, unless asked to stop.
312
+ constexpr auto is_interrupted = [](const auto & e)
313
+ { return e.error_code () == mamba_error_code::user_interrupted; };
314
+ if (!result.has_value () && result.map_error (is_interrupted).error ())
315
+ {
316
+ return result;
317
+ }
318
+
319
+ // TODO load local channels even when offline if (!ctx.offline)
320
+ if (subdir_params.offline )
321
+ {
322
+ return expected_t <void >();
323
+ }
324
+
325
+ return download_requests (
326
+ build_all_index_requests (subdirs_first, subdirs_last),
327
+ auth_info,
328
+ mirrors,
329
+ download_options,
330
+ remote_fetch_params,
331
+ download_monitor
332
+ );
333
+ }
334
+
335
+ template <typename Subdirs>
336
+ auto SubdirData::download_required_indexes (
337
+ Subdirs& subdirs,
338
+ const SubdirParams& subdir_params,
339
+ const specs::AuthenticationDataBase& auth_info,
340
+ const download::mirror_map& mirrors,
341
+ const download::Options& download_options,
342
+ const download::RemoteFetchParams& remote_fetch_params,
343
+ download::Monitor* check_monitor,
344
+ download::Monitor* download_monitor
345
+ ) -> expected_t<void>
346
+ {
347
+ return download_required_indexes (
348
+ subdirs.begin (),
349
+ subdirs.end (),
350
+ subdir_params,
351
+ auth_info,
352
+ mirrors,
353
+ download_options,
354
+ remote_fetch_params,
355
+ check_monitor,
356
+ download_monitor
357
+ );
358
+ }
359
+
360
+ template <typename First, typename End>
361
+ auto
362
+ SubdirData::build_all_check_requests (First subdirs_first, End subdirs_last, const SubdirParams& params)
363
+ -> download::MultiRequest
364
+ {
365
+ download::MultiRequest requests;
366
+ for (; subdirs_first != subdirs_last; ++subdirs_first)
367
+ {
368
+ if (!subdirs_first->valid_cache_found ())
369
+ {
370
+ auto check_list = subdirs_first->build_check_requests (params);
371
+ std::move (check_list.begin (), check_list.end (), std::back_inserter (requests));
372
+ }
373
+ }
374
+ return requests;
375
+ }
376
+
377
+ template <typename First, typename End>
378
+ auto SubdirData::build_all_index_requests (First subdirs_first, End subdirs_last)
379
+ -> download::MultiRequest
380
+ {
381
+ download::MultiRequest requests;
382
+ for (; subdirs_first != subdirs_last; ++subdirs_first)
383
+ {
384
+ if (!subdirs_first->valid_cache_found ())
385
+ {
386
+ requests.push_back (subdirs_first->build_index_request ());
387
+ }
388
+ }
389
+ return requests;
390
+ }
391
+
246
392
}
247
393
#endif
0 commit comments