fn map_partial_path()

in src/path_rewriting.rs [174:206]


fn map_partial_path(file_to_paths: &FxHashMap<String, Vec<PathBuf>>, path: PathBuf) -> PathBuf {
    let options = file_to_paths.get(path.file_name().unwrap().to_str().unwrap());

    if options.is_none() {
        return path;
    }

    let options = options.unwrap();

    if options.len() == 1 {
        return options[0].clone();
    }

    let mut result: Option<&PathBuf> = None;
    for option in options {
        if option.ends_with(&path) {
            if result.is_some() {
                error!("Only one file in the repository should end with {} ({} and {} both end with that).",
                path.display(),
                result.unwrap().display(),
                option.display());
            } else {
                result = Some(option)
            }
        }
    }

    if let Some(result) = result {
        result.clone()
    } else {
        path
    }
}