|
|
@ -1,4 +1,5 @@
|
|
|
|
use std::fs::{copy as fscopy, File};
|
|
|
|
use std::fs::{copy as fscopy, metadata, set_permissions, File};
|
|
|
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::process::Command;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
|
@ -157,24 +158,75 @@ impl Files {
|
|
|
|
pub fn copy(&self, config: &Config) -> MkrootResult<()> {
|
|
|
|
pub fn copy(&self, config: &Config) -> MkrootResult<()> {
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
target.push("bin");
|
|
|
|
target.push("bin");
|
|
|
|
Files::copy_files(&self.bins, &target, config.verbose)?;
|
|
|
|
Files::copy_files(&self.bins, &target, 0o755, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
target.push("sbin");
|
|
|
|
target.push("sbin");
|
|
|
|
Files::copy_files(&self.sbins, &target, config.verbose)?;
|
|
|
|
Files::copy_files(&self.sbins, &target, 0o755, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
target.push("libs");
|
|
|
|
target.push("libs");
|
|
|
|
Files::copy_files(&self.libs, &target, config.verbose)?;
|
|
|
|
Files::copy_files(&self.libs, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
let mut target = PathBuf::from(&config.root_dir);
|
|
|
|
target.push("lib64");
|
|
|
|
target.push("lib64");
|
|
|
|
Files::copy_files(&self.lib64s, &target, config.verbose)?;
|
|
|
|
Files::copy_files(&self.lib64s, &target, 0o644, config.verbose)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn copy_files(files: &[PathBuf], target: &PathBuf, verbose: bool) -> MkrootResult<()> {
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match metadata(&lib) {
|
|
|
|
|
|
|
|
Ok(meta) => {
|
|
|
|
|
|
|
|
let mut perms = meta.permissions();
|
|
|
|
|
|
|
|
perms.set_mode(0o755);
|
|
|
|
|
|
|
|
if let Err(e) = set_permissions(&lib, perms) {
|
|
|
|
|
|
|
|
return Err(MkrootError::from(format!(
|
|
|
|
|
|
|
|
"Error setting permissions {}: {}",
|
|
|
|
|
|
|
|
&lib.display(),
|
|
|
|
|
|
|
|
e
|
|
|
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(e) => {
|
|
|
|
|
|
|
|
return Err(MkrootError::from(format!(
|
|
|
|
|
|
|
|
"Error reading metadata {}: {}",
|
|
|
|
|
|
|
|
&lib.display(),
|
|
|
|
|
|
|
|
e
|
|
|
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn copy_files(
|
|
|
|
|
|
|
|
files: &[PathBuf],
|
|
|
|
|
|
|
|
target: &PathBuf,
|
|
|
|
|
|
|
|
mode: u32,
|
|
|
|
|
|
|
|
verbose: bool,
|
|
|
|
|
|
|
|
) -> MkrootResult<()> {
|
|
|
|
for f in files {
|
|
|
|
for f in files {
|
|
|
|
let mut t = PathBuf::from(&target);
|
|
|
|
let mut t = PathBuf::from(&target);
|
|
|
|
if let Some(filename) = &f.file_name() {
|
|
|
|
if let Some(filename) = &f.file_name() {
|
|
|
@ -191,6 +243,10 @@ impl Files {
|
|
|
|
&t.display(),
|
|
|
|
&t.display(),
|
|
|
|
e
|
|
|
|
e
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let mut perms = metadata(&t)?.permissions();
|
|
|
|
|
|
|
|
perms.set_mode(mode);
|
|
|
|
|
|
|
|
set_permissions(&t, perms)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if verbose {
|
|
|
|
} else if verbose {
|
|
|
|
println!("Skipping {}", &f.display());
|
|
|
|
println!("Skipping {}", &f.display());
|
|
|
|