From 893eee1558d1775d9e2140fc758f11b0d3a54988 Mon Sep 17 00:00:00 2001 From: Sourav Bansal Date: Sun, 11 Sep 2022 22:34:41 +0530 Subject: [PATCH] Update resource_download.rs --- src/utils/src/resource_download.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils/src/resource_download.rs b/src/utils/src/resource_download.rs index 25171ef..6b35522 100644 --- a/src/utils/src/resource_download.rs +++ b/src/utils/src/resource_download.rs @@ -13,11 +13,19 @@ pub enum Error { /// - `r_type`: the resource type; e.g. "kernel", "disk". /// - `r_tags`: optional tags to filter the resources; e.g. "{\"halt-after-boot\": true}" pub fn s3_download(r_type: &str, r_tags: Option<&str>) -> Result { + // The function downloads the resource from S3 which matched the paramaters. The first parameter of type string contains the resource + // type. The second parameter is optional and contains additional parameters for filtering. + + // dld_script is the command sent to the function in the file + // format used for interpolation to create a string command let dld_script = format!( "{}/../../tests/tools/s3_download.py", env!("CARGO_MANIFEST_DIR") ); + // command spawns a new process which runs the python script for downloading the resource from S3 + // dld_script along with args are used for configuring the process + // the python script is available at ../../tests/tools/s3_download.py let output = Command::new(dld_script.as_str()) .arg("-t") .arg(r_type) @@ -26,13 +34,15 @@ pub fn s3_download(r_type: &str, r_tags: Option<&str>) -> Result .arg("-1") .output() .expect("failed to execute process"); - + + // if the code returns some error, the rust returns the same error if !output.status.success() { return Err(Error::DownloadError( String::from_utf8(output.stderr).unwrap(), )); } - + + // else the script returns the path to the downloaded resource let res: String = String::from_utf8(output.stdout) .unwrap() .split('\n')