From 7d56c3484cc86ade78c7e898651968d95a05549a Mon Sep 17 00:00:00 2001 From: Yihau Chen Date: Mon, 23 Oct 2023 22:14:34 +0800 Subject: [PATCH] test: check the existence of target_path_parent before detelting (#33812) --- sdk/cargo-build-sbf/src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sdk/cargo-build-sbf/src/main.rs b/sdk/cargo-build-sbf/src/main.rs index e123680fc3..79a4a1378e 100644 --- a/sdk/cargo-build-sbf/src/main.rs +++ b/sdk/cargo-build-sbf/src/main.rs @@ -626,14 +626,16 @@ fn build_solana_package( // The package version directory doesn't contain a valid // installation, and it should be removed. let target_path_parent = target_path.parent().expect("Invalid package path"); - fs::remove_dir_all(target_path_parent).unwrap_or_else(|err| { - error!( - "Failed to remove {} while recovering from installation failure: {}", - target_path_parent.to_string_lossy(), - err, - ); - exit(1); - }); + if target_path_parent.exists() { + fs::remove_dir_all(target_path_parent).unwrap_or_else(|err| { + error!( + "Failed to remove {} while recovering from installation failure: {}", + target_path_parent.to_string_lossy(), + err, + ); + exit(1); + }); + } error!("Failed to install platform-tools: {}", err); exit(1); });