fn new(mappings_dir_path: PathBuf) -> std::io::Result<OnDiskKeyIDManager> {
        let mut key_store = HashMap::new();

        // Will ignore if the mappings directory already exists.
        fs::create_dir_all(&mappings_dir_path)?;

        for app_name_dir_path in list_dirs(&mappings_dir_path)?.iter() {
            for provider_dir_path in list_dirs(&app_name_dir_path)?.iter() {
                for key_name_file_path in list_files(&provider_dir_path)?.iter() {
                    info!("Found mapping file: {:?}.", key_name_file_path);
                    let mut key_info = Vec::new();
                    let mut key_info_file = File::open(&key_name_file_path)?;
                    let _ = key_info_file.read_to_end(&mut key_info)?;
                    let key_info = bincode::deserialize(&key_info[..]).or_else(|e| {
                        error!("Error deserializing key info ({}).", e);
                        Err(Error::new(ErrorKind::Other, "error deserializing key info"))
                    })?;
                    match base64_data_triple_to_key_triple(
                        os_str_to_u8_ref(app_name_dir_path.file_name().expect(
                            "The application name directory path should contain a final component.",
                        ))?,
                        os_str_to_provider_id(provider_dir_path.file_name().expect(
                            "The provider directory path should contain a final component.",
                        ))?,
                        os_str_to_u8_ref(key_name_file_path.file_name().expect(
                            "The key name directory path should contain a final component.",
                        ))?,
                    ) {
                        Ok(key_triple) => {
                            let _ = key_store.insert(key_triple, key_info);
                        }
                        Err(string) => {
                            error!("Failed to convert the mapping path found to an UTF-8 string (error: {}).", string);
                        }
                    }
                }
            }
        }

        Ok(OnDiskKeyIDManager {
            key_store,
            mappings_dir_path,
        })
    }
/// Creates an instance of the on-disk manager from the mapping files. This function will
/// create the mappings directory if it does not already exist.
/// The mappings folder is composed of three levels: two levels of directory and one level
/// of files. The key triple to key info mappings are represented on disk as the following:
///
/// mappings_dir_path/
/// |---app1/
/// |   |---provider1/
/// |   |   |---key1
/// |   |   |---key2
/// |   |   |   ...
/// |   |   |---keyP
/// |   |---provider2/
/// |   |   ...
/// |   |---providerM/
/// |---app2/
/// |   ...
/// |---appN/
///
/// where the path of a key name from the mappings directory is the key triple (application,
/// provider, key) and the data inside the key name file is the key info serialised in binary
/// format.
/// Each mapping is contained in its own file to prevent the modification of one mapping
/// impacting the other ones.
///
/// # Errors
///
/// Returns an std::io error if the function failed reading the mapping files.
Creates an instance of the on-disk manager from the mapping files. This function will
create the mappings directory if it does not already exist.
The mappings folder is composed of three levels: two levels of directory and one level
of files. The key triple to key info mappings are represented on disk as the following.




Creates an instance of the on - disk manager from the mapping files . This function will create the mappings directory if it does not already exist . The mappings folder is composed of three levels : two levels of directory and one level of files . The key triple to key info mappings are represented on disk as the following .
fn new(mappings_dir_path: PathBuf) -> std::io::Result<OnDiskKeyIDManager> {
        let mut key_store = HashMap::new();
        // Will ignore if the mappings directory already exists.
        fs::create_dir_all(&mappings_dir_path)?;
        for app_name_dir_path in list_dirs(&mappings_dir_path)?.iter() {
            for provider_dir_path in list_dirs(&app_name_dir_path)?.iter() {
                for key_name_file_path in list_files(&provider_dir_path)?.iter() {
                    info!("Found mapping file: {:?}.", key_name_file_path);
                    let mut key_info = Vec::new();
                    let mut key_info_file = File::open(&key_name_file_path)?;
                    let _ = key_info_file.read_to_end(&mut key_info)?;
                    let key_info = bincode::deserialize(&key_info[..]).or_else(|e| {
                        error!("Error deserializing key info ({}).", e);
                        Err(Error::new(ErrorKind::Other, "error deserializing key info"))
                    })?;
                    match base64_data_triple_to_key_triple(
                        os_str_to_u8_ref(app_name_dir_path.file_name().expect(
                            "The application name directory path should contain a final component.",
                        ))?,
                        os_str_to_provider_id(provider_dir_path.file_name().expect(
                            "The provider directory path should contain a final component.",
                        ))?,
                        os_str_to_u8_ref(key_name_file_path.file_name().expect(
                            "The key name directory path should contain a final component.",
                        ))?,
                    ) {
                        Ok(key_triple) => {
                            let _ = key_store.insert(key_triple, key_info);
                        }
                        Err(string) => {
                            error!("Failed to convert the mapping path found to an UTF-8 string (error: {}).", string);
                        }
                    }
                }
            }
        }
        Ok(OnDiskKeyIDManager {
            key_store,
            mappings_dir_path,
        })
    }
fn new ( mappings_dir_path : PathBuf ) -> std :: io :: Result < OnDiskKeyIDManager > { let mut key_store = HashMap :: new ( ) ; // Will ignore if the mappings directory already exists. fs :: create_dir_all ( & mappings_dir_path ) ? ; for app_name_dir_path in list_dirs ( & mappings_dir_path ) ? . iter ( ) { for provider_dir_path in list_dirs ( & app_name_dir_path ) ? . iter ( ) { for key_name_file_path in list_files ( & provider_dir_path ) ? . iter ( ) { info ! ( " " key_name_file_path ) ; let mut key_info = Vec :: new ( ) ; let mut key_info_file = File :: open ( & key_name_file_path ) ? ; let _ = key_info_file . read_to_end ( & mut key_info ) ? ; let key_info = bincode :: deserialize ( & key_info [ .. ] ) . or_else ( | e | { error ! ( " " e ) ; Err ( Error :: new ( ErrorKind :: Other , " " ) ) } ) ? ; match base64_data_triple_to_key_triple ( os_str_to_u8_ref ( app_name_dir_path . file_name ( ) . expect ( " " , ) ) ? , os_str_to_provider_id ( provider_dir_path . file_name ( ) . expect ( " " , ) ) ? , os_str_to_u8_ref ( key_name_file_path . file_name ( ) . expect ( " " , ) ) ? , ) { Ok ( key_triple ) => { let _ = key_store . insert ( key_triple , key_info ) ; } Err ( string ) => { error ! ( " " string ) ; } } } } } Ok ( OnDiskKeyIDManager { key_store , mappings_dir_path , } ) }
Creates an instance of the on-disk manager from the mapping files.
Creates an instance of the on - disk manager from the mapping files .
mappings_dir_path
PathBuf
mappings_dir_path
PathBuf
errors
Returns an std::io error if the function failed reading the mapping files.
Returns an std :: io error if the function failed reading the mapping files .