chore(dso): minor refactoring
This commit is contained in:
parent
344e16cf0f
commit
2213856c81
|
@ -60,6 +60,7 @@ impl Cleaner for DsoCleaner {
|
|||
}
|
||||
}
|
||||
|
||||
// DEBUGGING stuff you can uncomment for a quick and dirty graph:
|
||||
// println!(
|
||||
// "{:?}",
|
||||
// petgraph::dot::Dot::with_config(&state.graph, &[petgraph::dot::Config::EdgeNoLabel])
|
||||
|
@ -151,19 +152,7 @@ impl DsoCleaner {
|
|||
dst_path.display()
|
||||
);
|
||||
|
||||
state
|
||||
.paths_map
|
||||
.entry(src.st_ino)
|
||||
.or_default()
|
||||
.insert(path.into());
|
||||
|
||||
state
|
||||
.paths_map
|
||||
.entry(dst.st_ino)
|
||||
.or_default()
|
||||
.insert(dst_path);
|
||||
|
||||
state.graph.add_edge(src.st_ino, dst.st_ino, ());
|
||||
Self::update_graph(state, path.into(), src.st_ino, dst_path, dst.st_ino);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -192,22 +181,7 @@ impl DsoCleaner {
|
|||
search_paths.append(&mut rpaths);
|
||||
}
|
||||
|
||||
let ld_config_path = std::env::var("LD_LIBRARY_PATH");
|
||||
let mut env_paths = ld_config_path
|
||||
.as_ref()
|
||||
.map(|env| {
|
||||
env.split(':')
|
||||
.filter_map(|dir| {
|
||||
if dir.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(dir.to_string())
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
search_paths.append(&mut env_paths);
|
||||
search_paths.append(&mut Self::get_env_library_paths());
|
||||
}
|
||||
|
||||
if elf.runpaths != vec![""] {
|
||||
|
@ -249,19 +223,7 @@ impl DsoCleaner {
|
|||
continue; // These are not the droids you are looking for.
|
||||
}
|
||||
|
||||
state
|
||||
.paths_map
|
||||
.entry(src_inode)
|
||||
.or_default()
|
||||
.insert(path.into());
|
||||
|
||||
state
|
||||
.paths_map
|
||||
.entry(dst.st_ino)
|
||||
.or_default()
|
||||
.insert(tentative_path);
|
||||
|
||||
state.graph.add_edge(src_inode, dst.st_ino, ());
|
||||
Self::update_graph(state, path.into(), src_inode, tentative_path, dst.st_ino);
|
||||
continue 'next_lib;
|
||||
}
|
||||
|
||||
|
@ -270,4 +232,39 @@ impl DsoCleaner {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_env_library_paths() -> Vec<String> {
|
||||
let ld_config_path = std::env::var("LD_LIBRARY_PATH");
|
||||
ld_config_path
|
||||
.as_ref()
|
||||
.map(|env| {
|
||||
env.split(':')
|
||||
.filter(|s| s.is_empty())
|
||||
.map(|s| s.into())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn update_graph(
|
||||
state: &mut State,
|
||||
src_path: PathBuf,
|
||||
src_inode: ino_t,
|
||||
dst_path: PathBuf,
|
||||
dst_inode: ino_t,
|
||||
) {
|
||||
state
|
||||
.paths_map
|
||||
.entry(src_inode)
|
||||
.or_default()
|
||||
.insert(src_path);
|
||||
|
||||
state
|
||||
.paths_map
|
||||
.entry(dst_inode)
|
||||
.or_default()
|
||||
.insert(dst_path);
|
||||
|
||||
state.graph.add_edge(src_inode, dst_inode, ());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue