From b9eee66f942475e659a686549927031ad4101357 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 2 Nov 2021 15:41:06 -0700 Subject: [PATCH] Add cargo-build-bpf logic to recover from failed package downloads (#21138) --- sdk/cargo-build-bpf/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdk/cargo-build-bpf/src/main.rs b/sdk/cargo-build-bpf/src/main.rs index f487bff514..927db40f15 100644 --- a/sdk/cargo-build-bpf/src/main.rs +++ b/sdk/cargo-build-bpf/src/main.rs @@ -132,6 +132,20 @@ fn install_if_missing( .join(version) .join(package); + // Check whether the target path is an empty directory. This can + // happen if package download failed on previous run of + // cargo-build-bpf. Remove the target_path directory in this + // case. + if target_path.is_dir() + && target_path + .read_dir() + .map_err(|err| err.to_string())? + .next() + .is_none() + { + fs::remove_dir(&target_path).map_err(|err| err.to_string())?; + } + if !target_path.is_dir() && !target_path .symlink_metadata()