Skip to content

Commit

Permalink
Refactor find_library to return Result<Library, Error>
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 15, 2021
1 parent aa3ba6a commit fdf698d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,9 @@ impl DependencyAnalyzer {
if libraries.contains_key(&lib_name) {
continue;
}
if let Some(library) = self.find_library(&elf, &lib_name)? {
libraries.insert(lib_name, library.clone());
stack.extend(library.needed);
} else {
// TODO: return error
}
let library = self.find_library(&elf, &lib_name)?;
libraries.insert(lib_name, library.clone());
stack.extend(library.needed);
}

let interpreter = elf.interpreter.map(|interp| interp.to_string());
Expand Down Expand Up @@ -216,7 +213,7 @@ impl DependencyAnalyzer {
}

/// Try to locate a `lib` that is compatible to `elf`
fn find_library(&self, elf: &Elf, lib: &str) -> Result<Option<Library>, Error> {
fn find_library(&self, elf: &Elf, lib: &str) -> Result<Library, Error> {
for ld_path in self
.runpaths
.iter()
Expand All @@ -231,25 +228,25 @@ impl DependencyAnalyzer {
if compatible_elfs(elf, &lib_elf) {
let needed = lib_elf.libraries.iter().map(ToString::to_string).collect();
let (rpath, runpath) = self.read_rpath_runpath(&lib_elf, &lib_path, &bytes)?;
return Ok(Some(Library {
return Ok(Library {
name: lib.to_string(),
path: lib_path.to_path_buf(),
realpath: lib_path.canonicalize().ok(),
needed,
rpath,
runpath,
}));
});
}
}
}
Ok(Some(Library {
Ok(Library {
name: lib.to_string(),
path: PathBuf::from(lib),
realpath: None,
needed: Vec::new(),
rpath: Vec::new(),
runpath: Vec::new(),
}))
})
}
}

Expand Down

0 comments on commit fdf698d

Please sign in to comment.