6
6
#![ warn( missing_docs) ]
7
7
#![ warn( clippy:: missing_docs_in_private_items) ]
8
8
9
+ use crate :: config:: cache:: get_bin_cache;
9
10
use crate :: config:: dfinity:: ReplicaSubnetType ;
10
11
use crate :: lib:: environment:: Environment ;
11
12
use crate :: lib:: identity:: identity_utils:: CallSender ;
@@ -74,7 +75,7 @@ pub async fn install_nns(
74
75
eprintln ! ( "Installing the core backend wasm canisters..." ) ;
75
76
download_nns_wasms ( env) . await ?;
76
77
let ic_nns_init_opts = IcNnsInitOpts {
77
- wasm_dir : nns_wasm_dir ( env) ,
78
+ wasm_dir : nns_wasm_dir ( env) ? ,
78
79
nns_url : nns_url. to_string ( ) ,
79
80
test_accounts : vec ! [
80
81
canisters:: ED25519_TEST_ACCOUNT . to_string( ) ,
@@ -95,7 +96,7 @@ pub async fn install_nns(
95
96
canister_id,
96
97
} in NNS_FRONTEND
97
98
{
98
- let local_wasm_path = nns_wasm_dir ( env) . join ( wasm_name) ;
99
+ let local_wasm_path = nns_wasm_dir ( env) ? . join ( wasm_name) ;
99
100
let parsed_wasm_url = Url :: parse ( wasm_url)
100
101
. with_context ( || format ! ( "Could not parse url for {canister_name} wasm: {wasm_url}" ) ) ?;
101
102
download ( & parsed_wasm_url, & local_wasm_path) . await ?;
@@ -326,6 +327,15 @@ pub fn verify_local_replica_type_is_system(env: &dyn Environment) -> anyhow::Res
326
327
/// Downloads a file
327
328
#[ context( "Failed to download '{:?}' to '{:?}'." , source, target) ]
328
329
pub async fn download ( source : & Url , target : & Path ) -> anyhow:: Result < ( ) > {
330
+ if target. exists ( ) {
331
+ println ! ( "Already downloaded: {}" , target. to_string_lossy( ) ) ;
332
+ return Ok ( ( ) ) ;
333
+ }
334
+ println ! (
335
+ "Downloading {}\n from: {}" ,
336
+ target. to_string_lossy( ) ,
337
+ source. as_str( )
338
+ ) ;
329
339
let buffer = reqwest:: get ( source. clone ( ) )
330
340
. await
331
341
. with_context ( || "Failed to connect" ) ?
@@ -358,6 +368,15 @@ pub async fn download(source: &Url, target: &Path) -> anyhow::Result<()> {
358
368
/// Downloads and unzips a file
359
369
#[ context( "Failed to download and unzip '{:?}' from '{:?}'." , target, source. as_str( ) ) ]
360
370
pub async fn download_gz ( source : & Url , target : & Path ) -> anyhow:: Result < ( ) > {
371
+ if target. exists ( ) {
372
+ println ! ( "Already downloaded: {}" , target. to_string_lossy( ) ) ;
373
+ return Ok ( ( ) ) ;
374
+ }
375
+ println ! (
376
+ "Downloading {}\n from .gz: {}" ,
377
+ target. to_string_lossy( ) ,
378
+ source. as_str( )
379
+ ) ;
361
380
let response = reqwest:: get ( source. clone ( ) )
362
381
. await
363
382
. with_context ( || "Failed to connect" ) ?
@@ -403,27 +422,18 @@ pub async fn download_ic_repo_wasm(
403
422
fs:: create_dir_all ( wasm_dir)
404
423
. with_context ( || format ! ( "Failed to create wasm directory: '{}'" , wasm_dir. display( ) ) ) ?;
405
424
let final_path = wasm_dir. join ( & wasm_name) ;
406
- if final_path. exists ( ) {
407
- return Ok ( ( ) ) ;
408
- }
409
-
410
425
let url_str =
411
426
format ! ( "https://download.dfinity.systems/ic/{ic_commit}/canisters/{wasm_name}.gz" ) ;
412
427
let url = Url :: parse ( & url_str)
413
428
. with_context ( || format ! ( "Could not determine download URL. Are ic_commit '{ic_commit}' and wasm_name '{wasm_name}' valid?" ) ) ?;
414
- println ! (
415
- "Downloading {}\n from {}" ,
416
- final_path. to_string_lossy( ) ,
417
- url_str
418
- ) ;
419
429
download_gz ( & url, & final_path) . await
420
430
}
421
431
422
432
/// Downloads all the core NNS wasms, excluding only the front-end wasms II and NNS-dapp.
423
433
#[ context( "Failed to download NNS wasm files." ) ]
424
434
pub async fn download_nns_wasms ( env : & dyn Environment ) -> anyhow:: Result < ( ) > {
425
435
let ic_commit = std:: env:: var ( "DFX_IC_COMMIT" ) . unwrap_or_else ( |_| replica_rev ( ) . to_string ( ) ) ;
426
- let wasm_dir = & nns_wasm_dir ( env) ;
436
+ let wasm_dir = & nns_wasm_dir ( env) ? ;
427
437
for IcNnsInitCanister {
428
438
wasm_name,
429
439
test_wasm_name,
@@ -570,7 +580,7 @@ pub fn upload_nns_sns_wasms_canister_wasms(env: &dyn Environment) -> anyhow::Res
570
580
} in SNS_CANISTERS
571
581
{
572
582
let sns_cli = bundled_binary ( env, "sns" ) ?;
573
- let wasm_path = nns_wasm_dir ( env) . join ( wasm_name) ;
583
+ let wasm_path = nns_wasm_dir ( env) ? . join ( wasm_name) ;
574
584
let mut command = Command :: new ( sns_cli) ;
575
585
command
576
586
. arg ( "add-sns-wasm-for-tests" )
@@ -656,8 +666,8 @@ pub async fn install_canister(
656
666
}
657
667
658
668
/// The local directory where NNS wasm files are cached. The directory is typically created on demand.
659
- fn nns_wasm_dir ( env : & dyn Environment ) -> PathBuf {
660
- Path :: new ( & format ! ( ".dfx/wasms/nns/dfx-{}/" , env. get_version( ) ) ) . to_path_buf ( )
669
+ fn nns_wasm_dir ( env : & dyn Environment ) -> anyhow :: Result < PathBuf > {
670
+ Ok ( get_bin_cache ( & env. get_version ( ) . to_string ( ) ) ? . join ( "wasms" ) )
661
671
}
662
672
663
673
/// Get the path to a bundled command line binary
0 commit comments