|
|
@ -30,13 +30,13 @@ impl Files {
|
|
|
|
println!("Checking {}", &file.display());
|
|
|
|
println!("Checking {}", &file.display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Files::open(&file)?;
|
|
|
|
open(&file)?;
|
|
|
|
|
|
|
|
|
|
|
|
let (libs, lib64s) = Files::libs_from_ldd(&file, &config)?;
|
|
|
|
let (libs, lib64s) = libs_from_ldd(&file, &config)?;
|
|
|
|
myfiles.libs.extend(libs);
|
|
|
|
myfiles.libs.extend(libs);
|
|
|
|
myfiles.lib64s.extend(lib64s);
|
|
|
|
myfiles.lib64s.extend(lib64s);
|
|
|
|
|
|
|
|
|
|
|
|
if Files::check_sbin(&file) {
|
|
|
|
if check_sbin(&file) {
|
|
|
|
myfiles.sbins.push(file.to_owned());
|
|
|
|
myfiles.sbins.push(file.to_owned());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
myfiles.bins.push(file.to_owned());
|
|
|
|
myfiles.bins.push(file.to_owned());
|
|
|
@ -55,6 +55,52 @@ impl Files {
|
|
|
|
Ok(myfiles)
|
|
|
|
Ok(myfiles)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn copy(&self, config: &Config) -> MkrootResult<()> {
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("bin");
|
|
|
|
|
|
|
|
copy_files(&self.bins, &target, 0o755, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("sbin");
|
|
|
|
|
|
|
|
copy_files(&self.sbins, &target, 0o755, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("libs");
|
|
|
|
|
|
|
|
copy_files(&self.libs, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("lib64");
|
|
|
|
|
|
|
|
copy_files(&self.lib64s, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_linker_permissions(
|
|
|
|
|
|
|
|
libs: &[PathBuf],
|
|
|
|
|
|
|
|
dir: &PathBuf,
|
|
|
|
|
|
|
|
verbose: bool,
|
|
|
|
|
|
|
|
) -> MkrootResult<()> {
|
|
|
|
|
|
|
|
for lib in libs {
|
|
|
|
|
|
|
|
if let Some(fn_osstr) = &lib.file_name() {
|
|
|
|
|
|
|
|
if let Some(fn_str) = fn_osstr.to_str() {
|
|
|
|
|
|
|
|
if fn_str.starts_with("ld-linux") {
|
|
|
|
|
|
|
|
let mut lib = PathBuf::from(&dir);
|
|
|
|
|
|
|
|
lib.push(&fn_str);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if verbose {
|
|
|
|
|
|
|
|
println!("Setting linker {} to mode 0o755", &lib.display());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_perms(&lib, Permissions::from_mode(0o755))?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn open(p: &PathBuf) -> MkrootResult<()> {
|
|
|
|
fn open(p: &PathBuf) -> MkrootResult<()> {
|
|
|
|
if let Err(e) = File::open(&p) {
|
|
|
|
if let Err(e) = File::open(&p) {
|
|
|
|
return Err(MkrootError::from(format!(
|
|
|
|
return Err(MkrootError::from(format!(
|
|
|
@ -70,7 +116,7 @@ impl Files {
|
|
|
|
file: &PathBuf,
|
|
|
|
file: &PathBuf,
|
|
|
|
config: &Config,
|
|
|
|
config: &Config,
|
|
|
|
) -> MkrootResult<(Vec<PathBuf>, Vec<PathBuf>)> {
|
|
|
|
) -> MkrootResult<(Vec<PathBuf>, Vec<PathBuf>)> {
|
|
|
|
let ldd = Files::ldd(&file, &config)?;
|
|
|
|
let ldd = ldd(&file, &config)?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut libs: Vec<PathBuf> = Vec::new();
|
|
|
|
let mut libs: Vec<PathBuf> = Vec::new();
|
|
|
|
let mut lib64s: Vec<PathBuf> = Vec::new();
|
|
|
|
let mut lib64s: Vec<PathBuf> = Vec::new();
|
|
|
@ -92,7 +138,7 @@ impl Files {
|
|
|
|
println!("Adding {}", &match_path.display());
|
|
|
|
println!("Adding {}", &match_path.display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if Files::check_lib64(&match_path) {
|
|
|
|
if check_lib64(&match_path) {
|
|
|
|
lib64s.push(match_path);
|
|
|
|
lib64s.push(match_path);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
libs.push(match_path);
|
|
|
|
libs.push(match_path);
|
|
|
@ -104,24 +150,29 @@ impl Files {
|
|
|
|
Ok((libs, lib64s))
|
|
|
|
Ok((libs, lib64s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn check_lib64(path: &PathBuf) -> bool {
|
|
|
|
fn copy_files(
|
|
|
|
for c in path.components() {
|
|
|
|
files: &[PathBuf],
|
|
|
|
if c.as_os_str() == "lib64" {
|
|
|
|
target: &PathBuf,
|
|
|
|
return true;
|
|
|
|
mode: u32,
|
|
|
|
}
|
|
|
|
verbose: bool,
|
|
|
|
}
|
|
|
|
) -> MkrootResult<()> {
|
|
|
|
|
|
|
|
for f in files {
|
|
|
|
|
|
|
|
let mut t = PathBuf::from(&target);
|
|
|
|
|
|
|
|
if let Some(filename) = &f.file_name() {
|
|
|
|
|
|
|
|
t.push(filename);
|
|
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
if verbose {
|
|
|
|
|
|
|
|
println!("Copying {} to {}", &f.display(), &t.display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn check_sbin(path: &PathBuf) -> bool {
|
|
|
|
copy_file(&f, &t)?;
|
|
|
|
for c in path.components() {
|
|
|
|
set_perms(&t, Permissions::from_mode(mode))?;
|
|
|
|
if c.as_os_str() == "sbin" {
|
|
|
|
} else if verbose {
|
|
|
|
return true;
|
|
|
|
println!("Skipping {}", &f.display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn ldd(file: &PathBuf, config: &Config) -> MkrootResult<String> {
|
|
|
|
fn ldd(file: &PathBuf, config: &Config) -> MkrootResult<String> {
|
|
|
@ -156,73 +207,22 @@ impl Files {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn copy(&self, config: &Config) -> MkrootResult<()> {
|
|
|
|
fn check_lib64(path: &PathBuf) -> bool {
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
for c in path.components() {
|
|
|
|
target.push("bin");
|
|
|
|
if c.as_os_str() == "lib64" {
|
|
|
|
Files::copy_files(&self.bins, &target, 0o755, config.verbose)?;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("sbin");
|
|
|
|
|
|
|
|
Files::copy_files(&self.sbins, &target, 0o755, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("libs");
|
|
|
|
|
|
|
|
Files::copy_files(&self.libs, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
|
|
|
|
target.push("lib64");
|
|
|
|
|
|
|
|
Files::copy_files(&self.lib64s, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_linker_permissions(
|
|
|
|
|
|
|
|
libs: &[PathBuf],
|
|
|
|
|
|
|
|
dir: &PathBuf,
|
|
|
|
|
|
|
|
verbose: bool,
|
|
|
|
|
|
|
|
) -> MkrootResult<()> {
|
|
|
|
|
|
|
|
for lib in libs {
|
|
|
|
|
|
|
|
if let Some(fn_osstr) = &lib.file_name() {
|
|
|
|
|
|
|
|
if let Some(fn_str) = fn_osstr.to_str() {
|
|
|
|
|
|
|
|
if fn_str.starts_with("ld-linux") {
|
|
|
|
|
|
|
|
let mut lib = PathBuf::from(&dir);
|
|
|
|
|
|
|
|
lib.push(&fn_str);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if verbose {
|
|
|
|
|
|
|
|
println!("Setting linker {} to mode 0o755", &lib.display());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_perms(&lib, Permissions::from_mode(0o755))?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn copy_files(
|
|
|
|
false
|
|
|
|
files: &[PathBuf],
|
|
|
|
|
|
|
|
target: &PathBuf,
|
|
|
|
|
|
|
|
mode: u32,
|
|
|
|
|
|
|
|
verbose: bool,
|
|
|
|
|
|
|
|
) -> MkrootResult<()> {
|
|
|
|
|
|
|
|
for f in files {
|
|
|
|
|
|
|
|
let mut t = PathBuf::from(&target);
|
|
|
|
|
|
|
|
if let Some(filename) = &f.file_name() {
|
|
|
|
|
|
|
|
t.push(filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if verbose {
|
|
|
|
|
|
|
|
println!("Copying {} to {}", &f.display(), &t.display());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
copy_file(&f, &t)?;
|
|
|
|
fn check_sbin(path: &PathBuf) -> bool {
|
|
|
|
set_perms(&t, Permissions::from_mode(mode))?;
|
|
|
|
for c in path.components() {
|
|
|
|
} else if verbose {
|
|
|
|
if c.as_os_str() == "sbin" {
|
|
|
|
println!("Skipping {}", &f.display());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|