Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unused folders after download contracts node binary #240

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/pop-contracts/src/utils/contracts_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use flate2::read::GzDecoder;
use pop_common::GitHub;
use std::{
env::consts::OS,
fs,
io::{Seek, SeekFrom, Write},
path::PathBuf,
process::{Child, Command},
Expand Down Expand Up @@ -45,7 +46,7 @@ pub async fn is_chain_alive(url: url::Url) -> Result<bool, Error> {
/// * `cache` - The path where the binary will be stored.
///
pub async fn run_contracts_node(cache: PathBuf) -> Result<Child, Error> {
let cached_file = cache.join(release_folder_by_target()?).join(BIN_NAME);
let cached_file = cache.join(BIN_NAME);
if !cached_file.exists() {
let archive = archive_name_by_target()?;

Expand All @@ -61,6 +62,10 @@ pub async fn run_contracts_node(cache: PathBuf) -> Result<Child, Error> {
let tar = GzDecoder::new(file);
let mut archive = Archive::new(tar);
archive.unpack(cache.clone())?;
// Copy the file into the cache folder and remove the folder artifacts
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
let extracted_dir = cache.join(release_folder_by_target()?);
fs::copy(&extracted_dir.join(BIN_NAME), &cached_file)?;
fs::remove_dir_all(&extracted_dir.parent().unwrap_or(&cache.join("artifacts")))?;
}
let process = Command::new(cached_file.display().to_string().as_str()).spawn()?;

Expand Down Expand Up @@ -155,9 +160,11 @@ mod tests {
// Run the contracts node
let temp_dir = tempfile::tempdir().expect("Could not create temp dir");
let cache = temp_dir.path().join("cache");
let mut process = run_contracts_node(cache).await?;
let mut process = run_contracts_node(cache.clone()).await?;
// Check if the node is alive
assert!(is_chain_alive(local_url).await?);
assert!(cache.join("substrate-contracts-node").exists());
assert!(!cache.join("artifacts").exists());
process.kill()?;
Ok(())
}
Expand Down
Loading