summaryrefslogtreecommitdiff
path: root/src/rootfs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rootfs.rs')
-rw-r--r--[-rwxr-xr-x]src/rootfs.rs40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/rootfs.rs b/src/rootfs.rs
index badc595..c53b879 100755..100644
--- a/src/rootfs.rs
+++ b/src/rootfs.rs
@@ -1,4 +1,5 @@
use std::collections::HashMap;
+use crate::debug;
use std::fs;
use std::path::Path;
use std::os::unix::fs::symlink;
@@ -137,7 +138,7 @@ fn download_file_quiet(
let size = std::fs::metadata(&src).map_err(|e| e.to_string())?.len();
bytes_expected_global.fetch_add(size, Ordering::Relaxed);
let mut tmp_file = NamedTempFile::new().map_err(|e| e.to_string())?;
- let file_path = tmp_file.path().to_path_buf();
+ let _file_path = tmp_file.path().to_path_buf();
let mut src_file = std::fs::File::open(src).map_err(|e| e.to_string())?;
let mut buf = [0u8; 65536];
loop {
@@ -151,8 +152,8 @@ fn download_file_quiet(
let _ = std::fs::copy(&dict_src, &dict_dst);
}
bytes_done_global.fetch_add(size, Ordering::Relaxed);
- drop(tmp_file);
- return Ok((file_path, size));
+ let (_, path) = tmp_file.keep().map_err(|e| e.to_string())?;
+ return Ok((path, size));
}
use reqwest::blocking::Client;
@@ -177,7 +178,7 @@ fn download_file_quiet(
}
let mut tmp_file = NamedTempFile::new().map_err(|e| e.to_string())?;
- let file_path = tmp_file.path().to_path_buf();
+ let _file_path = tmp_file.path().to_path_buf();
let mut hasher = Sha256::new();
let mut buf = [0u8; 65536];
let mut downloaded: u64 = 0;
@@ -199,8 +200,8 @@ fn download_file_quiet(
}
}
- drop(tmp_file);
- Ok((file_path, downloaded))
+ let (_, path) = tmp_file.keep().map_err(|e| e.to_string())?;
+ Ok((path, downloaded))
}
fn render_overall_bar(bytes_done: u64, bytes_expected: u64) {
@@ -347,6 +348,7 @@ fn install_from_archive(
) -> Result<Vec<String>, String> {
let shadow = tempfile::tempdir().map_err(|e| format!("Failed to create temp dir: {}", e))?;
let work_dir = shadow.path().join(pkg_name);
+ fs::create_dir_all(&work_dir).map_err(|e| format!("Failed to create work dir: {}", e))?;
let extracted = if pkg_type == "ror" {
extract_ror(archive_path, &work_dir)
@@ -682,7 +684,27 @@ fn run_ldconfig_in_root(root_dir: &Path) -> Result<(), String> {
} else if root_dir.join("usr/sbin/ldconfig").exists() {
"/usr/sbin/ldconfig"
} else {
- return Ok(());
+ debug!("Target rootfs lacks ldconfig, attempting host ldconfig -r...");
+ let status = std::process::Command::new("ldconfig")
+ .arg("-r")
+ .arg(root_dir)
+ .arg("-C")
+ .arg("/etc/ld.so.cache")
+ .status();
+ match status {
+ Ok(s) if s.success() => {
+ debug!("Host ldconfig -r generated /etc/ld.so.cache successfully");
+ return Ok(());
+ }
+ Ok(s) => {
+ debug!("Host ldconfig -r exited with: {}", s);
+ return Ok(());
+ }
+ Err(e) => {
+ debug!("Failed to run host ldconfig: {}", e);
+ return Ok(());
+ }
+ }
};
match unsafe { fork() } {
@@ -1044,7 +1066,9 @@ pub fn build_rootfs(
println!("\n{} Phase 2: Running install_steps in chroot...", ">>>".cyan().bold());
println!("{} Mounting /dev /proc /sys...", ">>>".cyan());
- mount_virtual_fs(target_dir)?;
+ if let Err(e) = mount_virtual_fs(target_dir) {
+ eprintln!("{} Warning: Failed to mount virtual fs: {} (continuing anyway)", "[ror]".yellow(), e);
+ }
let result = run_all_install_steps(&group.packages, &installing, target_dir);