diff options
| author | qvkap <qvkapp@gmail.com> | 2026-09-23 22:25:25 +0300 |
|---|---|---|
| committer | qvkap <qvkapp@gmail.com> | 2026-09-23 22:25:25 +0300 |
| commit | f890ebb3c4c8803e3dd4abba66e70657397f8122 (patch) | |
| tree | f241c2463932e211bcd7b1f0492a7eec1e721fbf /src | |
| parent | 9f8906467a6c343a1a5d4a5afefc061ceba8e43d (diff) | |
| download | ror-f890ebb3c4c8803e3dd4abba66e70657397f8122.tar.gz ror-f890ebb3c4c8803e3dd4abba66e70657397f8122.zip | |
Bumped version to 1.0.3, fixing temporary file persistence via keep(), preventing UsrMerge circular symlink bugs, adding a host fallback for ldconfig, making virtual FS mount failures non-fatal during rootfs build, improving YAML error reporting, normalizing file permissions, and updating dependencies.
Diffstat (limited to 'src')
| -rw-r--r--[-rwxr-xr-x] | src/apply.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/check.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/config.rs | 15 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/group.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/info.rs | 37 | ||||
| -rw-r--r-- | src/install.rs | 170 | ||||
| -rw-r--r-- | src/parallel.rs | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/progress.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/repo.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/resolver.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/rootfs.rs | 40 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/search.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/sync.rs | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/update.rs | 0 |
14 files changed, 151 insertions, 117 deletions
diff --git a/src/apply.rs b/src/apply.rs index dd5268d..dd5268d 100755..100644 --- a/src/apply.rs +++ b/src/apply.rs diff --git a/src/check.rs b/src/check.rs index f7e3126..f7e3126 100755..100644 --- a/src/check.rs +++ b/src/check.rs diff --git a/src/config.rs b/src/config.rs index 9a4a22e..e4ffdaf 100755..100644 --- a/src/config.rs +++ b/src/config.rs @@ -219,18 +219,19 @@ impl Config { pub fn create_default_config(path: &Path) -> std::io::Result<()> { let ini = concat!( "[global]\n", - "ignore_speed = false\n", + "ignore_speed = true\n", "strict_gpg = false\n", + "allow_external_binaries = true\n", "parallel_downloads = 4\n", "arch = x86_64\n", - "libc = glibc\n", + "libc = glibc\n\n", "[repositories.rorkos]\n", - "url = \"https://\"\n", - "urlrepo = \"https://\"\n", - "mirror = \"https://\"\n", - "gpg_support = true\n", - "gpg_key = \"rorka.pub\"\n", + "url = \"https://rorkos.duckdns.org/pkg/\"\n", + "urlrepo = \"https://rorkos.duckdns.org/pkg/\"\n", + "mirror = \"https://rorkos.duckdns.org/pkg/\"\n", + "gpg_support = false\n", ); + fs::create_dir_all(path.parent().unwrap())?; let mut tmp = NamedTempFile::new_in(path.parent().unwrap_or(Path::new(".")))?; tmp.write_all(ini.as_bytes())?; diff --git a/src/group.rs b/src/group.rs index 8ce4a88..8ce4a88 100755..100644 --- a/src/group.rs +++ b/src/group.rs diff --git a/src/info.rs b/src/info.rs index d827a53..eb258bb 100755..100644 --- a/src/info.rs +++ b/src/info.rs @@ -1,43 +1,8 @@ use serde::{Deserialize, Serialize}; use std::fs; -use std::path::{Path, PathBuf}; use colored::Colorize; -const REPO_ROOT: &str = "/var/ror/packages"; - -fn find_case_insensitive_dir(parent: &Path, target: &str) -> Option<PathBuf> { - let exact = parent.join(target); - if exact.exists() && exact.is_dir() { - return Some(exact); - } - let target_lower = target.to_lowercase(); - for entry in fs::read_dir(parent).ok()? { - let entry = entry.ok()?; - if entry.file_type().ok()?.is_dir() && entry.file_name().to_string_lossy().to_lowercase() == target_lower { - return Some(entry.path()); - } - } - None -} - -fn find_package_file(pkg_name: &str) -> Option<PathBuf> { - let repo = Path::new(REPO_ROOT); - for entry in fs::read_dir(repo).ok()? { - let entry = entry.ok()?; - let cat_path = entry.path(); - if !cat_path.is_dir() { - continue; - } - if let Some(pkg_dir) = find_case_insensitive_dir(&cat_path, pkg_name) { - let dir_name = pkg_dir.file_name()?.to_string_lossy(); - let pkg_path = pkg_dir.join(format!("{}.yaml", dir_name)); - if pkg_path.exists() && pkg_path.is_file() { - return Some(pkg_path); - } - } - } - None -} +use crate::install::find_package_file; #[derive(Debug, Serialize, Deserialize)] struct Package { diff --git a/src/install.rs b/src/install.rs index 8a66118..a0cf8f2 100644 --- a/src/install.rs +++ b/src/install.rs @@ -65,8 +65,6 @@ pub enum VerOp { Ge, Gt, Le, Lt, Eq } #[derive(Debug, Clone)] pub struct VersionConstraint { - #[allow(dead_code)] - pub name: String, pub op: VerOp, pub version: String, } @@ -76,7 +74,7 @@ pub fn parse_dep(dep: &str) -> (String, Option<VersionConstraint>) { if let Some(idx) = dep.find(op_str) { let name = dep[..idx].trim().to_string(); let ver = dep[idx + op_str.len()..].trim().to_string(); - let c = VersionConstraint { name: name.clone(), op: op.clone(), version: ver }; + let c = VersionConstraint { op: op.clone(), version: ver }; return (name, Some(c)); } } @@ -463,64 +461,38 @@ pub fn parse_package_spec(s: &str) -> (String, Option<String>) { (s.to_string(), None) } -fn find_case_insensitive_dir(parent: &Path, target: &str) -> Option<PathBuf> { - let exact = parent.join(target); - if exact.exists() && exact.is_dir() { - return Some(exact); - } - let target_lower = target.to_lowercase(); - for entry in fs::read_dir(parent).ok()? { - let entry = entry.ok()?; - if entry.file_type().ok()?.is_dir() && entry.file_name().to_string_lossy().to_lowercase() == target_lower { - return Some(entry.path()); - } - } - None -} - -pub fn find_package_file(pkg_name: &str) -> Option<PathBuf> { - let (pkg_name, _) = parse_package_spec(pkg_name); - debug!("Looking for package {} in repository root", pkg_name); - let repo = Path::new(REPO_ROOT); - let read_dir = fs::read_dir(repo).ok()?; - for entry in read_dir.flatten() { - let cat_path = entry.path(); - if !cat_path.is_dir() { - continue; - } - if let Some(pkg_dir) = find_case_insensitive_dir(&cat_path, &pkg_name) { - let dir_name = pkg_dir.file_name()?.to_string_lossy().to_string(); - let pkg_path = pkg_dir.join(format!("{}.yaml", dir_name)); - if pkg_path.exists() && pkg_path.is_file() { - debug!("Found package at {:?}", pkg_path); - return Some(pkg_path); - } - } - } - None +pub fn find_package_file(pkg_name: &str) -> Option<PathBuf> { + find_package_with_repo(pkg_name).map(|(p, _)| p) } pub fn find_package_with_repo(pkg_name: &str) -> Option<(PathBuf, String)> { let (pkg_name, _) = parse_package_spec(pkg_name); debug!("Searching for package {} with repository info", pkg_name); let repo = Path::new(REPO_ROOT); - let read_dir = fs::read_dir(repo).ok()?; + let Ok(read_dir) = fs::read_dir(repo) else { + eprintln!("[ror-debug] Cannot read REPO_ROOT: {:?}", repo); + return None; + }; for entry in read_dir.flatten() { - let cat_path = entry.path(); - if !cat_path.is_dir() { + let repo_dir = entry.path(); + if !repo_dir.is_dir() || repo_dir.file_name().unwrap_or_default() == "groups" { continue; } - - if let Some(pkg_dir) = find_case_insensitive_dir(&cat_path, &pkg_name) { - let dir_name = pkg_dir.file_name()?.to_string_lossy().to_string(); - let pkg_path = pkg_dir.join(format!("{}.yaml", dir_name)); - if pkg_path.exists() && pkg_path.is_file() { - let repo_name = cat_path.file_name()?.to_string_lossy().to_string(); - debug!("Found package in repo {}: {:?}", repo_name, pkg_path); - return Some((pkg_path, repo_name)); + let repo_name = repo_dir.file_name()?.to_string_lossy().to_string(); + + for walk_entry in WalkDir::new(&repo_dir).min_depth(1).max_depth(5).into_iter().flatten() { + if walk_entry.file_type().is_dir() { + let dir_path = walk_entry.path(); + if dir_path.file_name()?.to_string_lossy().eq_ignore_ascii_case(&pkg_name) { + let dir_name = dir_path.file_name()?.to_string_lossy().to_string(); + let pkg_path = dir_path.join(format!("{}.yaml", dir_name)); + if pkg_path.exists() && pkg_path.is_file() { + return Some((pkg_path, repo_name)); + } + } } } } @@ -528,6 +500,7 @@ pub fn find_package_with_repo(pkg_name: &str) -> Option<(PathBuf, String)> { } + pub fn resolve_package_name(pkg_name: &str) -> Option<String> { let path = find_package_file(pkg_name)?; let content = fs::read_to_string(path).ok()?; @@ -584,7 +557,6 @@ pub fn resolve_filename(pkg: &Package, binary: &BinaryPackage) -> String { format!("{}-{}-pkg-{}-{}-rorkos.{}", pkg.name, pkg.version, binary.arch, libc, ext) } -#[allow(dead_code)] pub fn generate_dict_url(filename: &str, mirrors: &[String], cfg: &config::Config) -> Result<String, String> { let dict_filename = { let stem = if let Some(s) = filename.strip_suffix(".ror") { @@ -684,7 +656,7 @@ pub fn install_services(pkg: &Package) { "[ror]".yellow().bold(), pkg.name ); } - Some(init) if init != &service.init => { + Some(init) if !service.init.is_empty() && service.init != "all" && init != &service.init => { eprintln!( "{} Package '{}' has a service for '{}', but your init is '{}' — not supported", "[ror]".yellow().bold(), pkg.name, service.init, init @@ -731,7 +703,7 @@ pub fn install_services_to_root(pkg: &Package, root_dir: &Path) { "[ror]".yellow().bold(), pkg.name ); } - Some(init) if init != &service.init => { + Some(init) if !service.init.is_empty() && service.init != "all" && init != &service.init => { eprintln!( "{} Package '{}' has a service for '{}', but rootfs init is '{}' — not supported", "[ror]".yellow().bold(), pkg.name, service.init, init @@ -749,10 +721,16 @@ pub fn install_services_to_root(pkg: &Package, root_dir: &Path) { } } match std::fs::write(&full_path, &service.file) { - Ok(_) => println!( - "{} Created service for '{}': {}", - "[ror]".green().bold(), pkg.name, service.filepath - ), + Ok(_) => { + println!( + "{} Created service for '{}': {}", + "[ror]".green().bold(), pkg.name, service.filepath + ); + if service.file.starts_with("#!") { + use std::os::unix::fs::PermissionsExt; + let _ = std::fs::set_permissions(&full_path, std::fs::Permissions::from_mode(0o755)); + } + } Err(e) => eprintln!( "{} Failed to write service file '{}': {}", "[ror]".red().bold(), service.filepath, e @@ -946,9 +924,20 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu let mut files = extract_deb(&archive_path, Path::new("/"))?; all_installed_files.append(&mut files); } else if pkg_type == "ror" { + if let Ok(dict_url) = generate_dict_url(&effective_filename, &binary.mirrors, cfg) { + if let Ok(dict_path) = download_and_verify(&dict_url, "", cfg) { + let target_dict = archive_path.with_extension("dict"); + let _ = fs::copy(&dict_path, &target_dict); + let _ = fs::remove_file(&dict_path); + } + } sp2.tick(&format!("Extracting {}...", pkg_name)); let files = extract_ror(&archive_path, &work_dir) .map_err(|e| format!("Extraction failed: {}", e))?; + let target_dict = archive_path.with_extension("dict"); + if target_dict.exists() { + let _ = fs::remove_file(&target_dict); + } sp2.tick(&format!("Installing files for {}...", pkg_name)); let mut installed = install_files(&work_dir, &binary.install_prefix, &files) .map_err(|e| format!("Failed to install files: {}", e))?; @@ -1178,9 +1167,34 @@ fn install_files(source_dir: &Path, prefix: &str, files: &[String]) -> Result<Ve let target = fs::read_link(&src) .map_err(|e| format!("Failed to read link {}: {}", src.display(), e))?; validate_symlink_target(&target, &dst, prefix_path)?; - let _ = fs::remove_file(&dst); - symlink(&target, &dst) - .map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?; + + let target_in_root = if target.is_absolute() { + prefix_path.join(target.strip_prefix("/").unwrap_or(&target)) + } else { + dst.parent().unwrap_or(prefix_path).join(&target) + }; + + let is_self_or_canonical = if let Some(parent) = dst.parent() { + if let (Ok(parent_canonical), Ok(target_canonical)) = (fs::canonicalize(parent), fs::canonicalize(&target_in_root)) { + if let Some(file_name) = dst.file_name() { + parent_canonical.join(file_name) == target_canonical + } else { + false + } + } else { + false + } + } else { + false + }; + + if is_self_or_canonical { + debug!("Skipping symlink {:?} -> {:?} because target already exists as canonical file", dst, target); + } else { + let _ = fs::remove_file(&dst); + symlink(&target, &dst) + .map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?; + } } else { let _ = fs::remove_file(&dst); fs::copy(&src, &dst) @@ -1210,9 +1224,33 @@ pub fn install_files_to_root(source_dir: &Path, root: &Path, files: &[String]) - let target = fs::read_link(&src) .map_err(|e| format!("Failed to read link {}: {}", src.display(), e))?; validate_symlink_target(&target, &dst, root)?; - let _ = fs::remove_file(&dst); - symlink(&target, &dst) - .map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?; + let target_in_root = if target.is_absolute() { + root.join(target.strip_prefix("/").unwrap_or(&target)) + } else { + dst.parent().unwrap_or(root).join(&target) + }; + + let is_self_or_canonical = if let Some(parent) = dst.parent() { + if let (Ok(parent_canonical), Ok(target_canonical)) = (fs::canonicalize(parent), fs::canonicalize(&target_in_root)) { + if let Some(file_name) = dst.file_name() { + parent_canonical.join(file_name) == target_canonical + } else { + false + } + } else { + false + } + } else { + false + }; + + if is_self_or_canonical { + debug!("Skipping symlink {:?} -> {:?} because target already exists as canonical file", dst, target); + } else { + let _ = fs::remove_file(&dst); + symlink(&target, &dst) + .map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?; + } } else { let _ = fs::remove_file(&dst); fs::copy(&src, &dst) @@ -1263,7 +1301,13 @@ pub fn load_package(pkg_name: &str) -> Option<Package> { debug!("Loading full package metadata for {}", pkg_name); let pkg_path = find_package_file(&pkg_name)?; let content = fs::read_to_string(pkg_path).ok()?; - serde_yaml::from_str(&content).ok() + match serde_yaml::from_str(&content) { + Ok(pkg) => Some(pkg), + Err(e) => { + eprintln!("[ror-debug] Failed to parse YAML for {}: {}", pkg_name, e); + None + } + } } fn check_oss_policy(pkg: &Package) -> Result<(), String> { diff --git a/src/parallel.rs b/src/parallel.rs index a3a722b..aacd9c3 100644 --- a/src/parallel.rs +++ b/src/parallel.rs @@ -162,7 +162,7 @@ async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result<Pa } 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 body = res.bytes().await.map_err(|e| e.to_string())?; @@ -179,8 +179,8 @@ async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result<Pa } } - drop(tmp_file); - Ok(file_path) + let (_, path) = tmp_file.keep().map_err(|e| e.to_string())?; + Ok(path) }) .await .unwrap_or_else(|_| Err("Download timed out".into())); diff --git a/src/progress.rs b/src/progress.rs index ec97b79..ec97b79 100755..100644 --- a/src/progress.rs +++ b/src/progress.rs diff --git a/src/repo.rs b/src/repo.rs index 34cbbd6..34cbbd6 100755..100644 --- a/src/repo.rs +++ b/src/repo.rs diff --git a/src/resolver.rs b/src/resolver.rs index 33c67e2..33c67e2 100755..100644 --- a/src/resolver.rs +++ b/src/resolver.rs 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); diff --git a/src/search.rs b/src/search.rs index 9fc691b..9fc691b 100755..100644 --- a/src/search.rs +++ b/src/search.rs diff --git a/src/sync.rs b/src/sync.rs index 2d1b6b7..2d1b6b7 100755..100644 --- a/src/sync.rs +++ b/src/sync.rs diff --git a/src/update.rs b/src/update.rs index 62be1b5..62be1b5 100755..100644 --- a/src/update.rs +++ b/src/update.rs |