fn update_deposition_files(
    host: impl AsRef<str>,
    token: impl AsRef<str>,
    deposition_id: &u64,
    deposition_files: Vec<DepositionFile>,
    config_files: Vec<ConfigFile>,
) -> Result<()> {
    let deposition_files_map: HashMap<String, DepositionFile> = deposition_files
        .into_iter()
        .map(|f| (f.filename.clone(), f))
        .collect();
    let config_files_map: HashMap<String, ConfigFile> = config_files
        .into_iter()
        .map(|f| (f.filename.clone(), f))
        .collect();

    for (filename, deposition_file) in deposition_files_map.iter() {
        match config_files_map.get(filename) {
            Some(config_file) => {
                if deposition_file.checksum == config_file.checksum {
                    // do nothing
                    continue;
                } else {
                    // delete and create
                    delete_deposition_file(&host, &token, deposition_id, &deposition_file.id)?;
                    create_deposition_file(
                        &host,
                        &token,
                        deposition_id,
                        &config_file.filename,
                        &config_file.file_path,
                    )?;
                }
            }
            None => {
                // delete
                delete_deposition_file(&host, &token, deposition_id, &deposition_file.id)?;
            }
        }
    }
    for (filename, config_file) in config_files_map.iter() {
        match deposition_files_map.get(filename) {
            Some(_) => {
                // do nothing (already done)
                continue;
            }
            None => {
                // create
                create_deposition_file(
                    &host,
                    &token,
                    deposition_id,
                    &config_file.filename,
                    &config_file.file_path,
                )?;
            }
        }
    }
    Ok(())
}
/// in deposition_files, in config_files
///   - checksum is the same: do nothing
///   - checksum is not the same: delete and create
/// in deposition_files, not in config_files: delete
/// not in deposition_files, in config_files: create
in deposition_files, in config_files
checksum is the same: do nothing
checksum is not the same: delete and create
in deposition_files, not in config_files: delete
not in deposition_files, in config_files: create
in deposition_files in config_files checksum is the same : do nothing checksum is not the same : delete and create in deposition_files not in config_files : delete not in deposition_files in config_files : create
fn update_deposition_files(
    host: impl AsRef<str>,
    token: impl AsRef<str>,
    deposition_id: &u64,
    deposition_files: Vec<DepositionFile>,
    config_files: Vec<ConfigFile>,
) -> Result<()> {
    let deposition_files_map: HashMap<String, DepositionFile> = deposition_files
        .into_iter()
        .map(|f| (f.filename.clone(), f))
        .collect();
    let config_files_map: HashMap<String, ConfigFile> = config_files
        .into_iter()
        .map(|f| (f.filename.clone(), f))
        .collect();
    for (filename, deposition_file) in deposition_files_map.iter() {
        match config_files_map.get(filename) {
            Some(config_file) => {
                if deposition_file.checksum == config_file.checksum {
                    // do nothing
                    continue;
                } else {
                    // delete and create
                    delete_deposition_file(&host, &token, deposition_id, &deposition_file.id)?;
                    create_deposition_file(
                        &host,
                        &token,
                        deposition_id,
                        &config_file.filename,
                        &config_file.file_path,
                    )?;
                }
            }
            None => {
                // delete
                delete_deposition_file(&host, &token, deposition_id, &deposition_file.id)?;
            }
        }
    }
    for (filename, config_file) in config_files_map.iter() {
        match deposition_files_map.get(filename) {
            Some(_) => {
                // do nothing (already done)
                continue;
            }
            None => {
                // create
                create_deposition_file(
                    &host,
                    &token,
                    deposition_id,
                    &config_file.filename,
                    &config_file.file_path,
                )?;
            }
        }
    }
    Ok(())
}
fn update_deposition_files ( host : impl AsRef < str > , token : impl AsRef < str > , deposition_id : & u64 , deposition_files : Vec < DepositionFile > , config_files : Vec < ConfigFile > , ) -> Result < ( ) > { let deposition_files_map : HashMap < String , DepositionFile > = deposition_files . into_iter ( ) . map ( | f | ( f . filename . clone ( ) , f ) ) . collect ( ) ; let config_files_map : HashMap < String , ConfigFile > = config_files . into_iter ( ) . map ( | f | ( f . filename . clone ( ) , f ) ) . collect ( ) ; for ( filename , deposition_file ) in deposition_files_map . iter ( ) { match config_files_map . get ( filename ) { Some ( config_file ) => { if deposition_file . checksum == config_file . checksum { // do nothing continue ; } else { // delete and create delete_deposition_file ( & host , & token , deposition_id , & deposition_file . id ) ? ; create_deposition_file ( & host , & token , deposition_id , & config_file . filename , & config_file . file_path , ) ? ; } } None => { // delete delete_deposition_file ( & host , & token , deposition_id , & deposition_file . id ) ? ; } } } for ( filename , config_file ) in config_files_map . iter ( ) { match deposition_files_map . get ( filename ) { Some ( _ ) => { // do nothing (already done) continue ; } None => { // create create_deposition_file ( & host , & token , deposition_id , & config_file . filename , & config_file . file_path , ) ? ; } } } Ok ( ( ) ) }
in deposition_files, in config_files
 checksum is the same: do nothing
 checksum is not the same: delete and create
in deposition_files, not in config_files: delete
not in deposition_files, in config_files: create
in deposition_files in config_files checksum is the same : do nothing checksum is not the same : delete and create in deposition_files not in config_files : delete not in deposition_files in config_files : create
host
impl AsRef<str>
token
impl AsRef<str>
deposition_id
&u64
deposition_files
Vec<DepositionFile>
config_files
Vec<ConfigFile>
host
impl AsRef<str>
token
impl AsRef<str>
deposition_id
&u64
deposition_files
Vec<DepositionFile>
config_files
Vec<ConfigFile>