summaryrefslogtreecommitdiff
path: root/src/group.rs
diff options
context:
space:
mode:
authorqvkap <qvkapp@gmail.com>2026-10-05 19:54:51 +0300
committerqvkap <qvkapp@gmail.com>2026-10-05 19:54:51 +0300
commit78828df65dfc90d30e82490b290db04ebf2c6f30 (patch)
treedf81438ed7323167d177a7074dafcba59726b06c /src/group.rs
parentf267c259163e121ff376bd764b10767a7939ef79 (diff)
downloadror-78828df65dfc90d30e82490b290db04ebf2c6f30.tar.gz
ror-78828df65dfc90d30e82490b290db04ebf2c6f30.zip
fix: sync uses fetch+reset instead of pull, group supports direct .yaml path from cwd
Diffstat (limited to 'src/group.rs')
-rw-r--r--src/group.rs53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/group.rs b/src/group.rs
index 8ce4a88..bc34a68 100644
--- a/src/group.rs
+++ b/src/group.rs
@@ -1,25 +1,12 @@
use serde::Deserialize;
use std::fs;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use colored::Colorize;
use crate::config;
use crate::install;
const GROUPS_DIR: &str = "/var/ror/packages/groups";
-fn sanitize_group_name(name: &str) -> Result<(), String> {
- if name.is_empty() {
- return Err("Group name is empty".to_string());
- }
- if name.contains('/') || name.contains('\\') || name.contains("..") || name.contains('\0') {
- return Err(format!("Invalid group name: '{}' contains path traversal characters", name));
- }
- if name.starts_with('-') {
- return Err(format!("Invalid group name: '{}' starts with dash", name));
- }
- Ok(())
-}
-
#[derive(Debug, Deserialize)]
pub struct Group {
#[allow(dead_code)]
@@ -30,7 +17,7 @@ pub struct Group {
pub packages: Vec<String>,
#[serde(default)]
pub install_steps: String,
-
+
#[serde(rename = "init-system")]
#[allow(dead_code)]
pub init_system: Option<String>,
@@ -47,14 +34,30 @@ pub struct Group {
pub su: Vec<String>,
}
+pub fn resolve_group_path(name_or_path: &str) -> PathBuf {
+ let p = Path::new(name_or_path);
+
+ if p.is_absolute() || name_or_path.contains('/') {
+ return p.to_path_buf();
+ }
+
+ if name_or_path.ends_with(".yaml") {
+ let cwd_path = std::env::current_dir()
+ .unwrap_or_else(|_| PathBuf::from("."))
+ .join(name_or_path);
+ if cwd_path.exists() {
+ return cwd_path;
+ }
+ return PathBuf::from(format!("{}/{}", GROUPS_DIR, name_or_path));
+ }
+
+ PathBuf::from(format!("{}/{}.yaml", GROUPS_DIR, name_or_path))
+}
+
#[allow(dead_code)]
pub fn install_group(group_name: &str, cfg: &config::Config) {
- if let Err(e) = sanitize_group_name(group_name) {
- eprintln!("{} {}", "[ror]".red().bold(), e);
- return;
- }
- let group_file = format!("{}/{}.yaml", GROUPS_DIR, group_name);
- if !Path::new(&group_file).exists() {
+ let group_file = resolve_group_path(group_name);
+ if !group_file.exists() {
eprintln!("{} Group '{}' not found!", "[ror]".red().bold(), group_name);
return;
}
@@ -94,11 +97,10 @@ pub fn install_group(group_name: &str, cfg: &config::Config) {
println!("{} Group '{}' installation completed.", "[ror]".blue().bold(), group.name);
}
-pub fn load_group(group_name: &str) -> Result<Group, String> {
- sanitize_group_name(group_name)?;
- let group_file = format!("{}/{}.yaml", GROUPS_DIR, group_name);
+pub fn load_group(name_or_path: &str) -> Result<Group, String> {
+ let group_file = resolve_group_path(name_or_path);
let content = fs::read_to_string(&group_file)
- .map_err(|e| format!("Failed to read group file: {}", e))?;
+ .map_err(|e| format!("Failed to read group file '{}': {}", group_file.display(), e))?;
let group: Group = serde_yaml::from_str(&content)
.map_err(|e| format!("Group YAML error: {}", e))?;
Ok(group)
@@ -127,4 +129,3 @@ pub fn list_groups() {
}
}
}
-