Refactor: returns error instead of unwrapping path join

master
Mason Stallmo 6 years ago
parent bcdbaab731
commit c99b93498c
  1. 17
      src/license.rs

@ -12,7 +12,16 @@ use PBAR;
fn glob_license_files(path: &Path) -> Result<Vec<String>, failure::Error> { fn glob_license_files(path: &Path) -> Result<Vec<String>, failure::Error> {
let mut license_files: Vec<String> = Vec::new(); let mut license_files: Vec<String> = Vec::new();
for entry in glob(path.join("LICENSE*").to_str().unwrap())? { let path_string = match path.join("LICENSE*").to_str() {
Some(path_string) => path_string.to_owned(),
None => {
return Err(format_err!(
"Could not convert joined license path to String"
));
}
};
for entry in glob(&path_string)? {
match entry { match entry {
Ok(globed_path) => { Ok(globed_path) => {
let file_name = match globed_path.file_name() { let file_name = match globed_path.file_name() {
@ -20,10 +29,10 @@ fn glob_license_files(path: &Path) -> Result<Vec<String>, failure::Error> {
None => return Err(format_err!("Could not get file name from path")), None => return Err(format_err!("Could not get file name from path")),
}; };
let file_name_string = match file_name.to_str() { let file_name_string = match file_name.to_str() {
Some(file_name_string) => file_name_string, Some(file_name_string) => file_name_string.to_owned(),
None => return Err(format_err!("Could not convert filename to string")), None => return Err(format_err!("Could not convert filename to String")),
}; };
license_files.push(String::from(file_name_string)); license_files.push(file_name_string);
} }
Err(e) => println!("{:?}", e), Err(e) => println!("{:?}", e),
} }

Loading…
Cancel
Save