From f890ebb3c4c8803e3dd4abba66e70657397f8122 Mon Sep 17 00:00:00 2001 From: qvkap Date: Wed, 23 Sep 2026 22:25:25 +0300 Subject: 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. --- src/apply.rs | 0 src/check.rs | 0 src/config.rs | 15 ++--- src/group.rs | 0 src/info.rs | 37 +----------- src/install.rs | 170 +++++++++++++++++++++++++++++++++++--------------------- src/parallel.rs | 6 +- src/progress.rs | 0 src/repo.rs | 0 src/resolver.rs | 0 src/rootfs.rs | 40 ++++++++++--- src/search.rs | 0 src/sync.rs | 0 src/update.rs | 0 14 files changed, 151 insertions(+), 117 deletions(-) mode change 100755 => 100644 src/apply.rs mode change 100755 => 100644 src/check.rs mode change 100755 => 100644 src/config.rs mode change 100755 => 100644 src/group.rs mode change 100755 => 100644 src/info.rs mode change 100755 => 100644 src/progress.rs mode change 100755 => 100644 src/repo.rs mode change 100755 => 100644 src/resolver.rs mode change 100755 => 100644 src/rootfs.rs mode change 100755 => 100644 src/search.rs mode change 100755 => 100644 src/sync.rs mode change 100755 => 100644 src/update.rs (limited to 'src') diff --git a/src/apply.rs b/src/apply.rs old mode 100755 new mode 100644 diff --git a/src/check.rs b/src/check.rs old mode 100755 new mode 100644 diff --git a/src/config.rs b/src/config.rs old mode 100755 new mode 100644 index 9a4a22e..e4ffdaf --- 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 old mode 100755 new mode 100644 diff --git a/src/info.rs b/src/info.rs old mode 100755 new mode 100644 index d827a53..eb258bb --- 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 { - 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 { - 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) { 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) { (s.to_string(), None) } -fn find_case_insensitive_dir(parent: &Path, target: &str) -> Option { - 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 { - 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 { + 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 { 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 { 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 {:?} 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 { 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 Result Result, 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 old mode 100755 new mode 100644 diff --git a/src/sync.rs b/src/sync.rs old mode 100755 new mode 100644 diff --git a/src/update.rs b/src/update.rs old mode 100755 new mode 100644 -- cgit v1.2.3