fn assign_ids_across_directory(
    collection_str: String,
    repo_path: &Path,
    highest_ids: &mut Map<u32, u32>,
    output_mode: OutputMode,
    assignments: &mut Vec<String>,
) {
    let dir_path = repo_path.join(collection_str);

    if let Ok(collection_entry) = fs::read_dir(dir_path) {
        for dir_entry in collection_entry {
            let unwrapped_dir_entry = dir_entry.unwrap();
            let dir_name = unwrapped_dir_entry.file_name().into_string().unwrap();
            let dir_path = unwrapped_dir_entry.path();
            let dir_path_clone = dir_path.clone();
            for advisory_entry in fs::read_dir(dir_path).unwrap() {
                let unwrapped_advisory = advisory_entry.unwrap();
                let advisory_path = unwrapped_advisory.path();
                let advisory_path_clone = advisory_path.clone();
                let advisory_path_for_reading = advisory_path.clone();
                let advisory_path_for_deleting = advisory_path.clone();
                let displayed_advisory_path = advisory_path.display();
                let advisory_filename = unwrapped_advisory.file_name();
                let advisory_filename_str = advisory_filename.into_string().unwrap();
                if advisory_filename_str.contains("RUSTSEC-0000-0000") {
                    let advisory_data = fs::read_to_string(advisory_path_clone)
                        .map_err(|e| {
                            format_err!(
                                ErrorKind::Io,
                                "Couldn't open {}: {}",
                                displayed_advisory_path,
                                e
                            );
                        })
                        .unwrap();

                    let advisory_parts = Parts::parse(&advisory_data).unwrap();
                    let advisory: Advisory = toml::from_str(&advisory_parts.front_matter).unwrap();
                    let date = advisory.metadata.date;
                    let year = date.year();
                    let new_id = highest_ids.get(&year).cloned().unwrap_or_default() + 1;
                    let year_str = year.to_string();
                    let string_id = format!("RUSTSEC-{}-{:04}", year_str, new_id);
                    let new_filename = format!("{}.md", string_id);
                    let new_path = dir_path_clone.join(new_filename);
                    let original_file = File::open(advisory_path_for_reading).unwrap();
                    let reader = BufReader::new(original_file);
                    let new_file = File::create(new_path).unwrap();
                    let mut writer = LineWriter::new(new_file);
                    for line in reader.lines() {
                        let current_line = line.unwrap();
                        if current_line.contains("id = ") {
                            writer
                                .write_all(format!("id = \"{}\"\n", string_id).as_ref())
                                .unwrap();
                        } else {
                            let current_line_with_newline = format!("{}\n", current_line);
                            writer
                                .write_all(current_line_with_newline.as_ref())
                                .unwrap();
                        }
                    }
                    highest_ids.insert(year, new_id);
                    fs::remove_file(advisory_path_for_deleting).unwrap();
                    if output_mode == OutputMode::HumanReadable {
                        status_ok!("Assignment", "Assigned {} to {}", string_id, dir_name);
                    } else {
                        assignments.push(format!("{} to {}", string_id, dir_name))
                    }
                }
            }
        }
    }
}
///Assign ids to files with placeholder IDs within the directory defined by dir_path
Assign ids to files with placeholder IDs within the directory defined by dir_path
Assign ids to files with placeholder IDs within the directory defined by dir_path
fn assign_ids_across_directory(
    collection_str: String,
    repo_path: &Path,
    highest_ids: &mut Map<u32, u32>,
    output_mode: OutputMode,
    assignments: &mut Vec<String>,
) {
    let dir_path = repo_path.join(collection_str);
    if let Ok(collection_entry) = fs::read_dir(dir_path) {
        for dir_entry in collection_entry {
            let unwrapped_dir_entry = dir_entry.unwrap();
            let dir_name = unwrapped_dir_entry.file_name().into_string().unwrap();
            let dir_path = unwrapped_dir_entry.path();
            let dir_path_clone = dir_path.clone();
            for advisory_entry in fs::read_dir(dir_path).unwrap() {
                let unwrapped_advisory = advisory_entry.unwrap();
                let advisory_path = unwrapped_advisory.path();
                let advisory_path_clone = advisory_path.clone();
                let advisory_path_for_reading = advisory_path.clone();
                let advisory_path_for_deleting = advisory_path.clone();
                let displayed_advisory_path = advisory_path.display();
                let advisory_filename = unwrapped_advisory.file_name();
                let advisory_filename_str = advisory_filename.into_string().unwrap();
                if advisory_filename_str.contains("RUSTSEC-0000-0000") {
                    let advisory_data = fs::read_to_string(advisory_path_clone)
                        .map_err(|e| {
                            format_err!(
                                ErrorKind::Io,
                                "Couldn't open {}: {}",
                                displayed_advisory_path,
                                e
                            );
                        })
                        .unwrap();
                    let advisory_parts = Parts::parse(&advisory_data).unwrap();
                    let advisory: Advisory = toml::from_str(&advisory_parts.front_matter).unwrap();
                    let date = advisory.metadata.date;
                    let year = date.year();
                    let new_id = highest_ids.get(&year).cloned().unwrap_or_default() + 1;
                    let year_str = year.to_string();
                    let string_id = format!("RUSTSEC-{}-{:04}", year_str, new_id);
                    let new_filename = format!("{}.md", string_id);
                    let new_path = dir_path_clone.join(new_filename);
                    let original_file = File::open(advisory_path_for_reading).unwrap();
                    let reader = BufReader::new(original_file);
                    let new_file = File::create(new_path).unwrap();
                    let mut writer = LineWriter::new(new_file);
                    for line in reader.lines() {
                        let current_line = line.unwrap();
                        if current_line.contains("id = ") {
                            writer
                                .write_all(format!("id = \"{}\"\n", string_id).as_ref())
                                .unwrap();
                        } else {
                            let current_line_with_newline = format!("{}\n", current_line);
                            writer
                                .write_all(current_line_with_newline.as_ref())
                                .unwrap();
                        }
                    }
                    highest_ids.insert(year, new_id);
                    fs::remove_file(advisory_path_for_deleting).unwrap();
                    if output_mode == OutputMode::HumanReadable {
                        status_ok!("Assignment", "Assigned {} to {}", string_id, dir_name);
                    } else {
                        assignments.push(format!("{} to {}", string_id, dir_name))
                    }
                }
            }
        }
    }
}
fn assign_ids_across_directory ( collection_str : String , repo_path : & Path , highest_ids : & mut Map < u32 , u32 > , output_mode : OutputMode , assignments : & mut Vec < String > , ) { let dir_path = repo_path . join ( collection_str ) ; if let Ok ( collection_entry ) = fs :: read_dir ( dir_path ) { for dir_entry in collection_entry { let unwrapped_dir_entry = dir_entry . unwrap ( ) ; let dir_name = unwrapped_dir_entry . file_name ( ) . into_string ( ) . unwrap ( ) ; let dir_path = unwrapped_dir_entry . path ( ) ; let dir_path_clone = dir_path . clone ( ) ; for advisory_entry in fs :: read_dir ( dir_path ) . unwrap ( ) { let unwrapped_advisory = advisory_entry . unwrap ( ) ; let advisory_path = unwrapped_advisory . path ( ) ; let advisory_path_clone = advisory_path . clone ( ) ; let advisory_path_for_reading = advisory_path . clone ( ) ; let advisory_path_for_deleting = advisory_path . clone ( ) ; let displayed_advisory_path = advisory_path . display ( ) ; let advisory_filename = unwrapped_advisory . file_name ( ) ; let advisory_filename_str = advisory_filename . into_string ( ) . unwrap ( ) ; if advisory_filename_str . contains ( " " ) { let advisory_data = fs :: read_to_string ( advisory_path_clone ) . map_err ( | e | { format_err ! ( ErrorKind Io " " displayed_advisory_path e ) ; } ) . unwrap ( ) ; let advisory_parts = Parts :: parse ( & advisory_data ) . unwrap ( ) ; let advisory : Advisory = toml :: from_str ( & advisory_parts . front_matter ) . unwrap ( ) ; let date = advisory . metadata . date ; let year = date . year ( ) ; let new_id = highest_ids . get ( & year ) . cloned ( ) . unwrap_or_default ( ) + 1 ; let year_str = year . to_string ( ) ; let string_id = format ! ( " " year_str new_id ) ; let new_filename = format ! ( " " string_id ) ; let new_path = dir_path_clone . join ( new_filename ) ; let original_file = File :: open ( advisory_path_for_reading ) . unwrap ( ) ; let reader = BufReader :: new ( original_file ) ; let new_file = File :: create ( new_path ) . unwrap ( ) ; let mut writer = LineWriter :: new ( new_file ) ; for line in reader . lines ( ) { let current_line = line . unwrap ( ) ; if current_line . contains ( " " ) { writer . write_all ( format ! ( " \" \" \n " string_id ) . as_ref ( ) ) . unwrap ( ) ; } else { let current_line_with_newline = format ! ( " \n " current_line ) ; writer . write_all ( current_line_with_newline . as_ref ( ) ) . unwrap ( ) ; } } highest_ids . insert ( year , new_id ) ; fs :: remove_file ( advisory_path_for_deleting ) . unwrap ( ) ; if output_mode == OutputMode :: HumanReadable { status_ok ! ( " " " " string_id dir_name ) ; } else { assignments . push ( format ! ( " " string_id dir_name ) ) } } } } } }
Assign ids to files with placeholder IDs within the directory defined by dir_path
Assign ids to files with placeholder IDs within the directory defined by dir_path
collection_str
String
repo_path
&Path
highest_ids
&mut Map<u32, u32>
output_mode
OutputMode
assignments
&mut Vec<String>
collection_str
String
repo_path
&Path
highest_ids
&mut Map<u32, u32>
output_mode
OutputMode
assignments
&mut Vec<String>