diff --git a/src/utils/af_utils.rs b/src/utils/af_utils.rs index 4d6ec59..d4c0b54 100644 --- a/src/utils/af_utils.rs +++ b/src/utils/af_utils.rs @@ -167,12 +167,35 @@ pub fn add_chemistry_to_args_piscem(chem_str: &str, cmd: &mut std::process::Comm } pub fn get_permit_if_absent(af_home: &Path, chem: &Chemistry) -> Result { + // check if the file already exists + let odir = af_home.join("plist"); + match chem { + Chemistry::TenxV2 => { + let chem_file = "10x_v2_permit.txt"; + if odir.join(chem_file).exists() { + return Ok(PermitListResult::AlreadyPresent(odir.join(chem_file))); + } + } + Chemistry::TenxV3 => { + let chem_file = "10x_v3_permit.txt"; + if odir.join(chem_file).exists() { + return Ok(PermitListResult::AlreadyPresent(odir.join(chem_file))); + } + } + _ => { + return Ok(PermitListResult::UnregisteredChemistry); + } + } + + // the file doesn't exist, so get the json file that gives us + // the chemistry name to permit list URL mapping. let permit_dict_url = "https://raw.githubusercontent.com/COMBINE-lab/simpleaf/dev/resources/permit_list_info.json"; let permit_dict: serde_json::Value = minreq::get(permit_dict_url) .send()? .json::()?; let opt_chem_file: Option; let opt_dl_url: Option; + // parse the JSON appropriately based on the chemistry we have match chem { Chemistry::TenxV2 => { if let Some(d) = permit_dict.get("10xv2") { @@ -219,8 +242,8 @@ pub fn get_permit_if_absent(af_home: &Path, chem: &Chemistry) -> Result>(cmd: S) -> Command { pub fn download_to_file>(url: T, filename: &str) -> Result<()> { let url = url.as_ref(); + + debug!( + "Downloading file from {} and writing to file {}", + url, filename + ); + let request = minreq::get(url).with_timeout(120).send()?; match request.status_code { 200..=299 => { // success + debug!( + "Obtained status code {} from final url {}", + request.status_code, request.url + ); } x => { bail!(