pub fn delete_review_proofs(crate_name: &str, crate_version: &str) -> anyhow::Result<()> {
    // open every *.proof.crev file in my crev reviews directory
    for path in proof_crev_files_paths()?.iter() {
        let mut file_content = std::fs::read_to_string(path)?;
        let mut pos_cursor = 0;
        let mut vec_range: Vec<Range<usize>> = vec![];
        loop {
            let range = find_range_including_delimiters(&file_content, &mut pos_cursor, "----- BEGIN CREV PROOF -----", "----- END CREV PROOF -----");
            match range {
                Some(mut range) => {
                    // if there is some white space after the segment, include it in the range.
                    let pos_2 = find_pos_before_delimiter(&file_content, pos_cursor, "----- BEGIN CREV PROOF -----");
                    range.end = match pos_2 {
                        Some(pos_2) => pos_2,
                        None => file_content.len(),
                    };

                    let proof_text = unwrap!(file_content.get(range.clone()));
                    // This must not panic because it is internal to the previous range.
                    let range_yaml = unwrap!(find_range_between_delimiters(
                        proof_text,
                        &mut 0,
                        "----- BEGIN CREV PROOF -----",
                        "----- SIGN CREV PROOF -----",
                    ));
                    // if this panics it's a bug in the code and not an exception to handle
                    let yaml = unwrap!(proof_text.get(range_yaml));
                    let proof_crev: ProofCrevForReview = unwrap!(serde_yaml::from_str(yaml));
                    // I will remove only if it has the review segment.
                    if proof_crev.review.is_some() && proof_crev.package.name == crate_name && proof_crev.package.version == crate_version {
                        vec_range.push(range.clone());
                    }
                }
                None => break,
            }
        }
        if !vec_range.is_empty() {
            // remove all ranges from the bottom up
            while let Some(range) = vec_range.pop() {
                file_content.drain(range);
            }
            if file_content.trim().is_empty() {
                // delete the file
                unwrap!(std::fs::remove_file(path));
            } else {
                std::fs::write(path, file_content)?;
            }
        }
    }
    Ok(())
}
/// remove old proofs, so the new review proof will be unique
remove old proofs, so the new review proof will be unique
remove old proofs so the new review proof will be unique
pub fn delete_review_proofs(crate_name: &str, crate_version: &str) -> anyhow::Result<()> {
    // open every *.proof.crev file in my crev reviews directory
    for path in proof_crev_files_paths()?.iter() {
        let mut file_content = std::fs::read_to_string(path)?;
        let mut pos_cursor = 0;
        let mut vec_range: Vec<Range<usize>> = vec![];
        loop {
            let range = find_range_including_delimiters(&file_content, &mut pos_cursor, "----- BEGIN CREV PROOF -----", "----- END CREV PROOF -----");
            match range {
                Some(mut range) => {
                    // if there is some white space after the segment, include it in the range.
                    let pos_2 = find_pos_before_delimiter(&file_content, pos_cursor, "----- BEGIN CREV PROOF -----");
                    range.end = match pos_2 {
                        Some(pos_2) => pos_2,
                        None => file_content.len(),
                    };
                    let proof_text = unwrap!(file_content.get(range.clone()));
                    // This must not panic because it is internal to the previous range.
                    let range_yaml = unwrap!(find_range_between_delimiters(
                        proof_text,
                        &mut 0,
                        "----- BEGIN CREV PROOF -----",
                        "----- SIGN CREV PROOF -----",
                    ));
                    // if this panics it's a bug in the code and not an exception to handle
                    let yaml = unwrap!(proof_text.get(range_yaml));
                    let proof_crev: ProofCrevForReview = unwrap!(serde_yaml::from_str(yaml));
                    // I will remove only if it has the review segment.
                    if proof_crev.review.is_some() && proof_crev.package.name == crate_name && proof_crev.package.version == crate_version {
                        vec_range.push(range.clone());
                    }
                }
                None => break,
            }
        }
        if !vec_range.is_empty() {
            // remove all ranges from the bottom up
            while let Some(range) = vec_range.pop() {
                file_content.drain(range);
            }
            if file_content.trim().is_empty() {
                // delete the file
                unwrap!(std::fs::remove_file(path));
            } else {
                std::fs::write(path, file_content)?;
            }
        }
    }
    Ok(())
}
pub fn delete_review_proofs ( crate_name : & str , crate_version : & str ) -> anyhow :: Result < ( ) > { // open every *.proof.crev file in my crev reviews directory for path in proof_crev_files_paths ( ) ? . iter ( ) { let mut file_content = std :: fs :: read_to_string ( path ) ? ; let mut pos_cursor = 0 ; let mut vec_range : Vec < Range < usize > > = vec ! [ ] ; loop { let range = find_range_including_delimiters ( & file_content , & mut pos_cursor , " " , " " ) ; match range { Some ( mut range ) => { // if there is some white space after the segment, include it in the range. let pos_2 = find_pos_before_delimiter ( & file_content , pos_cursor , " " ) ; range . end = match pos_2 { Some ( pos_2 ) => pos_2 , None => file_content . len ( ) , } ; let proof_text = unwrap ! ( file_content get ( range clone ( ) ) ) ; // This must not panic because it is internal to the previous range. let range_yaml = unwrap ! ( find_range_between_delimiters ( proof_text mut 0 " " " " ) ) ; // if this panics it's a bug in the code and not an exception to handle let yaml = unwrap ! ( proof_text get ( range_yaml ) ) ; let proof_crev : ProofCrevForReview = unwrap ! ( serde_yaml from_str ( yaml ) ) ; // I will remove only if it has the review segment. if proof_crev . review . is_some ( ) && proof_crev . package . name == crate_name && proof_crev . package . version == crate_version { vec_range . push ( range . clone ( ) ) ; } } None => break , } } if ! vec_range . is_empty ( ) { // remove all ranges from the bottom up while let Some ( range ) = vec_range . pop ( ) { file_content . drain ( range ) ; } if file_content . trim ( ) . is_empty ( ) { // delete the file unwrap ! ( std fs remove_file ( path ) ) ; } else { std :: fs :: write ( path , file_content ) ? ; } } } Ok ( ( ) ) }
remove old proofs, so the new review proof will be unique
remove old proofs so the new review proof will be unique
crate_name
&str
crate_version
&str