Make SearchPathFile::file_name_str
non-optional.
Currently, it can be `None` if the conversion from `OsString` fails, in which case all searches will skip over the `SearchPathFile`. The commit changes things so that the `SearchPathFile` just doesn't get created in the first place. Same behaviour, but slightly simpler code.
This commit is contained in:
parent
89b61ea09f
commit
0ba47f3216
2 changed files with 14 additions and 17 deletions
|
@ -399,10 +399,7 @@ impl<'a> CrateLocator<'a> {
|
||||||
for spf in search_path.files.iter() {
|
for spf in search_path.files.iter() {
|
||||||
debug!("testing {}", spf.path.display());
|
debug!("testing {}", spf.path.display());
|
||||||
|
|
||||||
let file = match &spf.file_name_str {
|
let file = &spf.file_name_str;
|
||||||
None => continue,
|
|
||||||
Some(file) => file,
|
|
||||||
};
|
|
||||||
let (hash, found_kind) = if file.starts_with(&rlib_prefix)
|
let (hash, found_kind) = if file.starts_with(&rlib_prefix)
|
||||||
&& file.ends_with(".rlib")
|
&& file.ends_with(".rlib")
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,22 +15,15 @@ pub struct SearchPath {
|
||||||
/// doable, but very slow, because it involves calls to `file_name` and
|
/// doable, but very slow, because it involves calls to `file_name` and
|
||||||
/// `extension` that are themselves slow.
|
/// `extension` that are themselves slow.
|
||||||
///
|
///
|
||||||
/// This type augments the `PathBuf` with an `Option<String>` containing the
|
/// This type augments the `PathBuf` with an `String` containing the
|
||||||
/// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
|
/// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
|
||||||
/// `Option<String>` than the `PathBuf`. (It's an `Option` because
|
/// `String` than the `PathBuf`. (The filename must be valid UTF-8. If it's
|
||||||
/// `Path::file_name` can fail; if that happens then all subsequent checking
|
/// not, the entry should be skipped, because all Rust output files are valid
|
||||||
/// will also fail, which is fine.)
|
/// UTF-8, and so a non-UTF-8 filename couldn't be one we're looking for.)
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SearchPathFile {
|
pub struct SearchPathFile {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub file_name_str: Option<String>,
|
pub file_name_str: String,
|
||||||
}
|
|
||||||
|
|
||||||
impl SearchPathFile {
|
|
||||||
fn new(path: PathBuf) -> SearchPathFile {
|
|
||||||
let file_name_str = path.file_name().and_then(|f| f.to_str()).map(|s| s.to_string());
|
|
||||||
SearchPathFile { path, file_name_str }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, Encodable, Decodable)]
|
#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, Encodable, Decodable)]
|
||||||
|
@ -85,7 +78,14 @@ impl SearchPath {
|
||||||
// Get the files within the directory.
|
// Get the files within the directory.
|
||||||
let files = match std::fs::read_dir(&dir) {
|
let files = match std::fs::read_dir(&dir) {
|
||||||
Ok(files) => files
|
Ok(files) => files
|
||||||
.filter_map(|e| e.ok().map(|e| SearchPathFile::new(e.path())))
|
.filter_map(|e| {
|
||||||
|
e.ok().and_then(|e| {
|
||||||
|
e.file_name().to_str().map(|s| SearchPathFile {
|
||||||
|
path: e.path(),
|
||||||
|
file_name_str: s.to_string(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
Err(..) => vec![],
|
Err(..) => vec![],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue