mirror of
https://github.com/telemt/telemt.git
synced 2026-10-11 11:55:59 +03:00
Runtime paths symlink preserved + User Admission Registration
This commit is contained in:
+27
-3
@@ -35,6 +35,20 @@ pub(crate) fn resolve_runtime_config_path(
|
||||
startup_cwd: &Path,
|
||||
config_path_explicit: bool,
|
||||
) -> PathBuf {
|
||||
let normalize = |path: PathBuf| {
|
||||
let mut normalized = PathBuf::new();
|
||||
for component in path.components() {
|
||||
match component {
|
||||
std::path::Component::CurDir => {}
|
||||
std::path::Component::ParentDir => {
|
||||
normalized.pop();
|
||||
}
|
||||
component => normalized.push(component.as_os_str()),
|
||||
}
|
||||
}
|
||||
normalized
|
||||
};
|
||||
|
||||
if config_path_explicit {
|
||||
let raw = PathBuf::from(config_path_cli);
|
||||
let absolute = if raw.is_absolute() {
|
||||
@@ -42,7 +56,7 @@ pub(crate) fn resolve_runtime_config_path(
|
||||
} else {
|
||||
startup_cwd.join(raw)
|
||||
};
|
||||
return absolute.canonicalize().unwrap_or(absolute);
|
||||
return normalize(absolute);
|
||||
}
|
||||
|
||||
let etc_telemt = std::path::Path::new("/etc/telemt");
|
||||
@@ -54,7 +68,7 @@ pub(crate) fn resolve_runtime_config_path(
|
||||
];
|
||||
for candidate in candidates {
|
||||
if candidate.is_file() {
|
||||
return candidate.canonicalize().unwrap_or(candidate);
|
||||
return normalize(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +105,17 @@ fn normalize_runtime_dir(path: &Path, startup_cwd: &Path) -> PathBuf {
|
||||
} else {
|
||||
startup_cwd.join(path)
|
||||
};
|
||||
absolute.canonicalize().unwrap_or(absolute)
|
||||
let mut normalized = PathBuf::new();
|
||||
for component in absolute.components() {
|
||||
match component {
|
||||
std::path::Component::CurDir => {}
|
||||
std::path::Component::ParentDir => {
|
||||
normalized.pop();
|
||||
}
|
||||
component => normalized.push(component.as_os_str()),
|
||||
}
|
||||
}
|
||||
normalized
|
||||
}
|
||||
|
||||
/// Parsed CLI arguments.
|
||||
|
||||
@@ -52,6 +52,35 @@
|
||||
let _ = std::fs::remove_dir(&startup_cwd);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn runtime_paths_preserve_symlinks_for_descriptor_validation() {
|
||||
use std::os::unix::fs::symlink;
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let real_dir = dir.path().join("real");
|
||||
let linked_dir = dir.path().join("linked");
|
||||
std::fs::create_dir(&real_dir).unwrap();
|
||||
std::fs::write(real_dir.join("config.toml"), " ").unwrap();
|
||||
symlink(&real_dir, &linked_dir).unwrap();
|
||||
let linked_config = linked_dir.join("config.toml");
|
||||
|
||||
let config = resolve_runtime_config_path(
|
||||
linked_config.to_str().unwrap(),
|
||||
dir.path(),
|
||||
true,
|
||||
);
|
||||
let runtime = resolve_runtime_base_dir(
|
||||
&linked_config,
|
||||
dir.path(),
|
||||
true,
|
||||
Some(&linked_dir),
|
||||
);
|
||||
|
||||
assert_eq!(config, linked_config);
|
||||
assert_eq!(runtime, linked_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_runtime_config_path_uses_startup_candidates_when_not_explicit() {
|
||||
let nonce = std::time::SystemTime::now()
|
||||
|
||||
Reference in New Issue
Block a user